OPenGL Flat / Smooth rendering issue

Hi developpers community.

I use Meslab to create OBJ file from stl cad software.
The Vn vector is not unity vector. Is this normal?

Then When I display it, it is similar to the “smooth” tool rendering of MeshLab.
But in my software i would like to display it as “Flat” tool display of MeshLab.

How could I change the option in my C file to display it as same (which OpenGL function should I desable or enable)?

Thanks to help resolving the issue.

Fred

You can recompute a normal per triangle in a geometrie shader… and pass it to the fragment shader…

Could be a potential solution but not so nice.

I saw that the same point can be used for different face orientation.
But it should exist a solution that Meshlab use.

Fred

Or just compute normal per triangle while obj is loading, an put it in your vbos…

Another option is to compute the face normal in the fragment shader.

If the variable “eye” contains the eye-space position, then


vec3 normal = normalize(cross(dFdx(eye), dFdy(eye)));

gives you the eye-space normal.