Sign in to follow this  
ChemicalImbalance

gluPerspective and glOrtho at the same time

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this