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 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: loading multiple textures

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2003
    Location
    Chile
    Posts
    10

    loading multiple textures

    Hi Me again

    Quick and Painless:

    I know lots of you are familiar with this:

    int LoadGLTextures()
    {
    int Status=FALSE;

    AUX_RGBImageRec *TextureImage[1];

    memset(TextureImage,0,sizeof(void *)*1);

    This is ok if you want to load 1 texture, but what if I want to load more? To be more precise, what if the number of textures i want to load is stored in some int variable?
    int textures=5;
    AUX_RGBImageRec *TextureImage[textures];
    That doesn´t work....

    Any ideas?
    Thanks
    ?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    680

    Re: loading multiple textures

    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?

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jun 2003
    Posts
    181

    Re: loading multiple textures

    You'll need to use dynamic memory allocation. Read up on it in your favorite C or C++ book.

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2003
    Location
    Chile
    Posts
    10

    Re: loading multiple textures

    The "weird" code belongs to Nehe´s tutorials (#6)

    I´ve searched for dinamyc or variable arrays and all I get is this:

    TextureImage[];
    .....
    ....
    TextureImage[3];

    But that doesn´t work. Maybe for the AUX_RGB preceding it. The compiler´s error reads like: "expecting a constant"
    Hope someone knows what I´m talking about
    Thanks
    ?

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

    Re: loading multiple textures

    First we don't know every tutor out there by heart, while nehe is a good resourse the first lessons are examples, just to show how to do something. But those first examples are limited in that maybe not the correct way to do something beyond what it demostrates.

    I think the problem is that example is setup to load one texture and there is more to it then increasing the size of the texture array.

    Maybe this will help:

    TextureImage[0]; // is for storing the BMP file before it is loading into openGL's texture memory space, so this is really a temp storage and you could use this same variable over and over.

    GLuint texture[1]; // This is the real place the texture is going to be stored, currently has space for one texture.


    glGenTextures(1, &texture[0]); // Here is where we create our texture space.

    glBindTexture(GL_TEXTURE_2D, texture[0]); // What type of texture we are creating.

    glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data); // Copy our image into the texture space.


    To load multiple textures you would:

    LoadBMP into TextureImage[0]

    Create a texture space and copy the TextureImage into texture[?].

    Clear the TextureImage, per example in NEHE's code and load the next BMP file.

    Keep repeating until all of the files needed have been loaded.

    Note later NEHE goes go into loading multiple images, I forget which lesson.

    I have code for loading multiple images for a file list, but I do not use the glaux library since it is for the windows only platform.



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

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

    Re: loading multiple textures

    If you are going to allocate memory for an array on the function stack, which is what you are doing when you do something like int array[10], then the size of the array HAS to be a constant. If that number can be changed at runtime you need to use dynamic memory allocation to allocate the array on the heap.

    Example:

    int size = GetSize();
    int *pArray = new int[size];

    // use pArray

    // when done with the array do this:
    delete [] pArray;
    Deiussum
    Software Engineer and OpenGL enthusiast

  7. #7
    Intern Contributor
    Join Date
    Jul 2003
    Location
    va beach
    Posts
    64

    Re: loading multiple textures

    BYTE Texture[]={TEXTURE1,TEXTURE2,ECT, ECT};

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

    Re: loading multiple textures

    Originally posted by c0d3Junk3Y:
    BYTE Texture[]={TEXTURE1,TEXTURE2,ECT, ECT};

    That's still an array with a static size. You can't dynamically specify the number of elements in the brackets at runtime with the above code.
    Deiussum
    Software Engineer and OpenGL enthusiast

  9. #9
    Junior Member Newbie
    Join Date
    Jul 2003
    Location
    Chile
    Posts
    10

    Re: loading multiple textures

    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!!!!!

    ?

  10. #10
    Junior Member Regular Contributor
    Join Date
    Jun 2003
    Posts
    181

    Re: loading multiple textures

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

    An in the other hand the compiler asks for a constant
    The answer was already posted, twice, by Deiussum and myself. No need to get alarmed; dynamic memory allocation and pointers are not an easy thing to grasp at first, and take a little while to master.

Posting Permissions

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