PDA

View Full Version : How many textures?



Kronos259
06-14-2003, 12:15 AM
I am using the followin method to apply textures
GLuint texture[6];

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

AUX_RGBImageRec *LoadBMP(char *Filename)
{
FILE *File=NULL;

if (!Filename)
{
return NULL;
}

File=fopen(Filename,"r");

if (File)
{
fclose(File);
return auxDIBImageLoad(Filename);
}

return NULL;
}

int LoadGLTextures(){

AUX_RGBImageRec *TextureImage[6];
memset(TextureImage,0,sizeof(void *)*1);
TextureImage[0] = LoadBMP("Files/1.bmp");
TextureImage[1] = LoadBMP("Files/2.bmp");
TextureImage[2] = LoadBMP("Files/3.bmp");
TextureImage[3] = LoadBMP("Files/4.bmp");
TextureImage[4] = LoadBMP("Files/5.bmp");
TextureImage[5] = LoadBMP("Files/6.bmp");

glGenTextures(6, &texture[0]);

glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R, GL_LINEAR_MIPMAP_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX,TextureImage[0]->sizeY, 0, GL_RGB,GL_UNSIGNED_BYTE, TextureImage[0]->data);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R, GL_LINEAR_MIPMAP_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX,TextureImage[1]->sizeY, 0, GL_RGB,GL_UNSIGNED_BYTE, TextureImage[1]->data);
glBindTexture(GL_TEXTURE_2D, texture[2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R, GL_LINEAR_MIPMAP_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[2]->sizeX,TextureImage[2]->sizeY, 0, GL_RGB,GL_UNSIGNED_BYTE, TextureImage[2]->data);
glBindTexture(GL_TEXTURE_2D, texture[3]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R, GL_LINEAR_MIPMAP_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[3]->sizeX,TextureImage[3]->sizeY, 0, GL_RGB,GL_UNSIGNED_BYTE, TextureImage[3]->data);
glBindTexture(GL_TEXTURE_2D, texture[4]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R, GL_LINEAR_MIPMAP_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[4]->sizeX,TextureImage[4]->sizeY, 0, GL_RGB,GL_UNSIGNED_BYTE, TextureImage[4]->data);
glBindTexture(GL_TEXTURE_2D, texture[5]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R, GL_LINEAR_MIPMAP_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[5]->sizeX,TextureImage[5]->sizeY, 0, GL_RGB,GL_UNSIGNED_BYTE, TextureImage[5]->data);


for (int t = 0; t < 6; t++) {
if (TextureImage[t]){
if (TextureImage[t]->data){
free(TextureImage[t]->data); }
free(TextureImage[t]); }
}


return 1;


}


when i continue trying to use one more texture(6+1) the apllication will hang and the computer will not respond!!!

Some help please!!!!!! It is really urgent.

Tokage
06-14-2003, 06:45 AM
Well first of all, it would be easier to use a for loop for applying them. But that's not what you're asking. It seems that you're making an array of 6 elements and adding texture #6 goes outside those bounds...