Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: loading multiple textures

  1. #11
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,096

    Re: loading multiple textures

    Originally posted by Titus:
    Thatīs exactly my point.

    Iīve number of textures to be used, stored in some variable..

    An in the other hand the compiler asks for a constant


    HELP!!!!!

    ?
    Why are you looking to store the textures twice and take up so much memory? When you can load them into the texture memory?

    Per the NEHE example TextureImage[] is the image stored outside of openGL, so you will still have to copy it into openGL texture storage space and I gave you the correct answer, if it is that you want to load multiple textures into openGL's texture store.



    [This message has been edited by nexusone (edited 08-06-2003).]

  2. #12
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,096

    Re: loading multiple textures

    Multiple texture loading routine I wrote:


    Code :
    void Load_card_images(void)
    {
     
    int i;
     
    char filename[32];
     
    image_t temp_image;
     
    glEnable( GL_TEXTURE_2D );
     
    glPixelStorei( GL_UNPACK_ALIGNMENT,1 );
    glGenTextures( CARD_TEXTURES, deck_store_textures );  // Here I create space for 52 card textures
     
     
    for( i=0; i < CARD_TEXTURES; i++)  // I loop here to load the textures from files
    	{
        glBindTexture( GL_TEXTURE_2D, deck_store_textures[i] );
     
    	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    	strcpy( filename, "images/" ); 
        strncat( filename, CardList[i], 32 - strlen(filename));
    	tgaLoad( filename, &amp;temp_image, TGA_FREE | TGA_LOW_QUALITY );  // could replace this with loadBMP + a few other commands would be needed.  look something like this TextureImage[0]=LoadBMP(filename)
    }
     
     
    }

  3. #13
    Junior Member Newbie
    Join Date
    Aug 2003
    Location
    Beijing , China
    Posts
    17

    Re: loading multiple textures

    Originally posted by JanHH:
    this code seems very weird.. I never would think of something that looks like that if it's about loading textures. what image file format do you want do load?

    I think the question is different from the concept of multi_texture in opengl. The question could be understood as "How to load several textures independently in OpenGL".
    Is what I think correct?

    Sorry about my poor English!
    Help others and then be helped!

  4. #14
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,797

    Re: loading multiple textures

    Originally posted by nexusone:
    Multiple texture loading routine I wrote:


    Code :
     
    // Code cut for space
    glGenTextures( CARD_TEXTURES, deck_store_textures );  // Here I create space for 52 card textures
    I think the line of code I left above is ultimately where Titus is having problems. It's not that line per-se, but how do you allocate memory for the deck_store_textures variable above. Your comment is somewhat misleading in that you say you create space for 52 textures. You don't really. You create 52 texture id's, but you are not creating any space in deck_store_textures. The memory has to be allocated before you call this function.

    You can either create that memory on the stack, whereby you need to have a constant number like so:

    GLuint deck_store_textures[52];

    Or if you're not sure how many textures you need exactly, you need to do it dynamically on the heap.

    int nNumTextures = GetNumberOfTexturesSomehow();
    GLuint deck_store_textures = new GLuint[nNumTextures];


    [This message has been edited by Deiussum (edited 08-07-2003).]

    [This message has been edited by Deiussum (edited 08-07-2003).]
    Deiussum
    Software Engineer and OpenGL enthusiast

  5. #15
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,096

    Re: loading multiple textures

    Yes, you are correct that is only creates the texture id's(names), what is not in my code is the part where I call glTexImage2D, which correct me if I am wrong copy's our image data into the texture memory.

    So the point I was trying to get accross to titus that in the example from NEHE, the variable that he was using is just to store the image file until it is converted into a
    texture data by glTexImage2D and asigned a id from glGenTextures.

    Other then allocating memory to load a image from the file does not openGL manage it once it is loaded into it's texture space?


    [This message has been edited by nexusone (edited 08-07-2003).]

  6. #16
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,797

    Re: loading multiple textures

    Yeah, that's correct. Once you've uploaded the image data with glTexImage2D, you don't need to keep it around. So in the original post, he wouldn't need to keep an array of AUX_RGBImageRecs, but he would still need to keep an array of texture id's.

    In your example, it sounds like you are just keeping an array of texture IDs for a deck of cards, so it will always be 52 textures. In that case a constant is just fine. If it were some game like blackjack where you could have multiple decks, and you wanted to let the user decide how many decks were used, you'd need to use dynamic allocation. I think it's something like this that Titus is getting hung up on. I could be wrong, though.
    Deiussum
    Software Engineer and OpenGL enthusiast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •