DEADSOFTWARE

gl: fix big texture flip on hardware with texture size limits
[d2df-sdl.git] / src / game / renders / opengl / r_draw.pas
index cd0c58fb3e5c2aace4d792c3e52d4ba1fae8ed88..9db91836645d5460279debd7a4937a1ab3471bb9 100644 (file)
@@ -76,7 +76,8 @@ implementation
     glOrtho(0, w, h, 0, 0, 1);
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity;
-//    glTranslatef(0.5, 0.5, 0);
+    glEnable(GL_SCISSOR_TEST);
+    r_Draw_SetRect(0, 0, w - 1, h - 1);
   end;
 
   procedure DrawQuad (x, y, w, h: Integer);
@@ -126,7 +127,7 @@ implementation
   end;
 
   procedure r_Draw_Texture (img: TGLTexture; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean);
-    var i, j, offx, offy: Integer; n: TGLAtlasNode;
+    var i, j, first, last, step: Integer; n: TGLAtlasNode;
   begin
     ASSERT(w >= 0);
     ASSERT(h >= 0);
@@ -134,24 +135,25 @@ implementation
       DrawTile(nil, x, y, w, h, flip, NTR, NTB, NTG, NTA, blend)
     else
     begin
-      offx := 0;
-      offy := 0;
+      if flip then first := img.cols - 1 else first := 0;
+      if flip then last  := -1           else last  := img.cols;
+      if flip then step  := -1           else step  := +1;
+      glPushMatrix;
+      glTranslatef(x, y, 0);
+      glScalef(w / img.width, h / img.height, 1);
       for j := 0 to img.lines - 1 do
       begin
-        for i := 0 to img.cols - 1 do
-        begin
+        i := first;
+        repeat
           n := img.GetTile(i, j);
           ASSERT(n <> nil);
-          glPushMatrix;
-          glTranslatef(x + offx, y + offy, 0);
-          glScalef(w / img.width, h / img.height, 1);
           DrawTile(n, 0, 0, n.width, n.height, flip, r, g, b, a, blend);
-          glPopMatrix;
-          offx := offx + n.width;
-        end;
-        offx := 0;
-        offy := offy + n.height;
+          glTranslatef(n.width, 0, 0);
+          i := i + step;
+        until i = last;
+        glTranslatef(-img.width, n.height, 0);
       end;
+      glPopMatrix;
     end
   end;
 
@@ -271,10 +273,16 @@ implementation
       glVertex2i(r, b);
       glVertex2i(l, b);
 }
+{
       glVertex2f(l + 0.5, t + 0.5);
       glVertex2f(r - 0.5, t + 0.5);
       glVertex2f(r - 0.5, b - 0.5);
       glVertex2f(l + 0.5, b - 0.5);
+}
+      glVertex2f(l + 0, t + 0);
+      glVertex2f(r + 0.75, t + 0);
+      glVertex2f(r + 0.75, b + 0.75);
+      glVertex2f(l + 0, b + 0.75);
     glEnd;
   end;