[ACCEPTED]-Wireframes in OpenGL-opengl

Accepted answer
Score: 18
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );

Fill fills it... you want lines.

EDIT: Remember, you 2 can always put it back to fill when you're 1 done, like this

glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
 // add polygons here
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
Score: 5

From your question I assume you have some 17 huge middleware, and have only access to 16 shaders, am I right ?

In this case, create 15 in your vertex shader a varying called, for 14 instance, vertexID :

varying float vertexID; # in GLSL <= 3, or
out float vertexID;     # in GLSL 4

and assign it the built-in 13 gl_VertexID :

vertexID = (float)gl_VertexID;

This way, you'll get access 12 to gl_VertexID from the fragment shader, but 11 interpolated ! This is great because it 10 will be, for instance, 2 at one vertex, 3 9 at the neighbour, and 2.5 inbetween.

So you 8 just have to check if vertexID is close 7 to 2 (resp. 3) : if so, you're close to 6 an edge. That should be good enough for 5 visualisation & debug.

in float vertexID; # or
varying float vertexID;

// blabla

if (fract(vertexID) < 0.1){
    outcolor = vec4(1,0,0,0); # in glsl 4
}

Note that you'll 4 get only 2 edges of each triangle this way. And 3 maybe some will be ver thin ( if one vertexID 2 is 2 and the other 1000, the 0.1 zone is 1 little ).

Score: 2

Your question is not clear, but I guess 5 that you want to render both the filled 4 polygon AND the wireframe. Turns out that's 3 not so trivial. A classic way to solve the 2 problem is:

glPolygonMode( ... GL_FILL);
draw();
glPolygonOffset( param1, param2 );
glPolygonMode( ... GL_LINE );
draw();

but this is not without problems, such 1 as figuring out the values to pass to glPolygonOffset, etc.

More Related questions