Archived

This topic is now archived and is closed to further replies.

glGreenhorn

confused

Recommended Posts

glGreenhorn    122
hey, i have this little problem: i load a number of textures. the number of textures varies as it''s read from a file. so are the texture names. what i need to do is create an array of AUX_RGBImageRec * ''s as an array of pointers. what confuses me is the declaration syntax. so far i''ve come up with the following code: #define NUM_TEXTURES 1024 AUX_RGBImageRec * TextureImage[NUM_TEXTURES]; // 1) GLuint Texture[NUM_TEXTURES]; ///////// numTextures = 42; //e g this many textures are required to be loaded ///////// for(...) { TextureImage = new(AUX_RGBImageRec); // 2) } memset(TextureImage, 0, sizeof(void *) * numTextures); glGenTextures(numTextures, &Texture[0]); for(...) { //load all the files and create the textures } binding a texture from the list after it is loaded, however, doesn''t work as expected. i think it only loads one texture - i think it''s the first one only. my guess is something is wrong with the lines commented with 1) and 2)... how should i declare and allocate memory for an array of pointers to pointers to objects (AUX_RGBImageRec in this case)? thanks and keep cool !

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
this is what i did

  
int loadtextures(int number,char *Filename, char quality) // Load Bitmaps And Convert To Textures

{
int Status=FALSE; // Status Indicator


AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture


memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL


if (TextureImage[0]=LoadBMP(Filename))
{
Status=TRUE; // Set The Status To TRUE


glGenTextures(1, &text[number]); // Create Three Textures


switch(quality)
{
case 1:
{
// Create Nearest Filtered Texture

glBindTexture(GL_TEXTURE_2D, text[number]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
break;
}
case 2:
{
// Create Linear Filtered Texture

glBindTexture(GL_TEXTURE_2D, text[number]);
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, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
break;
}
case 3:
{
// Create MipMapped Texture

glBindTexture(GL_TEXTURE_2D, text[number]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
break;
}
}


}

if (TextureImage[0])
{
if (TextureImage[0]->data)
{
free(TextureImage[0]->data);
}
free(TextureImage[0]);
}
return Status;
}

Share this post


Link to post
Share on other sites