hedgewars/uStore.pas
changeset 3764 eb91c02f2d84
parent 3757 ad2f669c8435
child 3765 ebfe7c9b3085
--- a/hedgewars/uStore.pas	Tue Aug 24 13:24:37 2010 +0200
+++ b/hedgewars/uStore.pas	Tue Aug 24 17:03:44 2010 +0200
@@ -493,6 +493,13 @@
     VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
 begin
 if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit;
+
+// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
+if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then
+    exit;
+if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) > cScreenHeight / cScaleFactor) then
+    exit;
+
 rr.x:= X;
 rr.y:= Y;
 rr.w:= W;
@@ -531,6 +538,7 @@
 
 procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
 begin
+
 glPushMatrix;
 glTranslatef(X, Y, 0);
 glScalef(Scale, Scale, 1);
@@ -554,6 +562,12 @@
     hw, nx, ny: LongInt;
     VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
 begin
+// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
+if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) > cScreenWidth / cScaleFactor) then
+    exit;
+if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) > cScreenHeight / cScaleFactor) then
+    exit;
+
 glPushMatrix;
 glTranslatef(X, Y, 0);
 
@@ -635,6 +649,12 @@
 procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
 var VertexBuffer: array [0..3] of TVertex2f;
 begin
+// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
+if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then
+    exit;
+if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then
+    exit;
+
 glPushMatrix;
 glTranslatef(X, Y, 0);
 
@@ -728,6 +748,11 @@
 var l, r, t, b: real;
     TextureBuffer: array [0..3] of TVertex2f;
 begin
+// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
+if (abs(X) > 32) and ((abs(X) - 16)> cScreenWidth / cScaleFactor) then
+    exit;
+if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) > cScreenHeight / cScaleFactor) then
+    exit;
 
 t:= Pos * 32 / HHTexture^.h;
 b:= (Pos + 1) * 32 / HHTexture^.h;
@@ -768,6 +793,12 @@
 procedure DrawFillRect(r: TSDL_Rect);
 var VertexBuffer: array [0..3] of TVertex2f;
 begin
+// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
+if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) > cScreenWidth / cScaleFactor) then
+    exit;
+if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) > cScreenHeight / cScaleFactor) then
+    exit;
+
 glDisable(GL_TEXTURE_2D);
 
 Tint($00, $00, $00, $80);