glPolygoneMode(GL_FRONT_AND_BACK, GL_FILL) is ON, and how can I get wireframe at this situation? Is there any way to get wireframe rendering without switch Polygone Mode to GL_LINE?
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
Fill fills it... you want lines.
EDIT: Remember, you can always put it back to fill when you're done, like this
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
// add polygons here
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
From your question I assume you have some huge middleware, and have only access to shaders, am I right ?
In this case, create in your vertex shader a varying called, for instance, vertexID :
varying float vertexID; # in GLSL <= 3, or
out float vertexID; # in GLSL 4
and assign it the built-in gl_VertexID :
vertexID = (float)gl_VertexID;
This way, you'll get access to gl_VertexID from the fragment shader, but interpolated ! This is great because it will be, for instance, 2 at one vertex, 3 at the neighbour, and 2.5 inbetween.
So you just have to check if vertexID is close to 2 (resp. 3) : if so, you're close to an edge. That should be good enough for 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 get only 2 edges of each triangle this way. And maybe some will be ver thin ( if one vertexID is 2 and the other 1000, the 0.1 zone is little ).
Your question is not clear, but I guess that you want to render both the filled polygon AND the wireframe. Turns out that's not so trivial. A classic way to solve the problem is:
glPolygonMode( ... GL_FILL);
draw();
glPolygonOffset( param1, param2 );
glPolygonMode( ... GL_LINE );
draw();
but this is not without problems, such as figuring out the values to pass to glPolygonOffset, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With