Better fix for bug 2207 - SDL_RenderSetViewport behavior is different/incorrect on OpenGL renderer vs DirectX renderer
authorSam Lantinga <slouken@libsdl.org>
Fri, 15 Nov 2013 22:07:35 -0800
changeset 7995 0eed14683885
parent 7994 37c48b4ecb0c
child 7996 be1526907541
Better fix for bug 2207 - SDL_RenderSetViewport behavior is different/incorrect on OpenGL renderer vs DirectX renderer At least, it works better here on my Mac. :)
src/render/opengl/SDL_render_gl.c
--- a/src/render/opengl/SDL_render_gl.c	Fri Nov 15 22:05:26 2013 -0800
+++ b/src/render/opengl/SDL_render_gl.c	Fri Nov 15 22:07:35 2013 -0800
@@ -919,13 +919,21 @@
         return 0;
     }
 
-    data->glViewport(renderer->viewport.x, renderer->viewport.y,
-                     renderer->viewport.w, renderer->viewport.h);
+    if (renderer->target) {
+        data->glViewport(renderer->viewport.x, renderer->viewport.y,
+                         renderer->viewport.w, renderer->viewport.h);
+    } else {
+        int w, h;
+
+        SDL_GetRendererOutputSize(renderer, &w, &h);
+        data->glViewport(renderer->viewport.x, (h - renderer->viewport.y - renderer->viewport.h),
+                         renderer->viewport.w, renderer->viewport.h);
+    }
 
     data->glMatrixMode(GL_PROJECTION);
     data->glLoadIdentity();
     if (renderer->viewport.w && renderer->viewport.h) {
-        if (!renderer->target) {
+        if (renderer->target) {
             data->glOrtho((GLdouble) 0,
                           (GLdouble) renderer->viewport.w,
                           (GLdouble) 0,