Quellcode durchsuchen

Diagonal flipping with RenderCopyEx

Ivan Rubinson

As it turns out, it was impossible to render a texture flipped diagonally (both vertically and horizontally) with one RenderCopyEx call.
With help from #SDL @ freenode, we came up with a fix.
Sam Lantinga vor 11 Jahren
Ursprung
Commit
b36d98bd9c
2 geänderte Dateien mit 37 neuen und 29 gelöschten Zeilen
  1. 20 16
      src/render/direct3d/SDL_render_d3d.c
  2. 17 13
      src/render/opengl/SDL_render_gl.c

+ 20 - 16
src/render/direct3d/SDL_render_d3d.c

@@ -1635,22 +1635,26 @@ D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
     centerx = center->x;
     centery = center->y;
 
-    if (flip & SDL_FLIP_HORIZONTAL) {
-        minx = dstrect->w - centerx - 0.5f;
-        maxx = -centerx - 0.5f;
-    }
-    else {
-        minx = -centerx - 0.5f;
-        maxx = dstrect->w - centerx - 0.5f;
-    }
-
-    if (flip & SDL_FLIP_VERTICAL) {
-        miny = dstrect->h - centery - 0.5f;
-        maxy = -centery - 0.5f;
-    }
-    else {
-        miny = -centery - 0.5f;
-        maxy = dstrect->h - centery - 0.5f;
+    if ((flip & SDL_FLIP_VERTICAL) && (flip & SDL_FLIP_HORIZONTAL)) {
+        miny = dstrect->h - centery;
+        maxy = -centery;
+        minx = dstrect->w - centerx;
+        maxx = -centerx;
+    } else if (flip & SDL_FLIP_HORIZONTAL) {
+        miny = -centery;
+        maxy = dstrect->h - centery;
+        minx = dstrect->w - centerx;
+        maxx = -centerx;
+    } else if (flip & SDL_FLIP_VERTICAL) {
+        miny = dstrect->h - centery;
+        maxy = -centery;
+        minx = -centerx;
+        maxx = dstrect->w - centerx;
+    } else {
+        miny = -centery;
+        maxy = dstrect->h - centery;
+        minx = -centerx;
+        maxx = dstrect->w - centerx;
     }
 
     minu = (float) srcrect->x / texture->w;

+ 17 - 13
src/render/opengl/SDL_render_gl.c

@@ -1250,22 +1250,26 @@ GL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
     centerx = center->x;
     centery = center->y;
 
-    if (flip & SDL_FLIP_HORIZONTAL) {
-        minx =  dstrect->w - centerx;
+    if ((flip & SDL_FLIP_VERTICAL) && (flip & SDL_FLIP_HORIZONTAL)) {
+        miny = dstrect->h - centery;
+        maxy = -centery;
+        minx = dstrect->w - centerx;
         maxx = -centerx;
-    }
-    else {
-        minx = -centerx;
-        maxx =  dstrect->w - centerx;
-    }
-
-    if (flip & SDL_FLIP_VERTICAL) {
-        miny =  dstrect->h - centery;
+    } else if (flip & SDL_FLIP_HORIZONTAL) {
+        miny = -centery;
+        maxy = dstrect->h - centery;
+        minx = dstrect->w - centerx;
+        maxx = -centerx;
+    } else if (flip & SDL_FLIP_VERTICAL) {
+        miny = dstrect->h - centery;
         maxy = -centery;
-    }
-    else {
+        minx = -centerx;
+        maxx = dstrect->w - centerx;
+    } else {
         miny = -centery;
-        maxy =  dstrect->h - centery;
+        maxy = dstrect->h - centery;
+        minx = -centerx;
+        maxx = dstrect->w - centerx;
     }
 
     minu = (GLfloat) srcrect->x / texture->w;