Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Splitting BMPs

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

Hey, I''m using openGL for a 2d tile engine, and I was wondering if there is any way to load a bmp image, and then split it into multiple individual textures. The GLaux library seems to only let me save the entire bmp to a single texture. - Bong

Share this post

Link to post
Share on other sites
Hey I had to do this once too I did a small tile engine and such but now I''m trying to experiment on BSP''s and see how that works for settings like castles in rpgs and caves and such but I might go back and work on my tile engine again since I liked it heres my modification off Nehe''s .tga loader basically its the same thing though
TextureImage::Extract(int x, int y, int ex_width, int ex_height)
unsigned char *src = NULL,*dest = NULL, *dest2;
unsigned int type = GL_RGBA;
int bytes_per_pixel = bpp/8;
unsigned int id;

dest = new unsigned char[ex_width * ex_height * bytes_per_pixel];

x = x * (ex_width);
y = y * (ex_height);

src = buffer + (y * (width * bytes_per_pixel) + (x * bytes_per_pixel));

dest2 = dest;

for(int index = 0; index < ex_height; index++)
memcpy(dest2, src, (ex_width * bytes_per_pixel));

dest2 += (ex_width * bytes_per_pixel);
src += (width * bytes_per_pixel);
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);

if(bpp == 24)
type = GL_RGB;

gluBuild2DMipmaps(GL_TEXTURE_2D, type, ex_width, ex_height, type, GL_UNSIGNED_BYTE,dest);

src = NULL;

you can mess around with that as long as you have the buffer saved that you read in it works so like in your class keep like a unsigned char *buffer; where all the image data is kept only thing that is weird on this that I havent figured out really why it is is that lets say you have a 2 rows of cells and 3 colums
1 2 3
4 5 6
the cell 4 is located at 0,0 so you would call the function like
Extract(0,0,32,32) //if the tiles are 32x32 and that will give you the image of cell 4 if you want cell 1 you call Extract(0,1,32,32) yeah its weird like taht but I havent figured out why it does it...if anyone knows please tell

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!