Draw mesh with flat faces

hello,

i have a mesh which i am able to display in multiple modes : points, lines or triangles.

What i would like (and i can’t find the right solution) is to draw the mesh with simple faces like a low poly rendering.
For now all faces are drawn with interpolated color between each vertex.

void ofApp::onDisplacementChanged(float &val){
    for (int i = 0 ; i < mesh.getNumVertices() ; i++) {
        
        ofColor color = mesh.getColor(i);
        float brightness = ofMap(color.getBrightness(), 0, 255, -val, val);

        ofPoint oldPoint = mesh.getVertex(i);
        ofPoint newPoint(oldPoint.x, oldPoint.y, brightness);

        
        float distance = newPoint.distance(mesh.getVertex(i + 1));
        float alpha = ofMap(distance, 1, 400, 170, 255);
        ofColor newColor(color.r, color.g, color.b, alpha);
        
        mesh.setVertex(i, newPoint);
        mesh.setColor(i, newColor);

    }
}

I can’t find the logic to draw faces with plain colors.

thanks a lot for any tip

ok i got one solution

glShadeModel(GL_FLAT);

is there any other way ?

Your solution apply an aliasing shader to the opengl outpu, by default it is glShadeModel(GL_SMOOTH) which is applied.

This can help you : https://www.opengl.org/discussion_boards/showthread.php/198480-creating-mesh-with-low-polygon-count?p=1282463&viewfull=1#post1282463

It is a pseudo algorythm which explain how to reduce the number of vertice, by keeping the general shape.

You can draw a svg based on the position xy of each vertices, and then apply a main color to each area, and then apply the texture as UV texture.
It is a bit the opposite of what you seek, a texture from a mesh, as it makes you use the mesh for create a texture, but it can work.

thanks you for the explanation and the link. I will have a look at it.
I don’t really need to reduce the number of vertices though. The mesh is ok as is. I just need to render it as flat instead of smooth shading.
What i need though is to render faces as triangles and not quads…