PDA

View Full Version : PolygonMode front and back fill



chethan
04-18-2012, 05:28 AM
Hi folks, My question is on glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1.Is it possible to color on front and back faces of polygon triangle.
2.If yes how? give examples.

Advance thanks
regards
mmax

menzel
04-18-2012, 06:08 AM
I'm not quite sure what you mean.
With the given polygon mode, both, front and backfacing polygons will get rendered.
In GLSL you can check with gl_FrontFacing whether the fragment is from a front or backfacing polygon, so you can apply different materials this way.

Dan Bartlett
04-18-2012, 08:04 AM
If you're talking about controlling whether triangles should be culled when they are facing away from the camera (according to whether triangle vertices appear clockwise on screen or anti-clockwise), you could use:

glDisable(GL_CULL_FACE);
but the default value is disabled anyway. If you want to draw different colours on front + back, then you could use gl_FrontFacing in a shader as menzel said, or render twice with different values plugged into glCullFace.



glEnable(GL_CULL_FACE);

glCullFace(GL_FRONT);
#set up rendering properties for back faces#
DrawModel();

glCullFace(GL_BACK);
#set up rendering properties for front faces#
DrawModel();

chethan
04-18-2012, 07:52 PM
Thank you very much Dan.