Jump to content
  • Advertisement
Sign in to follow this  
rick_st3

OpenGL new-bie needs help

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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..!!!

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by zimerman
glEnable( GL_DEPTH_TEST ); !?

Enabling depth testing should normally happen in your Opengl context set up as well.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!