Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a substitute for glPolygonMode in Open GL ES/WebGL?

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.

like image 683
Xavier Avatar asked Aug 21 '10 22:08

Xavier


2 Answers

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.

like image 154
Christian Rau Avatar answered Nov 09 '22 19:11

Christian Rau


Conceivably you could render the entire scene using GL_LINES

like image 36
bobobobo Avatar answered Nov 09 '22 19:11

bobobobo