开发者

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

开发者 https://www.devze.com 2023-01-12 08:23 出处:网络
I would like to create a game in wireframe mo开发者_开发百科de 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\'

I would like to create a game in wireframe mo开发者_开发百科de 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

0

精彩评论

暂无评论...
验证码 换一张
取 消