ortho projection and UI's

Started by
-1 comments, last by okonomiyaki 20 years ago
So I have two functions, one resizes the screen for 3d graphics and one resizes the screen for the ortho projection for the user infterface.


GLvoid BaseApp::ResizeScreen()
{
	if(GameInfo::screenHeight==0) GameInfo::screenHeight = 1;

	glViewport(0,0,GameInfo::screenWidth,GameInfo::screenHeight);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	// Calculate The Aspect Ratio Of The Window

	gluPerspective(45.0f,(GLfloat)GameInfo::screenWidth/(GLfloat)GameInfo::screenHeight,0.5f,2000.0f);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}



GLvoid BaseApp::ResizeOrthoScreen()
{
	if(GameInfo::screenHeight==0) GameInfo::screenHeight = 1;

	glViewport(0,0,GameInfo::screenWidth,GameInfo::screenHeight);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	glOrtho(0.0f,GameInfo::screenWidth,GameInfo::screenHeight,0.0f,-1.0f,1.0f);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

Yay. I want to render my 3d map and then render a 2d UI on top of it. In one level of my scenegraph, I have 5 objects, linked together like so:

Map  ->   Hexagon1   ->   Hexagon2  ->   Hexagon3   ->   UI
 
So Hexagon1 is a sibling of Map, etc. When rendering, it starts at Map and goes through all of its siblings. Obviously it will end after UI, flip the buffer, and start over again. Map initially calls ResizeScreen. Then it renders the map. Now the scene graph says to render Hexagon1. The screen should already be projected into 3d space, right? Render it. Render Hexagon 2 and 3 as well. Now, when UI renders, it calls RenderOrthoScreen(). Then it renders the UI. When it starts over, map should call RenderScreen again and project it back into 3d space, right? Well, I can see the map fine, and I can see the UI fine, but for some reason I can''t see Hexagon1, 2, or 3. When I comment out the ResizeOrthoScreen call in UI, I can see everything except for UI (of course). One last thing is that Map translates the camera to where it is in space. Then draws the map. Then hexagon pushes a matrix, and translates the hexagon. Then is pops a matrix. Hexagon2 and 3 do this as well. Then UI calles ResizeOrthoScreen() and translates the UI around... Any obvious problems?? I can''t figure this out. Thanks!

This topic is closed to new replies.

Advertisement