What's wrong with this stupid code? SOLVED

Started by
7 comments, last by Hellraiser666 16 years, 3 months ago
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]
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..
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
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.
nope, sorry
glFrontFace(...); ?
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
glFrontface(); aint doing the trick either :s

Hellraiser666
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

This topic is closed to new replies.

Advertisement