#### Archived

This topic is now archived and is closed to further replies.

# How to display a Minimap correctly?

This topic is 5951 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, i''ve written a small engine, that creates a minimap of the level actually played on the fly. Now I want to diplay this texture and now do not know how to show it up the way i want it to be. Here is a screeny of what it looks like: As you see, the minimap is bigger than the are it should show up within. Now my question: How do I clip the minimap-texture to the circle of the minimap-background??? (The method I am using now (adapting the size of the whole minimap-texture to the circle) is not that great. I only want to show the parts of the world that surrond you. SnAkE''s Programming Resources

##### Share on other sites
I draw a similar kind of map and the easiest thing for me was to draw a solid circle (made from a triangle fan) and update the texture coordinates for the vertices. Then, all you have to make sure is that you have a texture containing the map.

##### Share on other sites
Sounds interesting...
but that uses many polygons, eh?! (in the circle)
and you have to change/rotate the texture-coordinates and clip it youself?

My problem is that i think i will not get the clipping-thing working (decide what the texture-coordinates are on the circle).

Could it be done with masking the texture?! (just an idea)
I tried it a few month ago, but it did not work i think.

SnAkE''s Programming Resources

##### Share on other sites
i shink u should use the stencil buffer for the circle. it is made for such problems.

##### Share on other sites
quote:
Original post by SnAkE
Sounds interesting...
but that uses many polygons, eh?! (in the circle)
and you have to change/rotate the texture-coordinates and clip it youself?

My problem is that i think i will not get the clipping-thing working (decide what the texture-coordinates are on the circle).

Could it be done with masking the texture?! (just an idea)
I tried it a few month ago, but it did not work i think.

The number of triangles doesn''t need to be that high. And even if there''s a lot of them, they cover a small area of the screen and should be insignificant when compared to the rest of your scene.

There''s no need to do any clipping, because you''re not drawing anything outside the circle. You know the texture coordinates of the center (they''re the player''s location converted to texcoords). When you create the circle, you use sine and cosine to determine the screen coordinates. The same way, you get points along the unit circle. Simply scale those by a factor (this defines the "zoom" level of your minimap) and add them to the center''s texcoords.

##### Share on other sites
Why not try to use a quad or even try masking or some thing like that.

##### Share on other sites
there is also the multitexturing magic with a modulated secondary texture. this will even allow effects like the map fading at the edge of the circle. though you could use just the alpha channel of the secondary texture. play with settings for the look you want. as a bouns this can even allow you to draw the green circle and the mini map with a single quad.

##### Share on other sites
Use the stencil buffer..............

##### Share on other sites
Lucky for you, I managed to scrounge up an example on how you can use the stencil buffer to do this (since you seem completely oblivious).

    glEnable(GL_STENCIL_TEST);// draw circle to the stencil buffer.glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // replace pixel in stencil bufferglStencilFunc(GL_ALWAYS, 1, 0xffffffff); //always draw, replace stencil buffer pixel with 1drawCircle();// render minimapglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);glStencilFunc(GL_EQUAL, 1, 0xffffffff);  // draw if stencil == 1 drawMinimap();glDisable(GL_STENCIL_TEST);

and clear stencil buffer each frame.

EDIT: If you use this, make sure to set in your pixelformat depth buffer bits = 31, stencil bits = 1, or some thing like that, depending on your settings.

[edited by - neosmyle on June 5, 2002 1:03:28 AM]

##### Share on other sites
i will try to do it with the stencil buffer... thanx for your sample-code Neosmyle i found some other infos on stecils, yet, so it should be no problem to make use of them!

SnAkE''s Programming Resources

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632591
• Total Posts
3007250

×

## Important Information

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!