简体   繁体   中英

OpenGL strange render using GL_TRIANGLES

I'm getting a strange effect rendering these spheres/cylinders I coded myself.

The vertices and indices are correct, since when I use GL_LINE_STRIP in glDrawElements instead of GL_TRIANGLES, my objects are rendering as intended, so there's no duplicated vertices, but when I invert the indices order, I get the same effect.

Here arethe objects rendered with GL_TRIANGLES, and you can see these inner circles being rendered within them:

http://imgur.com/4ocO2Bt

Here are the objects with GL_LINE_STRIP, and the geometry looks fine to me:

http://imgur.com/f0wGNC1

My vertex shader code is a standard MVP * vertex position transform, and pixel shader code is just outputting a color with nothing else done.

And just to be clear, even if I invert the indices, I still get the exact same image with GL_TRIANGLES, I still see through the object, with the same exact circles inside the mesh.

If glCullFace ( GL_FRONT); fixes your problem and you intend to render the geometry with lighting then you should do one of these:

Your triangles are drawn in CW(clockwise) fashion thus OpenGL calculates that the triangles closer to you are facing backwards and culls them since default is glCullFace ( GL_BACK); You can simply call it with GL_FRONT and fix the problem. However, when you are going to calculate the normal for the triangle the normal will be at the opposite direction. You can invert the normal or fix it with drawing triangles in CCW.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM