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!