Sign in to follow this  
SnowMoo

Minimap

Recommended Posts

hi, I wanted to create a minimap for my game.. however i am having problems with the code.. it either gives me the minimap only or the main game screen.. I just want a mini map at the bottom right hand corner but it doesn't comes out.. thanks to anyone who can help me solve my problem.
for(int i = 0; i < 2; i++)
		{
			if( i == 0)
			{
				int viewport[4];
				glGetIntegerv(GL_VIEWPORT,(int*)viewport);
				// Set The Viewport To The Bottom Right.  It Will Take Up Half The Screen Width And Height
				glViewport (w/2, 0, w/2, h/2);
				glMatrixMode (GL_PROJECTION);						// Select The Projection Matrix
				glLoadIdentity ();							// Reset The Projection Matrix
				// Set Up Perspective Mode To Fit 1/4 The Screen (Size Of A Viewport)
				gluPerspective( 45.0, (GLfloat)(w)/(GLfloat)(h), 0.1f, 500.0 ); 

				gluLookAt( 0.0, 8.5, 0.8, 0.0, 0.1, 0.0, 0.0, 1.0, 0.0 );
				ground->Render();

				renderGame();				
				// restore the original projection and viewport…
				glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
			}
			else
			{
				int viewport[4];
				glGetIntegerv(GL_VIEWPORT,(int*)viewport);

				glViewport ( 0, 0, w, h );
				glMatrixMode ( GL_PROJECTION );
				glLoadIdentity();
				gluPerspective( 45, (float)(w)/(float)(h), 0.1, 1000 );
				glMatrixMode ( GL_MODELVIEW );
				glLoadIdentity ();

				camera->LookAt();
				ground->Render();

				renderGame();				

				// restore the original projection and viewport…
				glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);

			}
		}

		UpdateUI();
		glFlush ();
		glDisable( GL_DEPTH_TEST );


Share this post


Link to post
Share on other sites
First, the loop isn't needed. It just executes the upper code snippet on the first run and the lower code snippet on the second run. You can do this by just listing them one after another.

While you do that, you can also get rid of some duplicate code.

Actually, why are you drawing everything twice?

Share this post


Link to post
Share on other sites
err.. ok.. i remove the loop.. o right.. wat you mean by listing them after one another? Because now i am trying to draw the main game scene but with a minimap which is the top-down view of the game scene and now with my code it doesn't come out.. i now only either one of the view only in my game screen.. Could you explain abit more on how to make it works? Thanks..

Share this post


Link to post
Share on other sites
Right now your code is basically the same as this:


// First run of the loop
int viewport[4];
glGetIntegerv(GL_VIEWPORT,(int*)viewport);
glViewport (w/2, 0, w/2, h/2);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective( 45.0, (GLfloat)(w)/(GLfloat)(h), 0.1f, 500.0 );

gluLookAt( 0.0, 8.5, 0.8, 0.0, 0.1, 0.0, 0.0, 1.0, 0.0 );
ground->Render();

renderGame();

glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);

// Second run of the loop
glGetIntegerv(GL_VIEWPORT,(int*)viewport);

glViewport ( 0, 0, w, h );
glMatrixMode ( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45, (float)(w)/(float)(h), 0.1, 1000 );
glMatrixMode ( GL_MODELVIEW );
glLoadIdentity ();

camera->LookAt();
ground->Render();

renderGame();

glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);

// Outside the loop
UpdateUI();
glFlush ();
glDisable( GL_DEPTH_TEST );



This is what I meant by "one after the other". Also, I think you should draw the map after drawing the main game screen (currently it's the other way around), but I'm not sure if that will make a difference.

Now, what do you mean when you say you are seeing either the game screen or the minimap? Do you mean the displays switch as the game is running? Or that on some runs of the game you are only seeing the minimap, and on others only the main game screen? Something else?

BTW, in the first call to gluPerspective(), you should pass w/2 and h/2, not w and h. Also, you should pass 1.0 as the near clip plane - specifying a very small value for it can cause some artifacts.

Share this post


Link to post
Share on other sites
When i remove the part where i draw the game screen, i will see the mini-map. When i put both codes in I will see the game screen only.. That is what i mean I am seeing either the game screen or the minimap.
I wrote the codes in the way u taught me.. it didn't work too.. I think this is because of the viewport being covered by the bigger viewport... However, i do not know how to fix it..


[Edited by - SnowMoo on July 6, 2008 7:34:23 AM]

Share this post


Link to post
Share on other sites
Did you do what Gage64 said in his last post?

Quote:

Also, I think you should draw the map after drawing the main game screen (currently it's the other way around)


I assume the minimap camera is farther away from the scene that the in-game camera. So the main screen would be drawn over the minimap.

BTW, why are you rendering the whole scene to the minimap? Assuming that the scene is quite large you wouldn't see every detail so maybe you could go with a simpler representation for better efficiency.

Edit:If you want to draw the minimap first - in order to reduce overdraw - you could render it to a texture and then draw a textured quad with depth 0 on screen.

Share this post


Link to post
Share on other sites
yup i did wat Gage64 said in the post by drawing the map after the main game screen..

Lord Evil, sorry to ask cos I am quite new to OpenGL... how to render the minimap to a texture? Did u mean I draw a picture of a layout of the game and I map that picture onto a quad and draw some symbols on top of the quad to represent my player?? or u meant something else?? Please clarify abit. Thanks =)

Share this post


Link to post
Share on other sites
For rendering to a texture there are Framebuffer Objects (FBO) or Pixelbuffer Objects (PBO,). They basically are textures you can redirect the rendering to, i.e. instead of the backbuffer you render to that texture.

You would draw the minimap as if it were the screen and then draw a quad with that rendered texture to the real screen.

You could also just render the minimap to a viewport and disable depth testing and depth writes (provided that your map/terrain doesn't have overhangs). You would then first render the map/terrain and then some geometric objects like triangles or quads that represent important objects on the map.
You shouldn't draw everything in full detail to the minimap since then the player might not be able to notice important objects and the map itself might be too crowded.

The above approach would also apply to rendering to a texture first. With this you then could use depth testing. Just make the texture the current rendering target, set projection and camera matrices accordingly, render the minimap normally and then switch back to the backbuffer as the rendertarget and render the textured quad to it.

Rendering to a texture would help with using a depth buffer or lazy updates of the texture (update only when the minimap has changed, i.e. some object has move significantly).

Share this post


Link to post
Share on other sites
A) You dont seem to disable the depth test when drawing the minimap.

B) You draw the minimap at the top quadrant, then you set the viewport as the WHOLE screen and you render the game. The main view draws over your minimap. Do them the other way and it should render fine.


Also, what Lord Evil said.

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