Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL - GL_FRONT versus GL_FRONT_AND_BACK

Tags:

opengl

I'm tinkering with an open source project that uses OpenGL for rendering in 3D. In the construction of the materials I see code like this:

// set ambient material reflectance
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mAmbient);

In other examples, this is used:

glMaterialfv(GL_FRONT, GL_AMBIENT, mAmbient);

So my question is, what is the difference here? Under what circumstances would it look different and, if my volume is enclosed with all normals pointing outwards, is there any performance difference?

like image 1000
Drew Noakes Avatar asked Feb 26 '23 20:02

Drew Noakes


1 Answers

One sets the material for front and back faces, the other, just front faces. If you culling back faces, it's not going to really matter. If you're not culling back faces, well, you'll see the material on the front face only.

If you're enclosing a volume, you probably won't directly see the back faces - the only way you would is if the camera was inside the volume. If it's outside, then you'll never see the back faces, and there's little point to rendering them. (Which is why in many games, if you force the camera into an object, it'll look like all the polygons are 1 sided: that's back face culling) OpenGL just has the ability to set different properties for the front and the back faces of a triangle/quad/etc.

like image 68
Thanatos Avatar answered Mar 06 '23 20:03

Thanatos