X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FOpenGL_Windows.cpp;h=e112066ebb79df5d3c0946be2b206cc709278283;hb=a04b9ae281db1ca19937c0c30e138e9ed57b0d21;hp=ddf9408a26c370822a0dc4c005c21812275de534;hpb=2fea8aa4d67ff70b015a34eb058a5e598b3d737d;p=lugaru.git diff --git a/Source/OpenGL_Windows.cpp b/Source/OpenGL_Windows.cpp index ddf9408..e112066 100644 --- a/Source/OpenGL_Windows.cpp +++ b/Source/OpenGL_Windows.cpp @@ -29,34 +29,23 @@ 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 "jpeglib.h" +} - #include "Game.h" - extern "C" { - #include "zlib.h" - #include "png.h" - #include "jpeglib.h" - } +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 @@ -125,8 +114,6 @@ extern float volume; #include #endif -#include "fmod.h" - #include "res/resource.h" using namespace std; @@ -276,7 +263,6 @@ static int _argc = 0; static char **_argv = NULL; #endif -#ifdef _WIN32 bool cmdline(const char *cmd) { for (int i = 1; i < _argc; i++) @@ -290,21 +276,6 @@ bool cmdline(const char *cmd) return false; } -#else -bool cmdline(const char *cmd) -{ - for (int i = 1; i < _argc; i++) - { - char *arg = _argv[i]; - while (*arg == '-') - arg++; - if (stricmp(arg, cmd) == 0) - return true; - } - - return false; -} -#endif // -------------------------------------------------------------------------- @@ -1030,25 +1001,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; @@ -1181,7 +1133,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 @@ -1220,9 +1172,7 @@ void CleanUp (void) // game.Dispose(); -#if USE_DEVIL - ilShutDown(); -#endif + #if USE_SDL SDL_Quit(); @@ -1330,12 +1280,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); } @@ -1605,58 +1555,58 @@ int main(int argc, char **argv) } 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); } } @@ -1669,105 +1619,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); } @@ -1926,10 +1801,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); } @@ -2007,5 +1882,5 @@ save_png_done: return retval; } -#endif +