float dialoguetime;
int dialoguegonethrough[20];
+std::vector<TextureInfo> Game::textures;
+
Game::Game()
{
terraintexture = 0;
extern GLuint rabbittexture;
+struct TextureInfo;
+
class Game
{
public:
- typedef std::map<std::string, GLuint> TextureList;
- typedef std::map<GLuint, std::string> GLTextureList;
- typedef TextureList::iterator TexIter;
- static TextureList textures;
+ static std::vector<TextureInfo> textures;
GLuint terraintexture;
GLuint terraintexture2;
static void LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha);
static void LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize);
+ static void LoadTextureData(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha);
+ static void LoadTextureSaveData(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize, bool reload);
void LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize);
- bool AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize);
+ bool AddClothes(const char *fileName, GLubyte *array);
void InitGame();
+ void LoadScreenTexture();
void LoadStuff();
void LoadingScreen();
void FadeLoadingScreen(float howmuch);
Account* accountactive;
};
+//keeps track of which textures are loaded
+//TODO: delete them properly
+struct TextureInfo{
+ bool isLoaded;
+ bool isSkin;
+ const char* fileName;
+ GLuint* ptextureid;
+ int mipmap;
+ bool hasalpha;
+ GLubyte* array;
+ int* skinsize;
+
+ void load(){
+ if(isSkin)
+ Game::LoadTextureSaveData(fileName,ptextureid,mipmap,array,skinsize,isLoaded);
+ else
+ Game::LoadTextureData(fileName,ptextureid,mipmap,hasalpha);
+ isLoaded=true;
+ }
+ TextureInfo(const char *_fileName, GLuint *_ptextureid,int _mipmap, bool _hasalpha):
+ isLoaded(false), isSkin(false), array(NULL), skinsize(NULL),
+ fileName(_fileName), ptextureid(_ptextureid), mipmap(_mipmap), hasalpha(_hasalpha) { }
+ TextureInfo(const char *_fileName, GLuint *_ptextureid, int _mipmap, GLubyte *_array, int *_skinsize):
+ isLoaded(false), isSkin(true), hasalpha(false),
+ fileName(_fileName), ptextureid(_ptextureid), mipmap(_mipmap), array(_array), skinsize(_skinsize) { }
+};
+
#ifndef __forceinline
# ifdef __GNUC__
# define __forceinline inline __attribute__((always_inline))
}
-Game::TextureList Game::textures;
-
void Game::Dispose()
{
int i,j;
Account::saveFile(":Data:Users", accountactive);
- TexIter it = textures.begin();
- for (; it != textures.end(); ++it)
- {
- if (glIsTexture(it->second))
- glDeleteTextures(1, &it->second);
- }
- textures.clear();
+ //textures.clear();
LOG("Shutting down sound system...");
}
-void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
+void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha){
+ textures.push_back(TextureInfo(fileName,textureid,mipmap,hasalpha));
+ textures.back().load();
+}
+
+void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize){
+ textures.push_back(TextureInfo(fileName,textureid,mipmap,array,skinsize));
+ textures.back().load();
+}
+
+void Game::LoadTextureData(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
{
GLuint type;
}
}
-void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
+void Game::LoadTextureSaveData(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize, bool reload)
{
GLuint type;
int i;
if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
int tempnum=0;
- for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
- if((i+1)%4||type==GL_RGB){
- array[tempnum]=texture.data[i];
- tempnum++;
- }
- }
+ if(!reload)
+ for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++)
+ if((i+1)%4||type==GL_RGB){
+ array[tempnum]=texture.data[i];
+ tempnum++;
+ }
*skinsize=texture.sizeX;
}
}
-bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
+bool Game::AddClothes(const char *fileName, GLubyte *array)
{
int i;
int bytesPerPixel;
}
+void Game::LoadScreenTexture(){
+ glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
+
+ if(!screentexture)
+ glGenTextures( 1, &screentexture );
+ glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
+
+
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture( GL_TEXTURE_2D, screentexture);
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+
+ glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
+}
+
void Game::LoadStuff()
{
static float temptexdetail;
//if(ismotionblur){
if(!screentexture){
- glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
- glGenTextures( 1, &screentexture );
- glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-
-
- glEnable(GL_TEXTURE_2D);
- glBindTexture( GL_TEXTURE_2D, screentexture);
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-
- glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
+ LoadScreenTexture();
}
if(targetlevel!=7){
char buf[64];
snprintf(buf, 63, ":Data:Textures:%s.png", args);
- if (!game->AddClothes(buf,0,1,&player[pnum].skeleton.skinText[pnum],&player[pnum].skeleton.skinsize))
+ if (!game->AddClothes(buf,&player[pnum].skeleton.skinText[pnum]))
return;
player[pnum].DoMipmaps();
tintr=player[i].clothestintr[j];
tintg=player[i].clothestintg[j];
tintb=player[i].clothestintb[j];
- AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
+ AddClothes((char *)player[i].clothes[j],&player[i].skeleton.skinText[0]);
}
player[i].DoMipmaps();
}
tintr=player[closest].clothestintr[i];
tintg=player[closest].clothestintg[i];
tintb=player[closest].clothestintb[i];
- AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
+ AddClothes((char *)player[closest].clothes[i],&player[closest].skeleton.skinText[0]);
}
player[closest].DoMipmaps();
}
tintr=player[numplayers].clothestintr[i];
tintg=player[numplayers].clothestintg[i];
tintb=player[numplayers].clothestintb[i];
- AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
+ AddClothes((char *)player[numplayers].clothes[i],&player[numplayers].skeleton.skinText[0]);
}
if(player[numplayers].numclothes){
player[numplayers].DoMipmaps();
fprintf(stderr, "Failed to initialize stereo, disabling.\n");
stereomode = stereoNone;
}
-
- //TODO: load textures here
}
static void toggleFullscreen(){
screen=SDL_SetVideoMode(0,0,0,flags);
if(!screen)
exit(1);
+ //reload opengl state
initGL();
+ for(std::vector<TextureInfo>::iterator it=Game::textures.begin(); it!=Game::textures.end(); it++){
+ it->load();
+ }
+ pgame->text.BuildFont();
+ pgame->LoadScreenTexture();
}
static void sdlEventProc(const SDL_Event &e, Game &game){
}
Uint32 sdlflags = SDL_OPENGL;
- if (!cmdline("windowed"))
- sdlflags |= SDL_FULLSCREEN;
+ //TODO: commented out temporarily
+ //if (!cmdline("windowed"))
+ //sdlflags |= SDL_FULLSCREEN;
SDL_WM_SetCaption("Lugaru", "Lugaru");
if (base)
{
- LOG("Font already created...");
- return;
+ glDeleteLists(base, 512);
+ base = 0;
+ //LOG("Font already created...");
+ //return;
}
// base=glGenLists(256); // Creating 256 Display Lists