# Confused: Culling Problem

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

## 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);
gluPerspective(65, (_Width / _Height), 1, 1000);
glMatrixMode(GL_MODELVIEW);
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);
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;
// 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 on other sites
Quote:
 Original post by EhrysMy 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 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 on other sites
Quote:
 Original post by EhrysDoes 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 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 >.<

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634134
• Total Posts
3015751
×