I have a problem with the textures in my program. I can’t apply a texture on a object. I load the textures, build the object textures, and then apply them, but nothing…
Here is some code to understand :
// This structure describe the element for a texture
typedef struct _TEXTURE
{
AUX_RGBImageRec* textureImage; // data of the bitmap
int textureIndice; // Reference of the texture
char* textureName; // name of the texture
struct _TEXTURE* next; // next TEXTURE (chain link)
} TEXTURE;
// This function defines the texture object
GLuint* SetParameterTEXTURE()
{
int cpt = 0;
GLuint* GLTexture;
TEXTURE* currentTEXTURE;
GLTexture = (GLuint*)malloc(nb_texture * sizeof(GLuint));
glGenTextures(nb_texture, GLTexture);
For each struct TEXTURE in the chain link
{
glBindTexture(GL_TEXTURE_2D, *(GLTexture + cpt));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, currentTEXTURE->textureImage->sizeX, currentTEXTURE->textureImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, currentTEXTURE->textureImage->data);
free(currentTEXTURE->textureImage);
currentTEXTURE->textureIndice = cpt;
cpt++;
}
return GLTexture;
}
// This function display the object
void DisplayFunc(GLuint* GLTexture)
{
…
Get the texture indice of the current element to draw
glBindTexture(GL_TEXTURE_2D, *(GLTexture + textureIndice);
Mapping
glTexCoord3f(…);
}
The function that loads the textures works perfectly, such as the mapping (mapping coords are generated by 3DS).
The problem is that there is no texture on the element. When I disable the line “glBindTexture(GL_TEXTURE_2D, *(GLTexture + cpt);” in the SetParameterTEXTURE func, there is only one texture (always the same, the first loaded in fact, but she is well mapped on its element) which is put on every element, although there are 3 or 4 textures in memory.
So did i forget something ?
Thanks to help me.
PS : of course i’ve called glEnable(GL_TEXTURE_2D);