3D to Ortho displays 3D then 3D dissappears!

Started by
3 comments, last by aewarnick 20 years, 2 months ago
This is annoying. I am trying to draw in 3D in the first part of my code and then switch to Ortho to draw in mouse coordinates but when I change the mode to projection for ortho, a weird thing happens! All the 3D code (in the loop) appears and vanishes. All that is left is the Ortho mode''s drawing.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	for(BYTE i=0; i<3; i++)
	{
		if(i==0)
		{
			glTranslatef(xAxis, yAxis, -4.5);
			glRotatef(tick, 0, 0, 1);
			//glColor4f(1, 1, 1, .5);

			glScalef(3.3, 2.9, 1);
		}
		else if(i==1)
		{
			glTranslatef(-1, 0, -3.5);
			glRotatef(tick, 1, 0, 0);
			glColor4f(1, 1, 1, .7);
		}
		else
		{
			glTranslatef(1, 0, -3.5);
			glRotatef(tick, 0, 1, 0);
			//glColor4f(1, 1, 1, 1-alp);
		}
	glBegin(GL_QUADS);
	glTexCoord2f (0, 0); glVertex3f (-1.0f, -1.0f, 0);
	glTexCoord2f (1, 0); glVertex3f (1.0f, -1.0f, 0);
	glTexCoord2f (1, 1); glVertex3f (1.0f, 1.0f, 0);
	glTexCoord2f (0, 1); glVertex3f (-1.0f, 1.0f, 0);
    glEnd ();

		glLoadIdentity();
	}

	glColor3f(1,1,1);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	//gluOrtho2D(0, this->ClW, this->ClH, 0);
	glOrtho(0, this->ClW, this->ClH, 0, -abmp.W, abmp.H);
	glTranslatef(mouseX, mouseY, 0);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glBegin(GL_QUADS);
	glTexCoord2f (0.0f,0.0f); glVertex2f (-abmp.W/2, -abmp.H/2);
    glTexCoord2f (1.0f, 0.0f); glVertex2f (abmp.W/2, -abmp.H/2);
    glTexCoord2f (1.0f, 1.0f); glVertex2f (abmp.W/2, abmp.H/2);
    glTexCoord2f (0.0f, 1.0f); glVertex2f (-abmp.W/2, abmp.H/2);
    glEnd (); 
*C++*->
Advertisement
My mistake, as far as I know the code is ok. I was having the problem because of a timer.
*C++*->
Wrong I was! It has something to do with setting the perspective again; gluPerspective
Am I right?
*C++*->
yes, indeed you are right.

you need to put this after your glClear(..) call:

glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(angle, fov, near, far);


and then carry on as normal with the rest of the code, starting with your first glMatrixMode(GL_MODELVIEW)
do unto others... and then run like hell.
Thanks for confirming my suspicion.
*C++*->

This topic is closed to new replies.

Advertisement