PDA

View Full Version : Loading Multiple Textures...



Sephiroth
01-19-2002, 06:21 PM
OK, I have been tweaking and modifying the rest of my game, but I desperately need tog et multiple texture loading working. Before I would only load two or three textures and reference them through loops and checks for the one small level I created. However, I needed a much more flexible system if I ever wanted to make something as nice as Unreal, so I have started working on it, but it won't work. Here are my code snippets, maybe one of you guys can help.




//Finds The Right Texture For
//My Triangle Drawing Routine
unsigned long FindTexture(char *texname)
{
char texbuf[32];

sprintf(texbuf, "%s", texname);
for(unsigned long loop = 0; loop < MAX_TEXTURES; loop++)
if(strstr(texture[loop].name, texbuf) != NULL)
return (loop + 1);

return 0;
}

//This Is SUPPOSED To Load The
//Bitmaps Each Object Uses
BOOL LoadBMP(unsigned long numTextures)
{
char texbuf[256];
int texnum = 0;
GLubyte fixer, image[32][32][3];
BOOL status;
FILE *texfile;
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;

//Generate the proper number of textures...
glGenTextures(numTextures, &amp;texture[0].handle);

for(unsigned long loop = 0; loop < numTextures; loop++)
{
//See if the current texture is already loaded...
status = TRUE;
for(unsigned long t_loop = 0; t_loop < MAX_TEXTURES; t_loop++)
if(strstr(texture[t_loop].name, area.object[loop].Texture) != NULL)
{
status = FALSE;
break;
}

//The texture was loaded, loop and go for the next one...
if(!status)
continue;

sprintf(texture[texnum].name, "%s", area.object[loop].Texture);
MessageBox(glwnd, texture[texnum].name, "LoadBMP(unsigned long)", MB_OK);
sprintf(texbuf, "Textures\\%s", texture[texnum].name);
if((texfile = fopen(texbuf, "rb")) == NULL)
return FALSE;

fread(&amp;bmfh, sizeof(BITMAPFILEHEADER), 1, texfile);
fread(&amp;bmih, sizeof(BITMAPINFOHEADER), 1, texfile);
fread(&amp;image, sizeof(image), 1, texfile);
fclose(texfile);

for(short int x_loop = 0; x_loop < 32; x_loop++)
{
for(short int y_loop = 0; y_loop < 32; y_loop++)
{
fixer = image[y_loop][x_loop][0];
image[y_loop][x_loop][0] = image[y_loop][x_loop][2];
image[y_loop][x_loop][2] = fixer;
}
}

glBindTexture(GL_TEXTURE_2D, texture[texnum].handle);
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_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 32, 32, GL_RGB, GL_UNSIGNED_BYTE, image);

texnum++;
}

return TRUE;
}

//And This Is How I Bind To
//Textures And Draw Them...
for(unsigned long o_loop = 0; o_loop < area.numObjects; o_loop++)
{
glBindTexture(GL_TEXTURE_2D, FindTexture(area.object[o_loop].Texture));
glBegin(GL_TRIANGLES);
for(int t_loop = 0; t_loop < area.object[o_loop].numTriangles; t_loop++)
{
glTexCoord2f(area.object[o_loop].triangle[t_loop].vertex[0].u, area.object[o_loop].triangle[t_loop].vertex[0].v);
glVertex3f(area.object[o_loop].triangle[t_loop].vertex[0].x, area.object[o_loop].triangle[t_loop].vertex[0].y, area.object[o_loop].triangle[t_loop].vertex[0].z);

glTexCoord2f(area.object[o_loop].triangle[t_loop].vertex[1].u, area.object[o_loop].triangle[t_loop].vertex[1].v);
glVertex3f(area.object[o_loop].triangle[t_loop].vertex[1].x, area.object[o_loop].triangle[t_loop].vertex[1].y, area.object[o_loop].triangle[t_loop].vertex[1].z);

glTexCoord2f(area.object[o_loop].triangle[t_loop].vertex[2].u, area.object[o_loop].triangle[t_loop].vertex[2].v);
glVertex3f(area.object[o_loop].triangle[t_loop].vertex[2].x, area.object[o_loop].triangle[t_loop].vertex[2].y, area.object[o_loop].triangle[t_loop].vertex[2].z);
}
glEnd();
}

Right now the level has the "Carved Stone.bmp" image for the walls, which will NOT load for some reason, and it uses "Tiles.bmp" for the ceiling/floor, which does load. Any ideas with what is wrong here, and after it's fixed, if there is any faster way to do this? Thanks for the help.