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

I would like to create a game in wireframe mode, but without glPolygoneMode I don’t know how I would do it. Is this something that I could combine with what's available? I am completely new to opengl. If someone did this and has a piece of code, I would love to see it. Any help is appreciated.

+4
source share
2 answers

Presumably you could display the whole scene using GL_LINES

+4
source

Unfortunately, you may have to actually completely convert your geometry into linear primitives and render them using GL_LINES . However, this, of course, is not easy to replace GL_TRIANGLES (or something else) with GL_LINES in your draw calls, you will have to completely reorder your vertices in order to adapt to the new primitive mode. This requires that you at least use different index arrays in glDrawElements... or, for non-indexed rendering ( glDrawArrays... ), generally different vertex arrays (although if you really decide to do this, this may be a good time to switching to indexed drawing instead).

However, if you have Geometry Shaders (although WebGL does not seem to support them, OpenGL ES should start with 3.2, as desptop GL does, but in any case it has the good old glPolygonMode ) and no longer uses them for something of another, everything becomes easier. In this case, you can simply set a fairly simple geometric shader between processing the vertex and the fragment, which takes triangles and displays 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 the correct block shader interface, you should be able to use your existing vertex and fragment shaders for the rest and just intercept this geometric shader between them to wireframe rendering all kinds of triangle-based primitives.

0
source

All Articles