Jump to content

  • Log In with Google      Sign In   
  • Create Account


Splitting BMPs


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Bong   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 August 2001 - 08:44 AM

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

Sponsor:

#2 Galileo430   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 August 2001 - 01:48 PM

If you write your own custom loading function then it''s relativly simple.

It''s like linar memory access.

#3 Derilect101   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 August 2001 - 03:34 PM

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];
memset(dest,0,sizeof(dest));

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;

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, type, ex_width, ex_height, type, GL_UNSIGNED_BYTE,dest);

free(dest);
dest2=NULL;
src = NULL;
return(id);
}


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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS