Jump to content
  • Advertisement
Sign in to follow this  
baconfish

Unity Mirroring an SDL surface?

This topic is 4076 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

This is some code I wrote years ago to load an image in SDL, mirror it on the x-axis, and make an OpenGL texture. Somehow it works fine except on images smaller than 256x256 or something.
GLuint loadTexture(string filename)
{
	SDL_Surface *imagesurface = IMG_Load(filename.c_str());
	GLubyte *pixels = (GLubyte *)imagesurface->pixels;
	GLuint texID;

	int width = imagesurface->w;
	int height = imagesurface->h;
	int bytesPerRow = imagesurface->format->BitsPerPixel / 8 * width;

	for (int y = 0; y < height / 2; y++)
	{
		for (int x = 0; x < bytesPerRow; x++)
		{
			int a = y * bytesPerRow + x;
			int b = (height - y) * bytesPerRow + x;

			GLubyte temp = pixels[a];
			pixels[a] = pixels;
			pixels = temp;
		}
	}

	glGenTextures(1, &texID);
	glBindTexture(GL_TEXTURE_2D, texID);
	if (imagesurface->format->BitsPerPixel == 24)
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
	else
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	

	SDL_FreeSurface(imagesurface);

	return texID;
}
EDIT: I are gud at internet code tags Can anyone see a problem I'm missing? I've had problems with this before, and some hero in the IRC channel showed me this library of helpful SDL functions he made. Unfortunately I can't remember who this helpful stranger (actually, I'm pretty sure he's a regular helpful awesome member of the community, I just can't remember him) is or what I did with the library, so I'm stuck with my own junk for now.

Share this post


Link to post
Share on other sites
Advertisement
If you're pasting this on a 3D surface, can't you just * -1 (invert) the texture coords?

[Edited by - AfroFire on May 19, 2007 5:54:15 AM]

Share this post


Link to post
Share on other sites
I could do that, but I'd rather not have to if I can avoid it.

EDIT: Just realised I can mirror surfaces with SDL_gfx. Still, I'd like to know where I went wrong with trying to flip it manually.

[Edited by - Stukkm on May 19, 2007 8:23:33 AM]

Share this post


Link to post
Share on other sites
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!