Jump to content
  • Advertisement
Sign in to follow this  
Hellraiser666

OpenGL What's wrong with this stupid code? SOLVED

This topic is 3907 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm having a very stupid problem with openGL, I've searched the web (kinda hard to desrcibe the problem in search terms though), and I wasn't able to fix it. The problem is fairly easy: When I render a simple sphere (via freeglut), all is ok. But now when I set the scene to perspective mode (via gluPerspective), I set the camera (via gluLookAt) and enable backface culling, the sphere becomes all messed up. It isn't backface culled at all, it seems to be randomly culled.
//Initialising the scene

glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,1.0,0.0,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//Eye,look and up are a vector class, the x(),y() and z() functions give a float
//which represents the x,... values	
 gluLookAt(eye.x(),eye.y(),eye.z(),look.x(),look.y(),look.z(),up.x(),up.y(),up.z());

//Render function
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotated(ang,0.0,1.0,0.0);
glutWireSphere(10,30,30);
glPopMatrix();
ang++;
glFlush();
glutSwapBuffers();

//Glut created the window with:
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);


This is what i get as output Can someone please tell me what I did wrong?? Thanks in advance, Hellraiser666 [Edited by - Hellraiser666 on January 14, 2008 2:00:35 PM]

Share this post


Link to post
Share on other sites
Advertisement
near plane is to close, try 'gluPerspective(45.0,1.0,0.1,100.0);'
also if that doesnt work you might want to try something like 'gluPerspective(45.0, (GLfloat)width/(GLfloat)height, 0.1, 100.0);' Thats how I always do it..

Share this post


Link to post
Share on other sites
Right, that solves the random culling. Thank you very much for that!

But now i still don't have backface culling on the sphere. Any ideas there?

Hellraiser666

Share this post


Link to post
Share on other sites
how do you know? Back face culling means it doesn't draw the backside of a polygon aka the part you can't see. Front and back are determined by winding. If I remember correctly Clock wise is front by default CC is back by default.

Share this post


Link to post
Share on other sites
Well, since a sphere has the nice habbit of having 2 conversion points (the poles), i can tell that the backfaces are not deleted. If they are deleted, i should be able to see only one of these spots at the time (most of the time). I'm seeing them both, so I don't think they are deleted.

The only possibility that i would be able to see them both, is if the wiresphere coats the innerside of the sphere as well. (unlikely)

I'm still stuck at the backface culling it seems :s

Share this post


Link to post
Share on other sites
I guess i have to take my words back on that "coated on the inside " thingy, freeglut does seem to do it! I replaced the sphere with a polygon quad and now it is correctly culled.

Thx for the help

Hellraiser

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!