diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/graphics.cpp | 49 | ||||
-rw-r--r-- | src/graphics.h | 9 | ||||
-rw-r--r-- | src/main.cpp | 8 |
3 files changed, 42 insertions, 24 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp index e71052df..98a17b4a 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -35,11 +35,17 @@ extern volatile int framesToDraw; - +#ifdef USE_OPENGL Graphics::Graphics(bool useOpenGL): mScreen(0), useOpenGL(useOpenGL) { } +#else +Graphics::Graphics(): + mScreen(0) +{ +} +#endif Graphics::~Graphics() { @@ -159,23 +165,8 @@ bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY, srcX += image->bounds.x; srcY += image->bounds.y; - if (!useOpenGL) { - // Check that preconditions for blitting are met. - if (!mScreen || !image->image) return false; - - SDL_Rect dstRect; - SDL_Rect srcRect; - dstRect.x = dstX; dstRect.y = dstY; - srcRect.x = srcX; srcRect.y = srcY; - srcRect.w = width; - srcRect.h = height; - - if (SDL_BlitSurface(image->image, &srcRect, mScreen, &dstRect) < 0) { - return false; - } - } #ifdef USE_OPENGL - else { + if (useOpenGL) { // Find OpenGL texture coordinates float texX1 = srcX / (float)image->texWidth; float texY1 = srcY / (float)image->texHeight; @@ -205,8 +196,24 @@ bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY, glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - } + } else #endif + { + // Check that preconditions for blitting are met. + if (!mScreen || !image->image) return false; + + SDL_Rect dstRect; + SDL_Rect srcRect; + dstRect.x = dstX; dstRect.y = dstY; + srcRect.x = srcX; srcRect.y = srcY; + srcRect.w = width; + srcRect.h = height; + + if (SDL_BlitSurface(image->image, &srcRect, mScreen, &dstRect) < 0) { + return false; + } + } + return true; } @@ -284,14 +291,14 @@ void Graphics::drawImageRect( void Graphics::updateScreen() { - if (useOpenGL) { #ifdef USE_OPENGL + if (useOpenGL) { glFlush(); glFinish(); SDL_GL_SwapBuffers(); + } else #endif - } - else { + { SDL_Flip(mScreen); } diff --git a/src/graphics.h b/src/graphics.h index cdbc4104..a3b4aab3 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -48,7 +48,11 @@ public gcn::SDLGraphics { /** * Constructor. */ +#ifdef USE_OPENGL Graphics(bool useOpenGL); +#else + Graphics(); +#endif /** * Destructor. @@ -145,7 +149,10 @@ public gcn::SDLGraphics { private: SDL_Surface *mScreen; - bool mFullscreen, mHWAccel, useOpenGL; + bool mFullscreen, mHWAccel; +#ifdef USE_OPENGL + bool useOpenGL; +#endif }; #endif diff --git a/src/main.cpp b/src/main.cpp index 5d06cf97..a6c07467 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -230,15 +230,19 @@ void init_engine() fullscreen = ((int)config.getValue("screen", 0) == 1); hwaccel = ((int)config.getValue("hwaccel", 0) == 1); +#ifdef USE_OPENGL bool useOpenGL = (config.getValue("opengl", 0) == 1); -#ifdef USE_OPENGL // Setup image loading for the right image format Image::setLoadAsOpenGL(useOpenGL); -#endif // Create the graphics context graphics = new Graphics(useOpenGL); +#else + // Create the graphics context + graphics = new Graphics(); +#endif + // Try to set the desired video mode if (!graphics->setVideoMode(width, height, bpp, fullscreen, hwaccel)) { |