Public Group

# GL_QUADS gives me wierd visual result?

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

## Recommended Posts

I am running through some of the tutorials at gametutorials.com showing how to use OpelGL, which has been very good so far .... But with using the GL_QUADS (Cubes) I get funny looking cubes which look like THIS (click). And the code I'm using to render the cube is pasted directly from the tutorial and looks like this:
    static float rotX = 0.0f, rotZ = 0.0, rotY = 0.0f;
double x = -1.5;
double y = -1.5;
double z = -1.5;

glRotatef(rotX, 1.0f, 0.0f, 0.0f);
glRotatef(rotY, 0.0f, 1.0f, 0.0f);
glRotatef(rotZ, 0.0f, 0.0f, 1.0f);

// These vertices create the Back Side
glColor3ub(0, 0, 255);   glVertex3f(x, y, z);
glColor3ub(255, 0, 255); glVertex3f(x, y + radius, z);
glColor3ub(0, 255, 255); glVertex3f(x + radius, y, z);
// These vertices create the Front Side
glColor3ub(0, 0, 255);   glVertex3f(x, y, z + radius);
// These vertices create the Bottom Face
glColor3ub(0, 0, 255);   glVertex3f(x, y, z);
glColor3ub(255, 0, 255); glVertex3f(x, y, z + radius);
glColor3ub(0, 255, 255); glVertex3f(x + radius, y, z);
// These vertices create the Top Face
glColor3ub(0, 0, 255);   glVertex3f(x, y + radius, z);
// These vertices create the Left Face
glColor3ub(0, 0, 255);   glVertex3f(x, y, z);
glColor3ub(255, 0, 255); glVertex3f(x, y, z + radius);
glColor3ub(0, 255, 255); glVertex3f(x, y + radius, z);
// These vertices create the Right Face
glColor3ub(0, 0, 255);   glVertex3f(x + radius, y, z);
glEnd();

rotX += 0.3f;
rotY += 0.3f;
rotZ += 0.8f;

well, the display functions I left as-is, and I moved around the integers and whatnot to make it work in my environment. Does anyone know why its doing that?

##### Share on other sites
I compiled the code and as far as i know the cube looked fine.
What _exactly_ is the problem?

##### Share on other sites
I would check that:

- GL_DEPTH_TEST is enabled
- glDepthFunc is GL_LEQUAL (or GL_LESS)
- The projection matrix is not stuffed, and not getting mixed up with GL_MODELVIEW

##### Share on other sites

Quote:
 Original post by sand_manThat link didnt work.I compiled the code and as far as i know the cube looked fine.What _exactly_ is the problem?

The problem is that when the cube rotates it seems to lose faces and draw some on top of another when they really shouldnt be etc... Like sometimes when it is faced at a certain angle you can see that a face exists but when you turn to face it it isnt there (along with an ajacent one). Some other ones from the back are projecting over the top of ones at the front.

That sorta stuff.

hh10k, I'm an extreme n00b and dont really understand how to use those, but I'll give them a shot to best of my ability.

Thank you fella's :)

##### Share on other sites
offhand i think you may be winding in clockwise order, so unless youre specifiying clockwise winding, that could be a problem, though only if youve enabled backface culling should it be a problem (i think) and i dont htink itd cause your problem.

Are you using GLUT? If so you need to tell glut youre using the depth buffer. I believe that is most liekly what is causing your problem. If you're using SDL, theres probably something similar but as I havent used SDL, I couldnt tell you.

##### Share on other sites
if youre using GLUT make sure you have GLUT_DEPTH or'd into your mode for glutInitDisplayMode
ie:
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH)

##### Share on other sites
I'm using SDL ....

I dont know how to impliment the paramets that hh10k speaks of.

As I said, I copied that code straight out of a tutorial which was written using Dev-C++ (which is what I use), so it strikes me very strange that its doing this ...

... thinking of it now though .... I didnt copy the entire tutorial, only the cude bit which I dumped into a previous application .... so maybe I should read the rest of the tutorial to see if they initialised OpelGL differently :-)

Sorry for being this mindless ! I'll be home in around 9 hours to give it a shot :-)

##### Share on other sites
ok, not ever doing any of this with SDL im a little fuzzy on it, but looking at the site youre using, and looking at some of the code there, ill proffer a few suggestions for places to look.

In void SetupPixelFormat(void):

SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, SCREEN_DEPTH); // size of depth buffer

also, as mentioned above. make sure
glEnable(GL_DEPTH_TEST);
is included. the source from gametutorials has it in their IntializeOpenGL() function

Hopefully some of this is being helpful to you.

##### Share on other sites
woohoo, enabling GL_DEPTH_TEST was the problem!

:-)

Thanks guys.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633730
• Total Posts
3013580
×