ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.