Problems CULLING my polygons..
i am having problems culling my polygons..i have been trying different things then decided just to test it on a simple 3-d cube that i drew. here is my code , but i am not getting the results i look for. its like the sides are culled when the cube is rotating.., the back side looks fine, everything else is messed up..thanks for your help in advance!
glTranslatef(0, 0, -4);
glRotatef(rot, 0, 1, 0);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
//glFrontFace(GL_CCW);
glBegin(GL_QUADS);
//front face
glVertex3f(0, 0, 0);
glVertex3f(1, 0, 0);
glVertex3f(1, -1, 0);
glVertex3f(0, -1, 0);
//right side
glVertex3f(1, 0, 0);
glVertex3f(1, 0, -1);
glVertex3f(1, -1, -1);
glVertex3f(1, -1, 0);
//back side
glVertex3f(0, 0 , -1);
glVertex3f(1, 0, -1);
glVertex3f(1, -1, -1);
glVertex3f(0, -1, -1);
//left side
glVertex3f(0, 0, 0);
glVertex3f(0, 0, -1);
glVertex3f(0, -1, -1);
glVertex3f(0, -1, 0);
//top side
glVertex3f(0, 0, 0);
glVertex3f(1, 0, 0);
glVertex3f(1, 0, -1);
glVertex3f(0, 0, -1);
glEnd();
glDisable(GL_CULL_FACE);
heh
Culling is based on the winding order.
So when you call :
//front face
glVertex3f(0, 0, 0);
glVertex3f(1, 0, 0);
glVertex3f(1, -1, 0);
glVertex3f(0, -1, 0);
//back side
glVertex3f(0, 0 , -1);
glVertex3f(1, 0, -1);
glVertex3f(1, -1, -1);
glVertex3f(0, -1, -1);
There is a problem because the winding order is respected for the front and back sides. BUT this should be inverted, since front and back sides are facing different ways, isn't it ?
For instance you should revert the two first and two last vertices of the back side :
//back side
glVertex3f(1, -1, -1);
glVertex3f(0, -1, -1);
glVertex3f(0, 0 , -1);
glVertex3f(1, 0, -1);
in order to reverse the winding order.
PS: as a side note, it's easier to see which face is culled or not using face colouring (call glColor before each face, with a different color for every face).
So when you call :
//front face
glVertex3f(0, 0, 0);
glVertex3f(1, 0, 0);
glVertex3f(1, -1, 0);
glVertex3f(0, -1, 0);
//back side
glVertex3f(0, 0 , -1);
glVertex3f(1, 0, -1);
glVertex3f(1, -1, -1);
glVertex3f(0, -1, -1);
There is a problem because the winding order is respected for the front and back sides. BUT this should be inverted, since front and back sides are facing different ways, isn't it ?
For instance you should revert the two first and two last vertices of the back side :
//back side
glVertex3f(1, -1, -1);
glVertex3f(0, -1, -1);
glVertex3f(0, 0 , -1);
glVertex3f(1, 0, -1);
in order to reverse the winding order.
PS: as a side note, it's easier to see which face is culled or not using face colouring (call glColor before each face, with a different color for every face).
too bad that you cant send attachments on here so i could send you the .exe so you could see what was going on.. i changed the winding order and i have the book , Beginning Game Programming, which is actually the 2nd version of the openGL game programming. it talks about it in there as well. but i still am getting the same results regardless what order i try..im sure there is something i am doing wrong i just dont see it..
heh
Simply email it to me.
What do you mean by "i still am getting the same results regardless what order i try" ? The same polygons are alwyas culled, whatever the order you setup ? When you use another winding order (glCullFace(GL_FRONT) or glCullFace(GL_BACK) and/or glFrontFace(GL_CW) and glFrontFace(GL_CCW)) the same polygons are culled too ?!
What do you mean by "i still am getting the same results regardless what order i try" ? The same polygons are alwyas culled, whatever the order you setup ? When you use another winding order (glCullFace(GL_FRONT) or glCullFace(GL_BACK) and/or glFrontFace(GL_CW) and glFrontFace(GL_CCW)) the same polygons are culled too ?!
ok what is your email? ill send you the .exe zipped up so you can see what it is doing as is....thanks!
not the same polygons arent culled but i just meant it wasnt working regardless of what i have tried..as far as ordering my vertices and tring FrontFace etc etc
not the same polygons arent culled but i just meant it wasnt working regardless of what i have tried..as far as ordering my vertices and tring FrontFace etc etc
heh
ok what is your email? ill send you the .exe zipped up so you can see what it is doing as is....thanks!
not the same polygons arent culled but i just meant it wasnt working regardless of what i have tried..as far as ordering my vertices and tring FrontFace etc etc
not the same polygons arent culled but i just meant it wasnt working regardless of what i have tried..as far as ordering my vertices and tring FrontFace etc etc
heh
Isn't my e-mail adress available in my profile ?
It's <nickname> 'at' netscape 'dot' net. (Sure you know what my nickname is).
While you're at it, can you also provide the source code so that I can test few things on it ? TIA.
It's <nickname> 'at' netscape 'dot' net. (Sure you know what my nickname is).
While you're at it, can you also provide the source code so that I can test few things on it ? TIA.
no your email is not on your profile :) ok ill zip up the source and exe and send it to you..lemme know what you find , think or whatever :)
heh
Ok, my bad ^^
I thought I had the e-mail in the profile. Now I restored it.
In fact I was confusing you (and myself) because the 1234 quad is not reversed by 3412 as I told you. It's reversed thanks to 1432. Considering the winding order is CCW (which is the most common winding order AFAIK, and is the default OpenGL) your cube would become :
I thought I had the e-mail in the profile. Now I restored it.
In fact I was confusing you (and myself) because the 1234 quad is not reversed by 3412 as I told you. It's reversed thanks to 1432. Considering the winding order is CCW (which is the most common winding order AFAIK, and is the default OpenGL) your cube would become :
glFrontFace(GL_CCW); glBegin(GL_QUADS); //front face glVertex3f(1, -1, 0); glVertex3f(1, 0, 0); glVertex3f(0, 0, 0); glVertex3f(0, -1, 0); //right side glVertex3f(1, -1, -1); glVertex3f(1, 0, -1); glVertex3f(1, 0, 0); glVertex3f(1, -1, 0); //back side glVertex3f(1, -1, -1); glVertex3f(0, -1, -1); glVertex3f(0, 0 , -1); glVertex3f(1, 0, -1); //left side glVertex3f(0, 0, 0); glVertex3f(0, 0, -1); glVertex3f(0, -1, -1); glVertex3f(0, -1, 0); //top side glVertex3f(0, 0, 0); glVertex3f(1, 0, 0); glVertex3f(1, 0, -1); glVertex3f(0, 0, -1);glEnd();
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement