new-bie needs help

Started by
20 comments, last by rick_st3 15 years, 10 months ago
Alright... I have just started learning opengl a week ago and am in a problem...i wrote a code to rotate a 3d cube on the vector (1.0f,1.0f,1.0f)...The cube does rotate on the axis but,well,it does not look like a cube..it looks something else.. Here are the coordinates which i plotted... glBegin(GL_QUADS); glColor3f(1.0f,1.0f,0.0f); glVertex3f(0.25f,0.25f,-0.25f); glVertex3f(-0.25f,0.25f,-0.25f); glVertex3f(-0.25f,0.25f,0.25f); //top glVertex3f(0.25f,0.25f,0.25f); glColor3f(0.0f,1.0f,0.0f); glVertex3f(-0.25f,0.25f,0.25f); glVertex3f(-0.25f,0.25f,-0.25f); glVertex3f(-0.25f,-0.25f,-0.25f); glVertex3f(-0.25f,-0.25f,0.25f); //left glColor3f(1.0f,0.0f,0.0f); glVertex3f(0.25f,-0.25f,-0.25f); glVertex3f(-0.25f,-0.25f,-0.25f); glVertex3f(-0.25f,0.25f,-0.25f); //back glVertex3f(0.25f,0.25f,-0.25f); glColor3f(0.0f,0.0f,1.0f); glVertex3f(-0.25f,-0.25f,0.25f); glVertex3f(-0.25f,-0.25f,-0.25f); glVertex3f(0.25f,-0.25f,-0.25f); //bottom glVertex3f(0.25f,-0.25f,0.25f); glColor3f(1.0f,0.0f,1.0f); glVertex3f(-0.25f,0.25f,0.25f); glVertex3f(-0.25f,-0.25f,0.25f); glVertex3f(0.25f,-0.25f,0.25f); glVertex3f(0.25f,0.25f,0.25f); //front glColor3f(0.0f,1.0f,1.0f); glVertex3f(0.25f,0.25f,-0.25f); glVertex3f(0.25f,0.25f,0.25f); glVertex3f(0.25f,-0.25f,0.25f); glVertex3f(0.25f,-0.25f,-0.25f); //right during the rotation when the bottom,front and right faces come towards the front only then it resembles a cube i.e. only den you can see three colors/face or else for all other positions there are more then 3 colors which makes the window a mess... please help..!!!
Advertisement
glEnable( GL_DEPTH_TEST ); !?
Its actually working perfectly. In order to not have this problem,you will need to turn on depth testing when you initialize your Opengl Context. Otherwise Opengl has no clue what side you want to look at. But in fact it is correctly being drawn, without depth testing.
Quote:Original post by zimerman
glEnable( GL_DEPTH_TEST ); !?

Enabling depth testing should normally happen in your Opengl context set up as well.
alright here goes my initialize function


GLvoid ric::glInitialize()
{
glClearColor(0.0f,0.0f,0.0f,0.0f);
glShadeModel(GL_SMOOTH);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

rquad = 0.0f;
}

now inspite of my enabling the depth testing m facing this problem...
Also do I have to imply display lists in order to get a complete rotating cube view..??

oh yes...i am using opengl with Qt actually...
And also i would like to know whether it is possible to paint the entire cube with the same color,say green, with just the edges having a different color,say black..?? thanks...
Drawing a green cube with black edges would require to draw the cube twice (if you don't use textures or shaders). So you basically draw the green cube (all vertices green) in fill mode and then change the color to black and either draw the quads in wireframe mode (which might give you diagonal lines if the quads are split into triangles by the driver) or draw the edges as individual lines. Just remember to change the depth comparison mode to GL_EQUAL or GL_LEQUAL, so that the lines drawn on top of the quad pass the depth test (they basically have the same depth as the quads).

Edit: Ah, I just reread your code. Where do those additional color appear? If only at the edges it could be due to GL_LEQUAL since at the edges the fragments produces by two quads might have the same depth.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
no actually the colors of the bottom three faces seem to overlap all the other colors even if one of the bottom three faces was supposed to b on the back side in that instance... and also if the bottom three faces overlap each other then the one latter included is on the top even if it is not supposed to be...
I think it would be the best if you showed us some screen shots so we can see what's going on.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
alright here is when the cube looks like one....
Image Hosted by ImageShack.us<br/>


and here are the other views...
Image Hosted by ImageShack.us<br/>

and...

Image Hosted by ImageShack.us<br/>

This topic is closed to new replies.

Advertisement