Sign in to follow this  

Confused: Culling Problem

This topic is 3318 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

Hiya, My culling appears to be inverted and I can't tell why. Everyone I've asked insists that I'm drawing the face anti-clockwise and I have glFrontFace set to CCW.
// This function sets up the projection and stuff
OnCreate()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(65, (_Width / _Height), 1, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0,0, _Width, _Height);
glEnable(GL_DEPTH_TEST);
// set the background clear colour to black
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// set the shade model to smooth (Gouraud shading)
glShadeModel(GL_SMOOTH);
glFrontFace(GL_CCW);
// remove back faces
glEnable(GL_CULL_FACE);
}

// This function is called every frame
OnDraw()
{
glPushMatrix();
glTranslatef(0.0f, -150.0, -500.0f); // Translate world, 150 down Y and 500 into screen. Emulates moving "camera" 150 UP y and 500 out of screen.
_TrackManager->DrawMap();
glPopMatrix();
SwapBuffers();

// There's actually an iterator here to draw through the different track parts.
// I have set it to draw the first part only.
// _Width is 153 (confirmed with Breakpoint) and _Length is 78 (confirmed with breakpoint)

_TrackManager::DrawMap()
{
	cout << "Drawing: " << _Name << " at " << _trackPosition.x()
		<< " " << _trackPosition.y() << " " <<  _trackPosition.z() << endl;
	glBegin(GL_QUADS);
		// Top Face
		glColor3f(1.0, 0.0, 0.0);
		
		glNormal3f(0.0, 1.0, 0.0);
		glVertex3f(0.0, 0.0, 0.0);
		glVertex3f(_Width, 0.0, 0.0f);
		glVertex3f(_Width, 0.0, -_Length);
		glVertex3f(0.0, 0.0, -_Length);
	glEnd();
}

My methodology here is that I want to draw the face at the origin, move to the right, then move down the negative z axis (into the screen), and return to the x origin. Any help understanding this would be appreciated. Thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ehrys
My culling appears to be inverted and I can't tell why. Everyone I've asked insists that I'm drawing the face anti-clockwise and I have glFrontFace set to CCW.
An easy test for this is to set glFrontFace to GL_CW, and see if the culling is correct. In that case you know that you are rendering in the opposite order.

Share this post


Link to post
Share on other sites
Setting FrontFace to CW does show the top face. Yet if I stick to the same winding pattern to draw a cuboid, the front face won't show.

Does the fact I'm drawing down the negative x axis invert the winding?

EDIT: Hmm I seem to have found the source of the confusion.

Drawing down the positive z Axis draws *into* the screen. Yet when translating, the negative z axis moves into the screen.

Is this normal behaviour? Or have I really done something bad somewhere :S

[Edited by - Ehrys on November 13, 2008 9:02:58 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Ehrys
Does the fact I'm drawing down the negative x axis invert the winding?
It is not inverted, but you do have to take into account the fact that you are looking from the back (i.e. the invisible side), rather than the front. So in relation to a fixed viewer, yes, it does seem inverted.
Quote:
Drawing down the positive z Axis draws *into* the screen. Yet when translating, the negative z axis moves into the screen.
glTranslate translates the world relative to the camera, not the camera relative to the world.

Share this post


Link to post
Share on other sites
EDIT: I'm retarded, it's a fact. I had a negative sign somewhere I shouldn't have. I can't believe I missed that =/

Sorry for wasting your time >.<

Share this post


Link to post
Share on other sites

This topic is 3318 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this