OpenIL Problem

This is a discussion on OpenIL Problem within the Game Programming forums, part of the General Programming Boards category; I've written the following function to load textures through OpenIL en mass, but when I run it I get a ...

  1. #1
    Supermassive black hole ahluka's Avatar
    Join Date
    Jul 2005
    Location
    South Wales, UK
    Posts
    1,709

    OpenIL Problem

    I've written the following function to load textures through OpenIL en mass, but when I run it I get a runtime error: "Stack around variable texid corrupted".

    Here's the function:

    Code:
    #define TEXTURES_COUNT 2
    
    // texture list - used to index textures array
    #define TEX_STONE       1
    #define TEX_BLUE        2
    
    // names of textures used to load texture files
    char    *textureNames[TEXTURES_COUNT] = { "data\\stone.tga",
                                              "data\\blue.tga"
                                            };
    
    GLuint  uiTextures[TEXTURES_COUNT];  // Holds all game textures
    
    bool LoadTextures ()
    {
            int             i;
            ILuint          texid;
            ILboolean       bLoad;
    
            // Check OpenIL version first
            if (ilGetInteger (IL_VERSION_NUM) < IL_VERSION)
            {
                    MessageBox (0, "Invalid OpenIL Version", "Jemmings", MB_OK | MB_ICONERROR);
                    return false;
            }
    
            ilInit ();
            ilGenImages (TEXTURES_COUNT, &texid);
            
            // Loop through and load all textures using textureNames 
            for (i = 0; i < TEXTURES_COUNT - 1; i++)
            {
                    ilBindImage (texid);
                    bLoad = ilLoadImage (textureNames[i]);
                    if (bLoad)
                    {
                            bLoad = ilConvertImage (IL_RGBA, IL_UNSIGNED_BYTE);
                            if (! bLoad)
                            {
                                    MessageBox (0, "Unable to convert texture[s]", "Jemmings", MB_OK | MB_ICONERROR);
                                    ilDeleteImages (TEXTURES_COUNT + 1, &texid);
                                    return false;
                            }
    
                            glGenTextures (TEXTURES_COUNT, &uiTextures[i]);
                            glBindTexture (GL_TEXTURE_2D, uiTextures[i]);
                            glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                            glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                            glTexImage2D (GL_TEXTURE_2D, 0, ilGetInteger (IL_IMAGE_BPP), ilGetInteger (IL_IMAGE_WIDTH),
                                            ilGetInteger (IL_IMAGE_HEIGHT), 0, ilGetInteger (IL_IMAGE_FORMAT),
                                            GL_UNSIGNED_BYTE, ilGetData ());
                    }
                    else
                    {
                            MessageBox (0, "Unable to load texture", "Jemmings", MB_OK | MB_ICONERROR);
                            ilDeleteImages (TEXTURES_COUNT + 1, &texid);
                            return false;
                    }
            }
    
            ilDeleteImages (TEXTURES_COUNT, &texid);
            return true;
    }
    I'm not sure I've gotten the hang of textures yet - glBindImage etc confuses me - if someone could explain it better (as well as help me with my problem ) I'd be grateful.
    Last edited by ahluka; 12-20-2005 at 01:29 AM.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    Supermassive black hole ahluka's Avatar
    Join Date
    Jul 2005
    Location
    South Wales, UK
    Posts
    1,709
    Yeehaa!
    Suck it to the idiot!
    I didn't declare texid as an array - seems to be working now.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21