Results 1 to 5 of 5

Thread: multiple textures from one file

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2005
    Posts
    4

    multiple textures from one file

    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.

    Code :
    glGenTextures(1, &texture[0]);
     
           glBindTexture(GL_TEXTURE_2D, texture[0]);
     
           glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImg[0]->w, TextureImg[0]->h, 0,
                        GL_BGR_EXT, GL_UNSIGNED_BYTE, TextureImg[0]->pixels); 
     
     
           glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 
                           TextureImg[0]->w / 2, TextureImg[0]->h, GL_BGR_EXT, 
                           GL_UNSIGNED_BYTE, TextureImg[0]->pixels); 
     
           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:

    http://img300.echo.cx/my.php?image=glimage4os.png

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: multiple textures from one file

    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.

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2005
    Posts
    4

    Re: multiple textures from one file

    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.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: multiple textures from one file

    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.

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2005
    Location
    Bremen, Germany
    Posts
    4

    Re: multiple textures from one file

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

Similar Threads

  1. Replies: 9
    Last Post: 11-02-2018, 08:16 AM
  2. Loading model with multiple objects from .obj file
    By InquisitorAles in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-06-2017, 04:35 AM
  3. multiple animations in one file?
    By ehmdjii in forum COLLADA
    Replies: 3
    Last Post: 06-06-2014, 10:46 AM
  4. Multiple Viewports, Multiple Textures - 3D
    By Cyndy in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 04-08-2010, 04:47 PM
  5. multiple lights and multiple textures
    By jide in forum OpenGL: GLSL
    Replies: 4
    Last Post: 10-26-2005, 06:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean