How to display a Minimap correctly?

Started by
10 comments, last by SnAkE 21 years, 10 months ago
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
Advertisement
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.

Kippesoep
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
i shink u should use the stencil buffer for the circle. it is made for such problems.
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.

Kippesoep
Why not try to use a quad or even try masking or some thing like that.
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.
Use the stencil buffer..............
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]
yeah, thanks for your repiles...
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

This topic is closed to new replies.

Advertisement