Jump to content
  • Advertisement
Sign in to follow this  
ChemicalImbalance

gluPerspective and glOrtho at the same time

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

Hi. I'm trying to render a scene using both gluPerspective (for 3D elements) and glOrtho (for UI elements). I've noticed that I use glOrtho first, it seems to render just fine, but if I use gluPerspective first, the UI elements end up skewed. I want to use some transparency with the UI, so I need to render the 3D elements first. Am I doing something wrong here?
	SwapBuffers(m_hDC);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f,(GLfloat)WindowWidth/(GLfloat)WindowHeight,0.1f,100.0f);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

    glTranslatef(0, 0, -1);

	ScaleAllDimensions(0.1f);
	glRotatef(-60, 1, 0, 0);
	glEnable(GL_TEXTURE_2D);
	m_EgoShip.Draw();
	glDisable(GL_TEXTURE_2D);
	m_StarField.Draw();

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-WindowWidth/2, WindowWidth/2, -WindowHeight/2.0f, WindowHeight/2.0f, 0, 10);
	glMatrixMode(GL_MODELVIEW);

	glDisable(GL_TEXTURE_2D);
	glColor3f(1, 1, 1);

	glPushMatrix();
		glTranslatef(100, 100, 0);
		glColor3f(1, 0, 0);
		DrawRoundedRect(GL_POLYGON, 200, 80, 10);
		glColor3f(1, 1, 1);
		DrawRoundedRect(GL_LINE_LOOP, 200, 80, 10);
	glPopMatrix();


Share this post


Link to post
Share on other sites
Advertisement
Try adding a glLoadIdentity() here:
glPushMatrix();
glLoadIdentity();
glTranslatef(100, 100, 0);
glColor3f(1, 0, 0);
DrawRoundedRect(GL_POLYGON, 200, 80, 10);
glColor3f(1, 1, 1);
DrawRoundedRect(GL_LINE_LOOP, 200, 80, 10);
glPopMatrix();

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!