diff options
Diffstat (limited to 'src/openglgraphics.cpp')
-rw-r--r-- | src/openglgraphics.cpp | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index f30e866d..28fd47f6 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -33,6 +33,8 @@ #include <SDL.h> +#include <cmath> + #ifndef GL_TEXTURE_RECTANGLE_ARB #define GL_TEXTURE_RECTANGLE_ARB 0x84F5 #define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 @@ -76,8 +78,19 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) int displayFlags = SDL_ANYFORMAT | SDL_OPENGL; - mWidth = w; - mHeight = h; + const double targetRatio = (double) 640 / 360; // 1.77778 + const double requestedRatio = (double) w / h; + + if (requestedRatio < targetRatio) { + // Screen is higher / narrower than target aspect ratio: calculate + // scale based on height. + mScale = (int) std::floor((double) h / 360); + } else { + mScale = (int) std::floor((double) w / 640); + } + + mWidth = w / mScale; + mHeight = h / mScale; mBpp = bpp; mFullscreen = fs; mHWAccel = hwaccel; @@ -109,7 +122,7 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) #endif // Setup OpenGL - glViewport(0, 0, w, h); + glViewport(0, 0, mWidth * mScale, mHeight * mScale); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); int gotDoubleBuffer; SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &gotDoubleBuffer); @@ -634,7 +647,7 @@ void OpenGLGraphics::_beginDraw() glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(0.0, (double)mTarget->w, (double)mTarget->h, 0.0, -1.0, 1.0); + glOrtho(0.0, (double) mWidth, (double) mHeight, 0.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -646,7 +659,7 @@ void OpenGLGraphics::_beginDraw() glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - pushClipArea(gcn::Rectangle(0, 0, mTarget->w, mTarget->h)); + pushClipArea(gcn::Rectangle(0, 0, mWidth, mHeight)); } void OpenGLGraphics::_endDraw() @@ -713,12 +726,15 @@ bool OpenGLGraphics::pushClipArea(gcn::Rectangle area) transX += mClipStack.top().xOffset; transY += mClipStack.top().yOffset; + int x = (int) (mClipStack.top().x * mScale); + int y = mTarget->h - (int) ((mClipStack.top().y + + mClipStack.top().height) * mScale); + int width = (int) (mClipStack.top().width * mScale); + int height = (int) (mClipStack.top().height * mScale); + glPushMatrix(); glTranslatef(transX, transY, 0); - glScissor(mClipStack.top().x, - mTarget->h - mClipStack.top().y - mClipStack.top().height, - mClipStack.top().width, - mClipStack.top().height); + glScissor(x, y, width, height); return result; } @@ -730,11 +746,14 @@ void OpenGLGraphics::popClipArea() if (mClipStack.empty()) return; + int x = (int) (mClipStack.top().x * mScale); + int y = mTarget->h - (int) ((mClipStack.top().y + + mClipStack.top().height) * mScale); + int width = (int) (mClipStack.top().width * mScale); + int height = (int) (mClipStack.top().height * mScale); + glPopMatrix(); - glScissor(mClipStack.top().x, - mTarget->h - mClipStack.top().y - mClipStack.top().height, - mClipStack.top().width, - mClipStack.top().height); + glScissor(x, y, width, height); } void OpenGLGraphics::setColor(const gcn::Color& color) |