Skip to main content
gamedev.net
🔒 Locked

Problem with Culling

Started by ne0_kamen Aug 15, 2006 at 5:29 AM 4 replies 950+ views
Original Post
ne0_kamen
ne0_kamen
Hi,It's my first post here ,but I have been watching the forums for about 3 months (since I started learning c++ and OpenGL :) ). Now to the question : I'm following some of the NeHe's tutorials but I have a little problem with the quadrics one.When I call gluCylinder() or any other glu primitive without backface culling I get this : Free Image Hosting at www.ImageShack.us And when I use glEnable(GL_CULL_FACE); I get this : Free Image Hosting at www.ImageShack.us The difference is obvious,right ? :) I khow that the job of the backface culling is to Cull(Not display) the backs of the objects so that we could get a better framerate.But the result is horrible...Any help would be appreciated. P.S.When I use backface culling and my own object(for example custom quad) the result is fine.So I don't think the problem is the culling settings. P.S2:Sorry if my English is full of errors,but I think you should understand what I wanted to ask :)
Rasmadrak
Rasmadrak
The obvious is that the bottom of the cylinder has its normals pointing the wrong way... post your code for drawing :)
"Game Maker For Life, probably never professional thou." =)
ne0_kamen
ne0_kamen
Well if the normals are pointing to the wrong way,why the problem exist even if I turn off lighting ?No matter,here is some parts of the code ,it's a bit of a mess ,you know :)

Code from my Init() function :
	quadratic = gluNewQuadric();	gluQuadricNormals(quadratic,GLU_SMOOTH);	gluQuadricTexture(quadratic,GL_TRUE);

Display function :
void Display()                  //Every Frame we call this function {	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);   //Actually clearing the buffer	glLoadIdentity();	gluLookAt(		0.0f, 0.0f, 10.0f,		0.0f, 0.0f, 0.0f,		0.0f, 1.0f, 0.0f);	setOrthographicProjection();	glPushMatrix();	glLoadIdentity();	renderBitmapString(-0.8,0.8,(void *)font,s,0.0f,.0f,1.0f,1.0f);	renderBitmapString(-0.8,0.7,(void *)font,s2,1.0f,1.0f,1.0f,0.0f);	renderBitmapString(-0.8,0.6,(void *)font,s3,1.0f,1.0f,1.0f,0.0f);	renderBitmapString(-0.8,0.5,(void *)font,s4,1.0f,1.0f,1.0f,0.0f);	glPopMatrix();	resetPerspectiveProjection();		glEnable(GL_TEXTURE_2D);	glBindTexture(GL_TEXTURE_2D,texture[0]);    glRotatef(xrot,1.0f,0.0f,0.0f);	glRotatef(yrot,0.0f,1.0f,0.0f);		switch(object)	{	case 0:		DrawCube();		break;	case 1:		gluCylinder(quadratic,1.0f,1.0f,3.0f,64,64);		break;	case 2:		gluDisk(quadratic,0.5f,1.5f,64,64);		break;	case 3:		gluSphere(quadratic,1.0f,64,64);		break;	case 4:		gluCylinder(quadratic,2.0f,0.0f,3.0f,64,64);		break;	case 5:		part1 += p1 ;		part2 += p2 ;		if(part1 > 359)		{			p1 = 0;			p2 = 1;			part1 = 0;			part2 = 0;		}		if(part2 > 359)		{			p1 = 1 ;			p2 = 0 ;		}		gluPartialDisk(quadratic,1.0f,1.5f,64,64,part1,part2 - part1);		break ;	}		glDisable(GL_TEXTURE_2D);	glutSwapBuffers();              //Changing the back and the front buffer	glFlush();                      //Execute any remaining functions}


And if the cylinder(and respectively its normals) is automaticaly generated from the glu library ,the normals should be OK,right ?
_the_phantom_
_the_phantom_
Quote:
Original post by ne0_kamen
I khow that the job of the backface culling is to Cull(Not display) the backs of the objects so that we could get a better framerate.But the result is horrible...Any help would be appreciated.


Thats more or less correct, by definition it removes back facing triangles, it bases this not on the normal but on the winding order of the triangles vertices (clockwise or counter-clockwise). The half of the cylinder which vanishes does so because you are seeing the back side of them, so the hardware/driver is culling them because they are back facing with regards to their winding order.

The best you can do here is draw without culling enabled as you want to see those triangles as such culling doesn't gain you anything...

_gl_coder_one_
_gl_coder_one_
What you are getting is correct !

Any polygon has two faces a front and a back one.
It is decided by the order in which the vertices have been specified Clockwise/anti-clockwise

In the second picture as you have enabled back face culling the
back faces the ones that lie in the inside of the cylinder are culled ( perhalps that is
how glu tesselates the cylinder )

thus you do not see them. The front ones are actually facing away from
the direction to the eye and hence are also culled( their normals point outside the sylinder ) . That is why you are seing a black region there.

Culling best works if you have a closed surface
ChaosWars
ChaosWars
If you want to achieve culling, you're going to have to write your own culling code to polygons with their normals at an angle > 90 degrees away from the camera.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.