Jump to content
  • Advertisement
Sign in to follow this  
Jossos

SDL_Surface help -- Drawing a minimap

This topic is 1928 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
{
private:
	float xPos, yPos, width, height;
	smMAP* mapRef;
	SDL_Surface *map_img;

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

	void Draw(int x, int y, int w = 200, int h = 200);
};
smMINIMAP::smMINIMAP(smMAP& map)
{
	*mapRef = map;

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

smMINIMAP::~smMINIMAP()
{
	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);
		}
	}

	glEnable(GL_TEXTURE_2D);

	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);

	glBegin(GL_QUADS);
		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);
	glEnd();
}

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

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!