LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-07-2005, 10:46 PM   #1
1337 Twinkie
Member
 
Registered: Jul 2004
Distribution: Fedora Core 2
Posts: 79

Rep: Reputation: 15
Backface Culling in OpenGL


I know that by default, OpenGL will do backface culling. Is there a way to turn it off?

If there is not (and even if there is), how does one reverse the normals of a polygon? I have tried reversing the order of the verticies, but to no avail.

PS- The polygons in question are quads

-Thanks in advance.
 
Old 01-07-2005, 11:15 PM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Actually, I don't think that culling is on by default. You enable and disable it using the following (default is disabled):

glEnable(GL_CULL_FACE);
glDisable(GL_CULL_FACE);

You can specify to cull front or back by using the following ( default is GL_BACK):

glCullFace(GL_FRONT /* or GL_BACK or even GL_FRONT_AND_BACK */);

OpenGL doesn't use normals to determine which is the front and which is the back. It actually uses the winding order of the polygon. The default is counter clockwise, but you can change that using:

glFrontFace(GL_CW /* or GL_CCW */);

To reverse the direction of a normal, you simply multiply it by -1. OpenGL doesn't calculate normals for you, you need to actually supply them yourself. Generally to get the normal of a face, you take the cross product of 2 of the edges, which gives you a vector that is perpendicular to them both...

Are you running into some specific problem? Try to describe that in more detail and maybe we can help.

Last edited by deiussum; 01-07-2005 at 11:17 PM.
 
Old 01-08-2005, 12:03 AM   #3
1337 Twinkie
Member
 
Registered: Jul 2004
Distribution: Fedora Core 2
Posts: 79

Original Poster
Rep: Reputation: 15
The specific problem was that the object was "inside out".

Enabling culling and telling it to cull the backs of faces fixed it.

Thanks for the help!
 
Old 01-08-2005, 09:10 AM   #4
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Could it be that the real problem is that you did not enable depth testing? In Linux, you not only need to enable depth testing (glEnable(GL_DEPTH_TEST);), you also need to create your context to have a depth buffer (Windows seems to usually have a depth buffer by default, Linux doesn't in my experience).

How you do that depends on exactly how you are creating your window. For instance, with Glut, you include GLUT_DEPTH in the options of the glutInitDisplayMode call. Also, you need to add GL_DEPTH_BUFFER_BIT to your glClear call. (e.g. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);)

Enabling backface culling is always good anyway to improve performance, but having it off shouldn't have made the object look "inside out" if the depth testing was working correctly.

Last edited by deiussum; 01-08-2005 at 09:16 AM.
 
Old 01-08-2005, 12:35 PM   #5
1337 Twinkie
Member
 
Registered: Jul 2004
Distribution: Fedora Core 2
Posts: 79

Original Poster
Rep: Reputation: 15
Yup. That was it. After performing a few more tests, I became less sure that the problem had to do with culling, since the visibility of faces also changed with the camera angle!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Culling Data from a CSV file to output in excel jterr02 Programming 2 05-19-2006 04:58 AM
Overwrite Mesa OpenGL with ATI OpenGL Carl-Fredrik Slackware 12 10-01-2004 03:33 PM
Culling Slack 10 Diademed Linux - Newbie 7 09-19-2004 08:25 PM
Changing from MESA OpenGL to ATI OpenGL tillyoubreakit Linux - Hardware 19 10-07-2003 07:32 PM
OpenGL is needed by plib-1.7.0- but i have opengl ! qwijibow Linux - Newbie 0 08-05-2003 07:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration