View Full Version : multiple textures from one file
06-19-2005, 07:06 AM
Hello I'm just looking to load multiple textures from a single bitmap file. I use the glTexSubImage2D to try and specify what part of the texture I want loaded but I must be doing something wrong.
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImg->w, TextureImg->h, 0,
GL_BGR_EXT, GL_UNSIGNED_BYTE, TextureImg->pixels);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
TextureImg->w / 2, TextureImg->h, GL_BGR_EXT,
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); Here is what I get:
This is not multitexturing, and I don't think you want multitexturing neither. what you are making is sub textures so the main texture always appear and the sub one too. This is intended to change rectangular portions of a texture.
I can't say more until you precise more what are your intentions.
06-19-2005, 08:39 AM
Basiclly I'm trying to make a 2D game and instead of loading hundreads of bitmap files which are sprites I can put multiple sprites in one bitmap file.
For example, take a look at this http://www.panelmonkey.org/sprite.php?id=397&theme=1
It's one big PNG file full of different sprites. Instead of loading the whole file I just load the sprite I need by using the cordinates of the image.
First, you need to create that texture. To do so, you'll need to load all the textures, calculate the size of the big texture that will own them all, calculate sizes and positions of each of all the little textures you'll put into the big one.
Now, you'll be able to do TexSubImage2D in order to place the little images into the big texture.
After that, you'll have your big texture filled with many little texture. Store that into a file (ie bmp) along with all the needed info (locality and sizes of each of the little images). With that, you'll be able to load the image and know the sub image as you wish.
Finally, for using that big image. You'll have to create few little image and use CopyTexSubImage2D in order to fill them quickly. Ensure the sizes of all the textures are the same (I guess).
I've never done that thought. It's only from my logic and what I know from gl. But I'm sure it's the good logic but some things I surely don't know (there might have more optimisation and such).
So to resume: one big texture and few little texture (created by TexImage2D). Load the big file, then copy sub portions of it inside your little textures. That's it !
Hope that helps.
06-24-2005, 07:30 AM
Why do you want to split this texture up anyway? You can load several sprites at once when they are in one bitmap and then set texture coordinates appropriately. For example if the sprites are in a 10x10 grid individual sprites can be accessed with texture coordinates 0.1 apart (eg. the quad spanning between 0.0/0.0 - 0.1/0.1).
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.