OK, now that the 3D engine is running nicely, I am having a big problem figuring out how to load textures only once. Afterwards, how do I refer to a texture since it’s given a number, yet the polygons refer to the bitmap filename? Here is an example:
//Bitmap loading Routine
BOOL LoadBMP(char *texname)
{
char texbuf[256];
GLubyte fixer, image[32][32][3];
FILE *texfile;
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;sprintf(texbuf, “…\Textures\%s”, texname);
if((texfile = fopen(texbuf, “rb”)) == NULL)
return FALSE;fread(&bmfh, sizeof(BITMAPFILEHEADER), 1, texfile);
fread(&bmih, sizeof(BITMAPINFOHEADER), 1, texfile);
fread(&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;
}
}glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
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);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, image);texnum++;
return TRUE;
}//Level Loading Routine
BOOL LoadWorld(char *map)
{
int numObjTri;
FILE *worldfile;FreeWorld();
texnum = 0;if((worldfile = fopen(map, “rb”)) == NULL)
return FALSE;fread(&area.numObjects, sizeof(unsigned long), 1, worldfile);
fread(&area.numSprites, sizeof(unsigned long), 1, worldfile);
fread(&area.numLights, sizeof(unsigned long), 1, worldfile);area.object = new OBJECT[area.numObjects];
for(unsigned long loop = 0; loop < area.numObjects; loop++)
{
fread(&area.object[loop].Type, sizeof(char), 1, worldfile);
fread(&area.object[loop].Texture, sizeof(char[16]), 1, worldfile);
fread(&numObjTri, sizeof(int), 1, worldfile);
area.object[loop].triangle = new TRIANGLE[numObjTri];
area.object[loop].numTriangles = numObjTri;
for(int t_loop = 0; t_loop < numObjTri; t_loop++)
{
fread(&area.object[loop].triangle[t_loop], sizeof(TRIANGLE), 1, worldfile);
}
}fclose(worldfile);
for(unsigned long loop = 0; loop < area.numObjects; loop++)
if(!LoadBMP(area.object[loop].Texture))
return FALSE;return TRUE;
}
As you can see, that is a horrible way to load textures, since the level may have “Tiles.bmp” on six objects. This means that each object would trigger a load! Now texnum is a globaly declared int, and texture is a global GLuint. Even after I get the repeat texture loading problem solved, how will I tell OpenGL what texture to bind to in the drawing routine, since it references the bitmap name? Thanks for the help, since i can see no way to do this that wouldn’t result in a MAJOR performance decrease.