]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/gui/glwidget.cpp
Fixed fullscreen mode, shrunk screen width.
[virtualjaguar] / src / gui / glwidget.cpp
index 56fcd0ed824de8490a95cf8e3440b935310dbe8a..af51f47ed3c8c093a6b6b41d85cde92732ceec0c 100644 (file)
@@ -9,6 +9,7 @@
 // Who  When        What
 // ---  ----------  -------------------------------------------------------------
 // JLH  01/14/2010  Created this file
+// JLH  02/03/2013  Added "centered" fullscreen mode with correct aspect ratio
 //
 
 #include "glwidget.h"
 #include <GL/glext.h>
 #endif
 
+
 GLWidget::GLWidget(QWidget * parent/*= 0*/): QGLWidget(parent), texture(0),
-       textureWidth(0), textureHeight(0), buffer(0), rasterWidth(340), rasterHeight(240)
+       textureWidth(0), textureHeight(0), buffer(0), rasterWidth(340), rasterHeight(240),
+       offset(0)
 {
        // Screen pitch has to be the texture width (in 32-bit pixels)...
        JaguarSetScreenPitch(1024);
 }
 
+
 GLWidget::~GLWidget()
 {
-//     free(backbuffer);
+       if (buffer)
+               delete[] buffer;
 }
 
+
 void GLWidget::initializeGL()
 {
        format().setDoubleBuffer(true);
@@ -49,18 +55,29 @@ void GLWidget::initializeGL()
        glClearColor(0.0, 0.0, 0.0, 0.0);
 }
 
+
 void GLWidget::paintGL()
 {
 //kludge
 rasterHeight = (vjs.hardwareTypeNTSC ? VIRTUAL_SCREEN_HEIGHT_NTSC : VIRTUAL_SCREEN_HEIGHT_PAL);
 
-       unsigned outputWidth  = width();
+       // If we're in fullscreen mode, we take the value of the screen width as
+       // set by MainWin, since it may be wider than what our aspect ratio allows.
+       // In that case, we adjust the viewport over so that it's centered on the
+       // screen. Otherwise, we simply take the width from our width() funtion
+       // which will always be correct in windowed mode.
+
+//     unsigned outputWidth  = width();
+       if (!fullscreen)
+               outputWidth = width();
+
        unsigned outputHeight = height();
 
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, outputWidth, 0, outputHeight, -1.0, 1.0);
-       glViewport(0, 0, outputWidth, outputHeight);
+//     glViewport(0, 0, outputWidth, outputHeight);
+       glViewport(0 + offset, 0, outputWidth, outputHeight);
 
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
@@ -79,13 +96,21 @@ rasterHeight = (vjs.hardwareTypeNTSC ? VIRTUAL_SCREEN_HEIGHT_NTSC : VIRTUAL_SCRE
        unsigned v = outputHeight;
 
        glBegin(GL_TRIANGLE_STRIP);
+#if 1
        glTexCoord2f(0, 0); glVertex3i(0, v, 0);
        glTexCoord2f(w, 0); glVertex3i(u, v, 0);
        glTexCoord2f(0, h); glVertex3i(0, 0, 0);
        glTexCoord2f(w, h); glVertex3i(u, 0, 0);
+#else
+       glTexCoord2f(0, 0); glVertex3i(0 + offset, v, 0);
+       glTexCoord2f(w, 0); glVertex3i(u + offset, v, 0);
+       glTexCoord2f(0, h); glVertex3i(0 + offset, 0, 0);
+       glTexCoord2f(w, h); glVertex3i(u + offset, 0, 0);
+#endif
        glEnd();
 }
 
+
 void GLWidget::resizeGL(int width, int height)
 {
        if (width > textureWidth || height > textureHeight)
@@ -118,6 +143,7 @@ memset(buffer, 0xFF, textureWidth * textureHeight * sizeof(uint32_t));
        }
 }
 
+
 #if 0
 class RubyGLWidget: public QGLWidget
 {