Thread: OpenIL Texture problem

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    OpenIL Texture problem

    Sorry to post about OpenIL textures again (this isn't a cross post, it's about something different than before).

    I've got this class, Entity, which acts as a base class in my game. Here's the class:

    Code:
    class Entity
    {
    public:
            Entity (void);
            ~Entity (void);
    
            virtual bool    LoadTexture (char *filename) = 0;
    
    protected:
            GLuint  Texture[1];
    
    private:
            RECT    BoundingBox;
            int     Width;
            int     Height;
    };
    Now ignore the private members for now - i'm having problems in the protected area. I derive the player class from this class, over-riding the LoadTexture method and inheriting Texture:

    Code:
    class Player : public Entity
    {
    public:
            Player (void);
            Player (unsigned int health);
            ~Player (void);
    
            bool            IsDead ();
            unsigned int    GetHealth ();
            void            SetHealth (unsigned int h);
            void            Render (GLfloat fMoveX, GLfloat fMoveY);
            // overridden
            bool            LoadTexture (char *filename);
    private:
            unsigned int    Health;
    
    };
    Again, ignore the private members - the problem here is with LoadTexture OR Render (I can't narrow it down). I'm pretty certain it's something to do with LoadTexture, although it runs fine. Here it is:

    Code:
    bool Player::LoadTexture (char *filename)
    {
            GLboolean       bSuccess;
            ILuint          uiTex;
    
            if (ilGetInteger (IL_VERSION_NUM) < IL_VERSION)
            {
                    MessageBox (0, "Inavlid OpenIL Version", "Player::LoadTexture", 
                                    MB_OK | MB_ICONERROR);
                    return false;
            }
    
            ilInit ();
            ilGenImages (1, &uiTex);
            ilBindImage (uiTex);
            bSuccess = ilLoadImage (filename);
            if (! bSuccess)
            {
                    MessageBox (0, "Unable to load texture", "Player::LoadTexture", 
                                    MB_OK | MB_ICONERROR);
                    return false;
            }
    
            bSuccess = ilConvertImage (IL_RGB, IL_UNSIGNED_BYTE);
            if (! bSuccess)
            {
                    MessageBox (0, "Unable to convert texture", "Player::LoadTexture",
                                    MB_OK | MB_ICONERROR);
                    return false;
            }
    
            glGenTextures (1, &Texture[0]);
            glBindTexture (GL_TEXTURE_2D, Texture[0]);
            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 ());
            glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    
            // Turn on auto texture mapping
            
            glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
            glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
            glEnable (GL_TEXTURE_GEN_S);
            glEnable (GL_TEXTURE_GEN_T);
            
            ilDeleteImages (1, &uiTex);
            return true;
    }
    I'm pretty certain it's nothing to do with glTexGeni because even if I don't call it and do the texture mapping myself in the Render function it makes no difference. Talking of which:

    Code:
    void Player::Render (GLfloat fMoveX, GLfloat fMoveY)
    {
            glTranslatef (fMoveX, fMoveY, 0.0f);
            glBindTexture (GL_TEXTURE_2D, Texture[0]);
            glBegin (GL_QUADS);
                    glVertex2f (-0.05f, -0.05f);
                    glVertex2f (0.05f, -0.05f);
                    glVertex2f (0.05f, 0.05f);
                    glVertex2f (-0.05f, 0.05f);
            glEnd ();
            glTranslatef (-fMoveX, -fMoveY, 0.0f);
    }
    I have no idea what's wrong, I'm sorry to dump all this code up here but I've been fiddling with it for a couple of hours with no avail. If you need to take a look at the main file just say the word and I'll post them up (.h and .cpp).

    Help!
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    What is the actual problem?? Is it that the image wont display or what??
    STL Util a small headers-only library with various utility functions. Mainly for fun but feedback is welcome.

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Oops, sorry.
    No I don't get any image, just the default white quad.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Ok first of all, you are not specifying calling glTexCoord2f or any of its equivalent in the drawing function. Second you might also want to check an extra time so that GL_TEXTURE_2D is enabled before you start the drawing (not sure if its required before you call glGenTextures but enable it before that too just to be sure).

    Edit: reread your post and did some lookup on some functions. First try with enabling GL_TEXTURE_2D before you load the texture and before you draw it. That way we can exclude that one if it still doesnt work.
    Last edited by Shakti; 12-20-2005 at 12:21 PM.
    STL Util a small headers-only library with various utility functions. Mainly for fun but feedback is welcome.

  5. #5
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    That made no difference. I enabled GL_TEXTURE_2D before loading the texture, then before drawing in the Render function.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  6. #6
    ---
    Join Date
    May 2004
    Posts
    1,379
    But are you applying the texture to the quad like Shakti said? glTexCoord2f

  7. #7
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Yes I've tried that and glTexGeni - nothing works. It doesn't matter I've spent more time on it than I wanted to so I'm starting over this afternoon - tis my last day at college!
    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. D3d Texture Wrapper == ARRRGGGGHHH
    By yaya in forum Game Programming
    Replies: 1
    Last Post: 03-25-2009, 06:41 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. OpenIL Problem
    By cboard_member in forum Game Programming
    Replies: 1
    Last Post: 12-20-2005, 04:52 AM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM