Skip to main content
GameDev.net gamedev.net
🔒 Locked

new-bie needs help

Started by rick_st3 Jun 18, 2008 at 4:07 AM 20 replies 2.3k views
Original Post
rick_st3
rick_st3
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..!!!
zimerman
zimerman
glEnable( GL_DEPTH_TEST ); !?
Arkaras
Arkaras
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.
Arkaras
Arkaras
Quote:
Original post by zimerman
glEnable( GL_DEPTH_TEST ); !?

Enabling depth testing should normally happen in your Opengl context set up as well.
rick_st3
rick_st3
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...
rick_st3
rick_st3
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...
Lord_Evil
Lord_Evil
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!
rick_st3
rick_st3
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...
Lord_Evil
Lord_Evil
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!
rick_st3
rick_st3
alright here is when the cube looks like one....
Image Hosted by ImageShack.us



and here are the other views...
Image Hosted by ImageShack.us


and...

Image Hosted by ImageShack.us
rick_st3
rick_st3
now the colors might me different as i tried varying their sequence and colors...
dmatter
dmatter
Hopefully a silly question, but do you make sure to call both glEnd() and glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) each and every frame?
Also, if you were using the win32 API, you'd have to make sure to state the number of bits for the depth buffer - make sure you do whatever the equivalent is with Qt.
rick_st3
rick_st3
i have used an update() statement after glEnd()in Qt...that is equivalent to calling the same paint function recursively... and the paint function starts off with a glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) statement...
rick_st3
rick_st3
no i hadn't enabled that option initially but the i tried enabling it in the glInitialize() but then again the problem remains the same..!!
Lord_Evil
Lord_Evil
Could you please post the relevant update and drawing functions? Take care to use the [ source] and [ /source ] tags (without the spaces).
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!
rick_st3
rick_st3
alright here goes my paint function

GLvoid ric::paintGL(){	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glLoadIdentity();	glRotatef(rx,1.0,1.0,1.0);//	glRotatef(ry,0.0,1.0,1.0);//	glRotatef(rz,0.0,0.0,1.0);	glOrtho(-2.0,2.0,-2.0,2.0,-2.0,2.0);	glBegin(GL_QUADS);				glColor3f(0.0f,0.0f,1.0f);		glVertex3f(-1.0f,-1.0f,1.0f);		glVertex3f(1.0f,-1.0f,1.0f);		glVertex3f(1.0f,-1.0f,-1.0f);			//deep blue bottom		glVertex3f(-1.0f,-1.0f,-1.0f);		glColor3f(1.0f,0.0f,1.0f);		glVertex3f(-1.0f,1.0f,1.0f);		glVertex3f(-1.0f,-1.0f,1.0f);		glVertex3f(1.0f,-1.0f,1.0f);		glVertex3f(1.0f,1.0f,1.0f);				// pink front		glColor3f(0.0f,1.0f,1.0f);		glVertex3f(1.0f,-1.0f,-1.0f);			//sky blue right		glVertex3f(1.0f,1.0f,-1.0f);		glVertex3f(1.0f,1.0f,1.0f);		glVertex3f(1.0f,-1.0f,1.0f);		glColor3f(1.0f,1.0f,0.0f);		glVertex3f(-1.0f,1.0f,-1.0f);		glVertex3f(1.0f,1.0f,-1.0f);		glVertex3f(1.0f,1.0f,1.0f);		glVertex3f(-1.0f,1.0f,1.0f);				// yellow top		glColor3f(1.0f,0.0f,0.0f);		glVertex3f(1.0f,1.0f,-1.0f);		glVertex3f(1.0f,-1.0f,-1.0f);		glVertex3f(-1.0f,-1.0f,-1.0f);		glVertex3f(-1.0f,1.0f,-1.0f);			//red back		glColor3f(0.0f,1.0f,0.0f);		glVertex3f(-1.0f,1.0f,-1.0f);		glVertex3f(-1.0f,-1.0f,-1.0f);		glVertex3f(-1.0f,-1.0f,1.0f);			//green	left		glVertex3f(-1.0f,1.0f,1.0f);	glEnd();	rx += 0.05f;	ry += 0.05f;	rz += 0.05f;	update();}



now what the update function does in Qt is calls the PaintGL() function automatically...
stefanborries
stefanborries
Seems you have some sides wrong (back/front), I'm not sure which. You better take a look at the sides.
Lord_Evil
Lord_Evil
Assuming the current matrix mode is GL_MODELVIEW that glOrtho(-2.0,2.0,-2.0,2.0,-2.0,2.0); call should not be there. Move it to the initializer function and make sure the matrix mode is set to GL_PROJECTION.
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!
rick_st3
rick_st3
^^^^^

before or after glOrtho...??

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.