# Thread: OpenGL Wierd **** - Order of Drawing Stuff?

1. ## OpenGL Wierd **** - Order of Drawing Stuff?

I am trying to figure out some wierd ****.

I have an object I defined as a cube which is for quadrilaterals as the faces,I couldn't figure out a cleverway to make it use a quad_strip with the vertices. Whatever. So, then I have a draw routine for it.

Code:
```void cube::draw(void)
{

glTranslatef(0.0f, 0.0f, -0.2f);
glRotatef(rotate / 2, 0, 1, 0);
glRotatef(rotate, 1, 0, 0);

for(int i = 0; i < 6; ++i)
{
glColor3f(colors[i].x, colors[i].y, colors[i].z);

for(int k = 0; k < 4; ++k)
{
glVertex3f(faces[i][k].x, faces[i][k].y, faces[i][k].z);
}
}

glEnd();
}```
And it does some wierd stuff. Dude! Like, so the thing is all rotating around n stuff. And then it seems like when some face is facing us, it may be drawn earlier than the one that is the back face, and then the backfaceappears to be the front. It's kind of hard to describe, it looks like that wierd figure-ground illusion with the wire cube with things jumping to the front and all. Here's a screenshot of it. http://img.photobucket.com/albums/v2...untitled-1.jpg I want to figure out how to make it just look like a solid cube instead of sometimes being able to 'see through it' or the illusion of that because things are drawn in front. Or, that'smy wierd hypothesis. Any ideas?

2. Are you using backface culling?
Are you using depth testing?
What is your near-clip set to?

3. I am not using backface culling. I don't know what depth testing is, and do not think I am using it. I believe my near clip is 0.1, and the far clip is 100.0f

4. >What is your near-clip set to?

x2

Move the box back a little and render it, it looks like your near clip is cutting it off.

5. Your near clipping plane is clipping that box. And from the photo you are obviously not using backface culling or you wouldn't see the other side of the cube after the clip since this would not change the clockwise or counter-clockwise orientation of the vertices for the backfaces.

6. Can you explain this sentence more?

>> And from the photo you are obviously not using backface culling or you wouldn't see the other side of the cube after the clip since this would not change the clockwise or counter-clockwise orientation of the vertices for the backfaces.

Does the orientation of the vertices matter or something? How consistent do they need to be?

7. I have something like this:

Code:
```cube::cube(point a, point b)
: rotate(0)
{
// Backface
faces[5][0] = point(b.x, a.y, b.z);
faces[5][1] = point(a.x, a.y, b.z);
faces[5][2] = point(a.x, b.y, b.z);
faces[5][3] = point(b.x, b.y, b.z);

// Rightsideface
faces[4][0] = point(b.x, a.y, b.z);
faces[4][1] = point(b.x, a.y, a.z);
faces[4][2] = point(b.x, b.y, a.z);
faces[4][3] = point(b.x, b.y, b.z);

//Leftsideface
faces[3][0] = point(a.x, a.y, a.z);
faces[3][1] = point(a.x, a.y, b.z);
faces[3][2] = point(a.x, b.y, b.z);
faces[3][3] = point(a.x, b.y, a.z);

// Frontface
faces[2][0] = point(b.x, a.y, a.z);
faces[2][1] = point(a.x, a.y, a.z);
faces[2][2] = point(a.x, b.y, a.z);
faces[2][3] = point(b.x, b.y, a.z);

// Topface
faces[1][0] = point(b.x, a.y, b.z);
faces[1][1] = point(a.x, a.y, b.z);
faces[1][2] = point(a.x, a.y, a.z);
faces[1][3] = point(b.x, a.y, a.z);

// Bottomface
faces[0][0] = point(b.x, b.y, b.z);
faces[0][1] = point(a.x, b.y, b.z);
faces[0][2] = point(a.x, b.y, a.z);
faces[0][3] = point(b.x, b.y, a.z);

// Colors dude
colors[0] = point(1.0f, 0.0f, 0.0f);
colors[1] = point(0.0f, 1.0f, 0.0f);
colors[2] = point(0.0f, 0.0f, 1.0f);
colors[3] = point(0.5f, 0.0f, 0.0f);
colors[4] = point(0.0f, 0.6f, 0.0f);
colors[5] = point(0.0f, 0.0f, 0.5f);

// cnormals();
}```
I changed it so all the vertices are clockwise, and I do not use normals in my code. I have a routine which tries calculating and hardcoding them but it doesn't seem to have any effect if it's there or not. I am not using backface culling, and I did resolve the clipping plane dealio, but I can still get pictures that look like the attachment.

8. Originally Posted by Tonto
Does the orientation of the vertices matter or something?
I am by no means an expert but I have read that the order of vertices does need to be clockwise.

9. >> I am by no means an expert but I have read that the order of vertices does need to be clockwise.

I found in this link in the section called 'winding' that the orientation does matter, and that counter-clockwise faces are seen as a front. http://www.quepublishing.com/article...&seqNum=7&rl=1 Well, all my faces are oriented in a counter-clockwise manner, does that mean they are all percieved as a front?

10. Code:
`glEnable(GL_DEPTH_TEST);`