GL_QUADS gives me wierd visual result?

Started by
7 comments, last by xyuri 19 years, 4 months ago
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;
    int radius = 3;
    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);

    glBegin(GL_QUADS);        
    // 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 + 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);
    glColor3ub(255, 0, 255); glVertex3f(x, y + radius, z + radius);
    glColor3ub(0, 255, 255); glVertex3f(x + radius, y + radius, z + radius); 
    glColor3ub(0, 255, 255); glVertex3f(x + radius, 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 + 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);
    glColor3ub(255, 0, 255); glVertex3f(x, y + radius, z + radius);
    glColor3ub(0, 255, 255); glVertex3f(x + radius, y + radius, z + radius); 
    glColor3ub(0, 255, 255); glVertex3f(x + radius, 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 + 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);
    glColor3ub(255, 0, 255); glVertex3f(x + radius, y, z + radius);
    glColor3ub(0, 255, 255); glVertex3f(x + radius, y + radius, z + radius); 
    glColor3ub(0, 255, 255); glVertex3f(x + radius, y + radius, 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?
__________Michael Dawson"IRC is just multiplayer notepad." - Reverend
Advertisement
That link didnt work.
I compiled the code and as far as i know the cube looked fine.
What _exactly_ is the problem?
I would check that:

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

Quote:Original post by sand_man
That link didnt work.
I compiled the code and as far as i know the cube looked fine.
What _exactly_ is the problem?
Sorry about the link, tis a silly host ... anyways ...

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 :)
__________Michael Dawson"IRC is just multiplayer notepad." - Reverend
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.
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)
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 :-)
__________Michael Dawson"IRC is just multiplayer notepad." - Reverend
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.
woohoo, enabling GL_DEPTH_TEST was the problem!

:-)

Thanks guys.
__________Michael Dawson"IRC is just multiplayer notepad." - Reverend

This topic is closed to new replies.

Advertisement