X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FOpenGL_Windows.cpp;h=24284725e5605a24f0f17a585c04b11b4ae73332;hb=8c25b8cd0c73ebf728cebb2cfbdb256b30fd0310;hp=2334e460b4c00a04094890b64b2193108da8ad0f;hpb=fe831b45a76f058d17bfef8b5f45d7e563d97089;p=lugaru.git diff --git a/Source/OpenGL_Windows.cpp b/Source/OpenGL_Windows.cpp index 2334e46..2428472 100644 --- a/Source/OpenGL_Windows.cpp +++ b/Source/OpenGL_Windows.cpp @@ -19,6 +19,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + #ifdef WIN32 #define UINT8 WIN32API_UINT8 #define UINT16 WIN32API_UINT16 @@ -29,34 +30,29 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #undef boolean #endif -#define USE_DEVIL 0 -#ifndef USE_DEVIL -# ifdef WIN32 -# define USE_DEVIL -# endif -#endif -#if USE_DEVIL - #include "IL/il.h" - #include "IL/ilu.h" - #include "IL/ilut.h" - #include "Game.h" -#else - - #include "Game.h" - extern "C" { - #include "zlib.h" - #include "png.h" +#include "Game.h" +extern "C" { + #include "zlib.h" + #include "png.h" + #ifdef WIN32 + #define INT32 INT32_jpeg #include "jpeglib.h" - } + #undef INT32 + #else + #include "jpeglib.h" + #endif +} + +static bool load_image(const char * fname, TGAImageRec & tex); +static bool load_png(const char * fname, TGAImageRec & tex); +static bool load_jpg(const char * fname, TGAImageRec & tex); +static bool save_image(const char * fname); +static bool save_png(const char * fname); - static bool load_image(const char * fname, TGAImageRec & tex); - static bool load_png(const char * fname, TGAImageRec & tex); - static bool load_jpg(const char * fname, TGAImageRec & tex); - static bool save_image(const char * fname); - static bool save_png(const char * fname); -#endif + +#include "openal_wrapper.h" // ADDED GWC #ifdef _MSC_VER @@ -101,6 +97,7 @@ extern Person player[maxplayers]; extern bool vblsync; extern bool stillloading; extern bool showpoints; +extern bool showdamagebar; extern bool alwaysblur; extern bool immediate; extern bool velocityblur; @@ -121,18 +118,17 @@ extern float volume; #include "gamegl.h" #include "MacCompatibility.h" + #ifdef WIN32 #include #endif -#include "fmod.h" - #include "res/resource.h" using namespace std; -#if USE_SDL + SDL_Rect **resolutions = NULL; static SDL_Rect rect_1024_768 = { 0, 0, 1024, 768 }; static SDL_Rect rect_800_600 = { 0, 0, 800, 600 }; @@ -143,7 +139,7 @@ static SDL_Rect *hardcoded_resolutions[] = { &rect_640_480, NULL }; -#endif + unsigned int resolutionDepths[8][2] = {0}; @@ -176,7 +172,7 @@ typedef struct tagPOINT { } POINT, *PPOINT; #endif -#if USE_SDL + #ifdef _MSC_VER #pragma warning(push) @@ -238,7 +234,7 @@ void sdlGetCursorPos(POINT *pt) #undef MessageBox #endif #define MessageBox(hwnd,text,title,flags) STUBBED("msgbox") -#endif + Point delta; @@ -283,7 +279,7 @@ bool cmdline(const char *cmd) char *arg = _argv[i]; while (*arg == '-') arg++; - if (stricmp(arg, cmd) == 0) + if (strcasecmp(arg, cmd) == 0) return true; } @@ -352,9 +348,7 @@ Boolean Button() return g_button; } -#if !USE_SDL -static void initSDLKeyTable(void) {} -#else + #define MAX_SDLKEYS SDLK_LAST static unsigned short KeyTable[MAX_SDLKEYS]; @@ -559,6 +553,8 @@ static void sdlEventProc(const SDL_Event &e, Game &game) ClearKey(MAC_CONTROL_KEY); if ((mod & KMOD_ALT) == 0) ClearKey(MAC_OPTION_KEY); + if ((mod & KMOD_META) == 0) + ClearKey(MAC_COMMAND_KEY); if ((mod & KMOD_SHIFT) == 0) ClearKey(MAC_SHIFT_KEY); if ((mod & KMOD_CAPS) == 0) @@ -566,7 +562,7 @@ static void sdlEventProc(const SDL_Event &e, Game &game) return; } } -#endif + // -------------------------------------------------------------------------- @@ -605,6 +601,7 @@ Boolean SetUp (Game & game) texttoggle=1; alwaysblur=0; showpoints=0; + showdamagebar=0; immediate=0; velocityblur=0; @@ -704,6 +701,8 @@ Boolean SetUp (Game & game) opstream << KeyToChar(game.attackkey); opstream << "\nChat key:\n"; opstream << KeyToChar(game.chatkey); + opstream << "\nDamage bar:\n"; + opstream << showdamagebar; opstream.close(); } if(ipstream){ @@ -850,16 +849,17 @@ Boolean SetUp (Game & game) ipstream.ignore(256,'\n'); ipstream >> string; game.chatkey=CharToKey(string); + ipstream.ignore(256,'\n'); + ipstream.ignore(256,'\n'); + ipstream >> i; + showdamagebar = (i != 0); ipstream.close(); if(detail>2)detail=2; if(detail<0)detail=0; if(screenwidth<0)screenwidth=640; if(screenheight<0)screenheight=480; -#if !USE_SDL // we'll take anything that works. - if(screenwidth>3000)screenwidth=640; - if(screenheight>3000)screenheight=480; -#endif + } if(kBitsPerPixel!=32&&kBitsPerPixel!=16){ kBitsPerPixel=16; @@ -870,7 +870,7 @@ Boolean SetUp (Game & game) SetupDSpFullScreen(); -#if USE_SDL + if (!SDL_WasInit(SDL_INIT_VIDEO)) { if (SDL_Init(SDL_INIT_VIDEO) == -1) @@ -968,7 +968,7 @@ Boolean SetUp (Game & game) if (!cmdline("nomousegrab")) SDL_WM_GrabInput(SDL_GRAB_ON); -#endif + glClear( GL_COLOR_BUFFER_BIT ); swap_gl_buffers(); @@ -1012,25 +1012,6 @@ Boolean SetUp (Game & game) glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glAlphaFunc( GL_GREATER, 0.5f); -#if USE_DEVIL - if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION || - iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION || - ilutGetInteger(ILUT_VERSION_NUM) < ILUT_VERSION) - { - ReportError("DevIL version is different...exiting!\n"); - return false; - } - - ilInit(); - iluInit(); - ilutInit(); - - ilutRenderer(ILUT_OPENGL); - - ilEnable(IL_ORIGIN_SET); - ilOriginFunc(IL_ORIGIN_LOWER_LEFT); -#endif - GLint width = kContextWidth; GLint height = kContextHeight; gMidPoint.h = width / 2; @@ -1050,7 +1031,7 @@ Boolean SetUp (Game & game) static void DoMouse(Game & game) { -#if USE_SDL + if(mainmenu||(abs(game.deltah)<10*realmultiplier*1000&&abs(game.deltav)<10*realmultiplier*1000)) { game.deltah *= usermousesensitivity; @@ -1066,7 +1047,7 @@ static void DoMouse(Game & game) else if (game.mousecoordv >= kContextHeight) game.mousecoordv = kContextHeight - 1; } -#endif + } @@ -1163,7 +1144,7 @@ void DoUpdate (Game & game) AbsoluteTime currTime = UpTime (); static int num_channels = 0; - num_channels += FSOUND_GetChannelsPlaying(); + num_channels += OPENAL_GetChannelsPlaying(); double deltaTime = (float) AbsoluteDeltaToDuration (currTime, start); if (0 > deltaTime) // if negative microseconds @@ -1202,11 +1183,9 @@ void CleanUp (void) // game.Dispose(); -#if USE_DEVIL - ilShutDown(); -#endif -#if USE_SDL + + SDL_Quit(); #define GL_FUNC(ret,fn,params,call,rt) p##fn = NULL; #include "glstubs.h" @@ -1214,18 +1193,14 @@ void CleanUp (void) // cheat here...static destructors are calling glDeleteTexture() after // the context is destroyed and libGL unloaded by SDL_Quit(). pglDeleteTextures = glDeleteTextures_doNothing; -#endif + } // -------------------------------------------------------------------------- -static bool g_focused = true; - - static bool IsFocused() { - STUBBED("write me"); - return true; + return ((SDL_GetAppState() & SDL_APPINPUTFOCUS) != 0); } @@ -1312,12 +1287,12 @@ char *calcBaseDir(const char *argv0) char *retval; char *envr; - char *ptr = strrchr((char *)argv0, '/'); + const char *ptr = strrchr((char *)argv0, '/'); if (strchr(argv0, '/')) { retval = strdup(argv0); if (retval) - *(strrchr(retval, '/')) = '\0'; + *((char *) strrchr(retval, '/')) = '\0'; return(retval); } @@ -1388,14 +1363,14 @@ int main(int argc, char **argv) if (!SetUp (game)) return 42; - while (!gDone&&!game.quit&&(!game.tryquit||!game.registered)) + while (!gDone&&!game.quit&&(!game.tryquit)) { if (IsFocused()) { gameFocused = true; // check windows messages - #if USE_SDL + game.deltah = 0; game.deltav = 0; SDL_Event e; @@ -1409,7 +1384,7 @@ int main(int argc, char **argv) } sdlEventProc(e, game); } - #endif + // game DoUpdate(game); @@ -1471,41 +1446,7 @@ int main(int argc, char **argv) // -------------------------------------------------------------------------- -#if !USE_SDL - int resolutionID(int width, int height) - { - int whichres; - whichres=-1; - if(width==640 && height==480)whichres=0; - if(width==800 && height==600)whichres=1; - if(width==1024 && height==768)whichres=2; - if(width==1280 && height==1024)whichres=3; - if(width==1600 && height==1200)whichres=4; - if(width==840 && height==524)whichres=5; - if(width==1024 && height==640)whichres=6; - if(width==1344 && height==840)whichres=7; - if(width==1920 && height==1200)whichres=8; - - return whichres; - } - int closestResolution(int width, int height) - { - int whichres; - whichres=-1; - if(width>=640 && height>=480)whichres=0; - if(width>=800 && height>=600)whichres=1; - if(width>=1024 && height>=768)whichres=2; - if(width>=1280 && height>=1024)whichres=3; - if(width>=1600 && height>=1200)whichres=4; - if(width==840 && height==524)whichres=5; - if(width==1024 && height==640)whichres=6; - if(width==1344 && height==840)whichres=7; - if(width>=1920 && height>=1200)whichres=8; - - return whichres; - } -#endif bool selectDetail(int & width, int & height, int & bpp, int & detail) { @@ -1513,135 +1454,68 @@ int main(int argc, char **argv) // currently with SDL, we just use whatever is requested // and don't care. --ryan. - #if !USE_SDL - int whichres = closestResolution(width, height); - - while (true) - { - if(whichres<=0 || whichres>8){ - whichres = 0; - width=640; - height=480; - } - if(whichres==1){ - width=800; - height=600; - } - if(whichres==2){ - width=1024; - height=768; - } - if(whichres==3){ - width=1280; - height=1024; - } - if(whichres==4){ - width=1600; - height=1200; - } - if(whichres==5){ - width=840; - height=524; - } - if(whichres==6){ - width=1024; - height=640; - } - if(whichres==7){ - width=1344; - height=840; - } - if(whichres==8){ - width=1920; - height=1200; - } - - if ((detail != 0) && (resolutionDepths[whichres][1] != 0)) - { - break; - } - else if ((detail == 0) && (resolutionDepths[whichres][0] != 0)) - { - break; - } - else if ((detail != 0) && (resolutionDepths[whichres][0] != 0)) - { - res = false; - detail = 0; - break; - } - else - - if (0 == whichres) - { - break; - } - - --whichres; - } - - bpp = resolutionDepths[whichres][(detail != 0)]; - #endif + return res; } extern int channels[100]; - extern FSOUND_SAMPLE * samp[100]; - extern FSOUND_STREAM * strm[20]; + extern OPENAL_SAMPLE * samp[100]; + extern OPENAL_STREAM * strm[20]; - extern "C" void PlaySoundEx(int chan, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused) + extern "C" void PlaySoundEx(int chan, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused) { - const FSOUND_SAMPLE * currSample = FSOUND_GetCurrentSample(channels[chan]); + const OPENAL_SAMPLE * currSample = OPENAL_GetCurrentSample(channels[chan]); if (currSample && currSample == samp[chan]) { - if (FSOUND_GetPaused(channels[chan])) + if (OPENAL_GetPaused(channels[chan])) { - FSOUND_StopSound(channels[chan]); - channels[chan] = FSOUND_FREE; + OPENAL_StopSound(channels[chan]); + channels[chan] = OPENAL_FREE; } - else if (FSOUND_IsPlaying(channels[chan])) + else if (OPENAL_IsPlaying(channels[chan])) { - int loop_mode = FSOUND_GetLoopMode(channels[chan]); - if (loop_mode & FSOUND_LOOP_OFF) + int loop_mode = OPENAL_GetLoopMode(channels[chan]); + if (loop_mode & OPENAL_LOOP_OFF) { - channels[chan] = FSOUND_FREE; + channels[chan] = OPENAL_FREE; } } } else { - channels[chan] = FSOUND_FREE; + channels[chan] = OPENAL_FREE; } - channels[chan] = FSOUND_PlaySoundEx(channels[chan], sptr, dsp, startpaused); + channels[chan] = OPENAL_PlaySoundEx(channels[chan], sptr, dsp, startpaused); if (channels[chan] < 0) { - channels[chan] = FSOUND_PlaySoundEx(FSOUND_FREE, sptr, dsp, startpaused); + channels[chan] = OPENAL_PlaySoundEx(OPENAL_FREE, sptr, dsp, startpaused); } } - extern "C" void PlayStreamEx(int chan, FSOUND_STREAM *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused) + extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused) { - const FSOUND_SAMPLE * currSample = FSOUND_GetCurrentSample(channels[chan]); - if (currSample && currSample == FSOUND_Stream_GetSample(sptr)) + const OPENAL_SAMPLE * currSample = OPENAL_GetCurrentSample(channels[chan]); + if (currSample && currSample == OPENAL_Stream_GetSample(sptr)) { - FSOUND_StopSound(channels[chan]); - FSOUND_Stream_Stop(sptr); + OPENAL_StopSound(channels[chan]); + OPENAL_Stream_Stop(sptr); } else { - FSOUND_Stream_Stop(sptr); - channels[chan] = FSOUND_FREE; + OPENAL_Stream_Stop(sptr); + channels[chan] = OPENAL_FREE; } - channels[chan] = FSOUND_Stream_PlayEx(channels[chan], sptr, dsp, startpaused); + channels[chan] = OPENAL_Stream_PlayEx(channels[chan], sptr, dsp, startpaused); if (channels[chan] < 0) { - channels[chan] = FSOUND_Stream_PlayEx(FSOUND_FREE, sptr, dsp, startpaused); + channels[chan] = OPENAL_Stream_PlayEx(OPENAL_FREE, sptr, dsp, startpaused); } } + bool LoadImage(const char * fname, TGAImageRec & tex) { bool res = true; @@ -1651,105 +1525,30 @@ int main(int argc, char **argv) return false; } - #if USE_DEVIL - ILstring f = strdup(ConvertFileName(fname)); - if (!f) - { - return false; - } - - ILuint iid=0; - ilGenImages(1, &iid); - ilBindImage(iid); - if (ilLoadImage(f)) - { - //iluFlipImage(); - tex.sizeX = ilGetInteger(IL_IMAGE_WIDTH); - tex.sizeY = ilGetInteger(IL_IMAGE_HEIGHT); - tex.bpp = ilGetInteger(IL_IMAGE_BITS_PER_PIXEL); - ILuint Bpp = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL), - imageSize = tex.sizeX * tex.sizeY * Bpp; - ILubyte *Data = ilGetData(); - memcpy(tex.data, Data, imageSize); - - // Truvision Targa files are stored as BGR colors - // We want RGB so Blue and Red bytes are switched - if (IL_TGA == ilGetInteger(IL_IMAGE_FORMAT)) - { - // Loop Through The Image Data - for (GLuint i = 0; i < int(imageSize); i += Bpp) - { - // Swaps The 1st And 3rd Bytes ('R'ed and 'B'lue) - GLbyte temp; // Temporary Variable - temp = tex.data[i]; // Temporarily Store The Value At Image Data 'i' - tex.data[i] = tex.data[i + 2]; // Set The 1st Byte To The Value Of The 3rd Byte - tex.data[i + 2] = temp; // Set The 3rd Byte To The Value In 'temp' (1st Byte Value) - } - } - } - else - { - res = false; - } - ilDeleteImages(1, &iid); -/* - if (tid) - { - GLuint texid = ilutGLLoadImage(f); - *tid = texid; - } - else if (mip) - { - ilutGLBuildMipmaps() - } - else - { - ilutGLTexImage(0); - } -*/ - free(f); - #else + res = load_image(fname, tex); - //if (!res) printf("failed to load %s\n", fname); - #endif + return res; } void ScreenShot(const char * fname) { - #if USE_DEVIL - ILstring f = strdup(fname); - if (!f) - { - return; - } - - ILuint iid; - ilGenImages(1, &iid); - ilBindImage(iid); - if (ilutGLScreen()) - { - ilSaveImage(f); - } - ilDeleteImages(1, &iid); - - free(f); - #else + save_image(fname); - #endif + } -#if !USE_DEVIL + static bool load_image(const char *file_name, TGAImageRec &tex) { - char *ptr = strrchr((char *)file_name, '.'); + const char *ptr = strrchr((char *)file_name, '.'); if (ptr) { - if (stricmp(ptr+1, "png") == 0) + if (strcasecmp(ptr+1, "png") == 0) return load_png(file_name, tex); - else if (stricmp(ptr+1, "jpg") == 0) + else if (strcasecmp(ptr+1, "jpg") == 0) return load_jpg(file_name, tex); } @@ -1908,10 +1707,10 @@ png_done: static bool save_image(const char *file_name) { - char *ptr = strrchr((char *)file_name, '.'); + const char *ptr = strrchr((char *)file_name, '.'); if (ptr) { - if (stricmp(ptr+1, "png") == 0) + if (strcasecmp(ptr+1, "png") == 0) return save_png(file_name); } @@ -1989,5 +1788,5 @@ save_png_done: return retval; } -#endif +