I'd swear that I had this fixed before, but appearently not. Or maybe it was fixed, and I somehow broke it again. Either way, I can't figure out how to fix it this time.
I have a texture class and a texture manager class (CTexture and CTextureManager respectivly) that I use for creating and applying textures in my engine.
The problem is, that all my objects will only use the texture that was loaded last, regardless of the ID I set (you'll see how this is done in the code below).
CTexture:
PHP Code:
public ref class CTexture{
public:
String ^name;
int ilImageName;
unsigned int id;
TEX_TYPE type;
TEX_FORMAT format;
public:
CTexture(String ^file, TEX_TYPE type, TEX_FORMAT format);
~CTexture(){
CUtility::Log("Deleted texture '"+name+"'");
}
};
CTextureManager:
PHP Code:
public ref class CTextureManager{
public:
static unsigned int numTextures;
static array<CTexture^> ^textures;
public:
CTextureManager(){
numTextures = 0;
textures = gcnew array<CTexture^>(MAX_TEXTURES);
}
~CTextureManager(){
CUtility::Log("Killed texture manager.");
}
void NewTexture(String ^file, TEX_TYPE type, TEX_FORMAT format);
void SetTexture(CTexture ^tex, TEX_UNIT unit);
};
Those were the class defs. Here are the functions (i'm going to leave out the code for actually creating the texture (CTexture's constructor), to avoid making this post too long. I'm 99% sure that much is correct anyway).
NewTexture and SetTexture:
PHP Code:
void CTextureManager::NewTexture(String ^file, TEX_TYPE type, TEX_FORMAT format){
textures[numTextures] = gcnew CTexture(file, type, format);
CUtility::Log("Created texture '"+file+"'");
numTextures++;
}
void CTextureManager::SetTexture(CTexture ^tex, TEX_UNIT unit){
Gl::glActiveTexture(unit);
Gl::glEnable(tex->type);
Gl::glBindTexture(tex->type, tex->id);
}
Now, all I should have to do to create a texture for an object is do this:
PHP Code:
this->texID[0] = CGfxCtrl::texManager->numTextures;
CGfxCtrl::texManager->NewTexture(texture, _2D, RGB8);
And set the texture like this:
PHP Code:
CGfxCtrl::texManager->SetTexture(CGfxCtrl::texManager->textures[obj->texID[0]], UNIT0);
before drawing.
I can't figure out why this won't work, but perhaps one of you can .
Thanks.