creating a minimap?

Started by
6 comments, last by ic0de 11 years, 3 months ago

scrshotty.jpg

So this is my application thus far, programming with c++, sdl and opengl. You can move around the map and all that good stuff, but there is no minimap, which is something I really want to create.

I wanted to know how I would go about creating a texture in opengl (using the data from each tile of the map) to draw a map representing each tile as a pixel, and applying this image to a quad which will occupy the black square.

I need to know all the syntax and have steps explained.

Help is very much appreciated! Hope you guys can help.

Advertisement

There are a number of ways of doing a minimap like this .. there are pros and cons to different approaches and which you choose will depend on things like:

How big is your overall map?

If your overall map isn't too huge you can just create a big texture to hold the whole 'giant mini map', then render a quad for a part of it by varying the tex coords. This would be the simplest approach.

If you've got a huge map, you might either periodically recreate your local 'giant mini map' or use a tiled scrolling approach for the mini-map texture.

How dynamic does the minimap have to be?

If you are showing mainly non-dynamic stuff on the mini map, you can precreate the texture, and reuse each frame. If it's very dynamic, you could say overlay the dynamic elements each frame, or just redraw the whole thing each frame. This depends on the requirements of your game.

If you are using a texture, you'll probably want to use 'render to texture' approaches (google this), there are a number of ways of achieving it. And you may end up modifying your general rendering routines so that they can be also used for drawing the minimap, to save you writing your rendering code twice.

You could also simply create the mini-map texture in software and upload it just like any other texture, if render to texture didn't appeal. You also might save the giant mini-map with the game level as a premade texture, depending on the game.

There are a number of ways of doing a minimap like this .. there are pros and cons to different approaches and which you choose will depend on things like:

How big is your overall map?

If your overall map isn't too huge you can just create a big texture to hold the whole 'giant mini map', then render a quad for a part of it by varying the tex coords. This would be the simplest approach.

If you've got a huge map, you might either periodically recreate your local 'giant mini map' or use a tiled scrolling approach for the mini-map texture.

How dynamic does the minimap have to be?

If you are showing mainly non-dynamic stuff on the mini map, you can precreate the texture, and reuse each frame. If it's very dynamic, you could say overlay the dynamic elements each frame, or just redraw the whole thing each frame. This depends on the requirements of your game.

If you are using a texture, you'll probably want to use 'render to texture' approaches (google this), there are a number of ways of achieving it. And you may end up modifying your general rendering routines so that they can be also used for drawing the minimap, to save you writing your rendering code twice.

You could also simply create the mini-map texture in software and upload it just like any other texture, if render to texture didn't appeal. You also might save the giant mini-map with the game level as a premade texture, depending on the game.

Well to how dynamic, The minimap size (and thus the map size) will be 32x32 pixels up to 256x256 pixels (/tiles), and will change 30 times per second. each pixel will show the color of the dominant player over the corresponding tile, or otherwise light green for grass, light brown for dirt, dark green for trees etc.

If i can bind the texture to a opengl quad, that will fix any screen resizing issues.

I just have no idea how to draw a texture pixel by pixel, and then apply it to a quad. I can do so with existing images, but this image needs to change 30 times per second (my apps frame rate).

Don't cross/double post...

http://www.gamedev.net/topic/637183-how-to-create-minimap-sdlopengl/

Don't cross/double post...

http://www.gamedev.net/topic/637183-how-to-create-minimap-sdlopengl/

Quite so, bad form old chap.

That said, unless the mods are moving across these answers to the old thread:

Drawing lots of individual pixels is not what opengl / direct3d are good at, they are optimized for dealing with bigger primitives, so any way to avoid pixel size operations should be explored.

If most of your tiles are going to be static: grass, dirt, trees .. then consider precreating the static background map. Then only in realtime do you have to worry about the units etc that might move about.

Then you can render your static minimap, then overlay afterwards your dynamic units. You could for instance, simply draw a quad for each unit, or, if you really wanted to be pixel based with LOTS of units you could I suppose blank a secondary texture each frame, then draw a pixel for each unit (with alpha), then draw this over the static mini map with alpha blending.

Don't cross/double post...

http://www.gamedev.net/topic/637183-how-to-create-minimap-sdlopengl/

Sorry, i thought it would be better to post this in a different section, because the last section hasn't gotten any results. Is it really such a hard thing to do?

Drawing lots of individual pixels is not what opengl / direct3d are good at, they are optimized for dealing with bigger primitives, so any way to avoid pixel size operations should be explored.

I think he really meant modifying the texels (pixels of the texture). That one is easy, just overwrite the texture contents before drawing. Considering this is just being done once per frame, the impact shouldn't be really huge, he could even take a lazy approach to it if needed.

Look up glTexImage2D, that's the function you need.

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
Well to how dynamic, The minimap size (and thus the map size) will be 32x32 pixels up to 256x256 pixels (/tiles), and will change 30 times per second. each pixel will show the color of the dominant player over the corresponding tile, or otherwise light green for grass, light brown for dirt, dark green for trees etc.

I noticed you're using SDL. Since the minimap is only 256x256 and you probably have some kind of data structure representing the state of each tile. I would assign a color to each type/state of the tile (you seem to already have) and go through each tile on your map and have SDL plot those pixels to an SDL_Surface sized 256x256 and then turn the SDL_Surface to a GL texture using glTexImage2D(). Or alternatively you could use shaders.

This topic is closed to new replies.

Advertisement