Jump to content
  • Advertisement
Sign in to follow this  
jon723

Orthographic projection not working when trying to render background

This topic is 4331 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

I'm tryin to render my scene in such a way that I render the background to the entire screen in 2d then switch to 3d for the other objects. When I try to switch to an orthographic projection to render the background nothing is rendered but the 3d objects are rendered. Can someone point out whats wrong or tell me the correct steps to accomplish what I'm looking for.
{
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(0.0, 0.0, -10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

	glDisable(GL_LIGHTING);	

	/*************************************
	Draw the background
	**************************************/
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	gluOrtho2D(0,640,0,480);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
	
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, testpic);
	glTranslatef(0.0,0.0,0.0);
	glBegin(GL_TRIANGLE_FAN);
	glColor4f(1.0,1.0,1.0,1.0);
	glTexCoord2f(0.0, 0.0);	glVertex2i(-1,1);
	glTexCoord2f(1.0, 0.0);	glVertex2i(-1,-1);
	glTexCoord2f(1.0, 1.0);	glVertex2i(1,-1);
	glTexCoord2f(0.0, 1.0); glVertex2i(1,1);
	glEnd();
	glDisable(GL_TEXTURE_2D);

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);	
	glPopMatrix();

	glEnable(GL_POLYGON_OFFSET_FILL);
	glPolygonOffset(1.0,0.001);

	glEnable(GL_FOG);
	glClearColor(fogcolor[0],fogcolor[1],fogcolor[2],fogcolor[3]);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glPushMatrix();
	glRotatef(-angle[1], 1.0, 1.0, 0.0);
	ptl1->Draw(t);
	glPopMatrix();	

	glPushMatrix();
	glRotatef(-angle[0], 1.0, 1.0, 0.0);
	ptl2->Draw(t);
	glPopMatrix();

	glPushMatrix();
	glRotatef(-angle[0], 1.0, 1.0, 0.0);
	ptl3->Draw(t);
	glPopMatrix();
	
	glDisable(GL_BLEND);
	glDisable(GL_POLYGON_OFFSET_FILL);
	glDisable(GL_FOG);
	

	angle[0] += tFTime;
	angle[1] += 1.5 * tFTime;
        angle[2] += 1.4 * tFTime;	

	if(angle[0] > 360.0)
		angle[0] = 1.0;
	if(angle[1] > 360.0)
		angle[1] = 1.0;	
	if(angle[3] > 360.0)
		angle[3] = 1.0;	
	
	return 1;
}

Share this post


Link to post
Share on other sites
Advertisement
You set the coordinate system to range from (0, 0) to (640, 480), and draw the background from (-1, 1) to (1, 1). Take a look in the lower left corner and you should see one pixel being drawn in the corner. That's your background. Assuming it got a visible color that is.

Share this post


Link to post
Share on other sites
Woah duh!!!!! Thanks for pointing that out. I fixed my calls to glVertex and that solved everything, thank you!!!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!