This commit is contained in:
parent
90d4097793
commit
7123b53ece
17 changed files with 294 additions and 177 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <gl\gl.h>
|
||||
#include <gl\glu.h>
|
||||
#include <gl\glut.h>
|
||||
#include <gl\glaux.h> // Header File For The Glaux Library
|
||||
#include <Vector>
|
||||
|
||||
#include "TexCache.h"
|
||||
|
@ -15,32 +16,113 @@
|
|||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
int CTexCache::ProcessTexture(char *TexName,char *Path,int Flags)
|
||||
int CTexCache::GetTexIdx(char *Name,int Flags)
|
||||
{
|
||||
int ListSize=TexList.size();
|
||||
|
||||
// Check if Tex exists
|
||||
|
||||
for (int Count=0;Count<ListSize;Count++)
|
||||
{
|
||||
if (strcmp(TexName,TexList[Count].Name)==0 && TexList[Count].Flags==Flags)
|
||||
if (strcmp(Name,TexList[Count].Name)==0 && TexList[Count].Flags==Flags)
|
||||
{
|
||||
return(Count);
|
||||
}
|
||||
}
|
||||
sTex NewTex;
|
||||
char Filename[256];
|
||||
strcpy(NewTex.Name,TexName);
|
||||
strcpy(NewTex.Path,Path);
|
||||
sprintf(Filename,"%s%s",Path,TexName);
|
||||
TRACE1("Loading Texture %s\n",Filename);
|
||||
LoadGLTexture(Filename,NewTex.TexID);
|
||||
NewTex.Flags=Flags;
|
||||
TexList.push_back(NewTex);
|
||||
|
||||
return(Count);
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
int CTexCache::ProcessTexture(char *TexName,char *Path,int Flags,sRGBData *RGBData)
|
||||
{
|
||||
int ListSize=TexList.size();
|
||||
int Idx;
|
||||
char Name[_MAX_FNAME];
|
||||
|
||||
_splitpath(TexName,0,0,Name,0);
|
||||
|
||||
// Check if Tex exists
|
||||
/* for (int Count=0;Count<ListSize;Count++)
|
||||
{
|
||||
if (strcmp(Name,TexList[Count].Name)==0 && TexList[Count].Flags==Flags)
|
||||
{
|
||||
return(Count);
|
||||
}
|
||||
}
|
||||
*/
|
||||
Idx=GetTexIdx(Name,Flags);
|
||||
if (Idx!=-1) return(Idx);
|
||||
|
||||
sTex NewTex;
|
||||
sRGBData ThisRGB;
|
||||
|
||||
strcpy(NewTex.Name,Name);
|
||||
strcpy(NewTex.Path,Path);
|
||||
NewTex.Flags=Flags;
|
||||
|
||||
if (!RGBData) // Need to load file
|
||||
{
|
||||
char Filename[_MAX_PATH];
|
||||
|
||||
sprintf(Filename,"%s%s.Bmp",Path,Name);
|
||||
TRACE1("Loading Texture %s\n",Filename);
|
||||
LoadBMP(Filename,ThisRGB);
|
||||
RGBData=&ThisRGB;
|
||||
LoadTex(NewTex,RGBData);
|
||||
FreeBMP(ThisRGB);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadTex(NewTex,RGBData);
|
||||
}
|
||||
|
||||
TexList.push_back(NewTex);
|
||||
|
||||
return(ListSize);
|
||||
}
|
||||
|
||||
/**************************************************************************************/
|
||||
/**************************************************************************************/
|
||||
/**************************************************************************************/
|
||||
void CTexCache::LoadBMP(char *Filename,sRGBData &RGBData)
|
||||
{
|
||||
FILE *File=NULL;
|
||||
AUX_RGBImageRec *Aux;
|
||||
|
||||
Aux=auxDIBImageLoad(Filename);
|
||||
RGBData.Width=Aux->sizeX;
|
||||
RGBData.Height=Aux->sizeY;
|
||||
RGBData.RGB=(char*)Aux->data;
|
||||
free(Aux); // Safe to free aux now, contents copied (I HATE AUX)
|
||||
}
|
||||
|
||||
/**************************************************************************************/
|
||||
void CTexCache::FreeBMP(sRGBData &RGBData)
|
||||
{
|
||||
if (RGBData.RGB)
|
||||
{
|
||||
free((unsigned char*)RGBData.RGB);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************************/
|
||||
void CTexCache::LoadTex(sTex &ThisTex,sRGBData *TexData)
|
||||
{
|
||||
ThisTex.Width=TexData->Width;
|
||||
ThisTex.Height=TexData->Height;
|
||||
|
||||
glGenTextures(1, &ThisTex.TexID);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, ThisTex.TexID);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, 3, TexData->Width, TexData->Height, 0, GL_RGB, GL_UNSIGNED_BYTE, TexData->RGB);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
/**************************************************************************************/
|
||||
/**************************************************************************************/
|
||||
/**************************************************************************************/
|
||||
|
||||
void CTexCache::Purge()
|
||||
{
|
||||
int ListSize=TexList.size();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue