Joshua Sosnowski
Joshua Sosnowski

Reputation: 11

Drawing a minimap (game)

I'm making a rts game, and have created a 2d array containing the map tiles. I'd like to transfer this to an image (an unsigned int or a sdl surface?) and I would likely draw this onto a gl Quad. I'd likely just use 2 for loops to draw the entire map each frame. The problem is, I don't know the syntax of how to do this.

I'd like the map size to be flexible (probably always a square), and therefore the minimap has to also be flexible.

If I can find out the syntax of how to create an image from scratch (or understand how an unsigned int can be interpreted as an image?) and draw each pixel, this would completely resolve my issue.

Upvotes: 1

Views: 1834

Answers (1)

user1944441
user1944441

Reputation:

You can first create a SDL_Surface using SDL_CreateRGBSurface( link has a tutorial ) with the desired height and width of the map.

SDL_Surface *map = SDL_CreateRGBSurface(Uint32 flags, int width, int height, int bitsPerPixel, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);

After you have the surface you can access the pixels of the surface with

map->pixels    //pointer to the start of pixel data for map

When you want to resize the map, you create a new SDL_Surface with the new size and transform pixels using image scaling algorithms to it then delete the old surface and use the new one as the map

Upvotes: 1

Related Questions