I would like to create a game in wireframe mode however without the glPolygoneMode command I don't know how I would do it. Is it something I could code myself with what is available? I'm completely new to opengl. If anyone has done this and has the code snippet I would love to see it. Any help is appreciated.
Unfortunately, you might have to actually completely convert your geometry to line primitives and render them using GL_LINES
. However, it is of course not done by simply replacing GL_TRIANGLES
(or whatever) with GL_LINES
in your draw calls, you will have to entirely reorder your vertices to accomodate for the new primitive mode. This requires you to at least use different index arrays in glDrawElements...
calls or, for non-indexed rendering (glDrawArrays...
), different vertex arrays altogether (though, in case you really choose to do that, this might be the right moment to switch to indexed drawing instead).
If, however, you have Geometry Shaders available (though, it seems WebGL doesn't support them, OpenGL ES should since 3.2, as does desptop GL but that has good old glPolygonMode
anyway) and don't already use them for something else, things get easier. In this case you can just install a rather simple geometry shader between the vertex and fragment processing that takes triangles and outputs 3 lines for each of them:
layout(triangles) in;
layout(line_strip, max_vertices=4) out;
void main()
{
for(int i=0; i<4; ++i)
{
// and whatever other attributes of course
gl_Position = gl_in[i%3].gl_Position;
EmitVertex();
}
}
If you use proper block-based shader interfacing, you should be able to use your existing vertex and fragment shaders for the rest and just hook that geometry shader in between them for the wireframe rendering of all kinds for triangle-based primitives.
Conceivably you could render the entire scene using GL_LINES
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