• Advertisement
Sign in to follow this  

SDL_Surface help -- Drawing a minimap

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I want to draw a minimap for my app pixel-by-pixel, but I have no idea how, and google has yielded no results (mainly stuff loading already existing images - I already know how to do)


I'll place my minimap Class for you to peruse and I hope someone can help me. It's the syntax I don't know about. (there's a bit of opengl in here too, but it's mostly an sdl question).

class smMINIMAP
	float xPos, yPos, width, height;
	smMAP* mapRef;
	SDL_Surface *map_img;

	void PutPixel(int x, int y, int color);
	smMINIMAP(smMAP& map);

	void Draw(int x, int y, int w = 200, int h = 200);
	*mapRef = map;

	map_img = SDL_CreateRGBSurface(0, mapRef->getWidth(), mapRef->getLength(), 32, 0, 0, 0, 0);

	delete mapRef;

void smMINIMAP::Draw(int x, int y, int w, int h)
	Uint32* pixels = (Uint32*)map_img->pixels;

	for (int w = 0; w < mapRef->getWidth(); w++)
		for (int l = 0; l < mapRef->getLength(); l++)
			PutPixel(w, l, 0xff0000);


	GLuint ret;

	glGenTextures(1, &ret);
	glBindTexture(GL_TEXTURE_2D, ret);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, map_img->w, map_img->h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, map_img->pixels);

		glTexCoord2f(0, 0); glVertex2f(x,     y);
		glTexCoord2f(1, 0); glVertex2f(x + w, y);
		glTexCoord2f(1, 1); glVertex2f(x + w, y + h);
		glTexCoord2f(0, 1); glVertex2f(x,     y + h);

void smMINIMAP::PutPixel(int x, int y, int color)
	unsigned int* ptr = (unsigned int*)map_img->pixels;
	int lineoffset = y * (map_img->pitch / 4);
	ptr[lineoffset + x] = color;



smMAP is just a 2d array of tiles. It's irrelevant right now, as I just want to make each pixel red to get something on the screen - then I can colorize it.


Help is greatly appreciated!

Edited by Jossos

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement