hedgewars/uRender.pas
changeset 10266 a90a55ec5b98
parent 10255 fdc342ebdc31
child 10275 6c91047f59b6
equal deleted inserted replaced
10265:7e8d4cd76ce7 10266:a90a55ec5b98
    56 procedure Tint                  (r, g, b, a: Byte); inline;
    56 procedure Tint                  (r, g, b, a: Byte); inline;
    57 procedure Tint                  (c: Longword); inline;
    57 procedure Tint                  (c: Longword); inline;
    58 procedure untint(); inline;
    58 procedure untint(); inline;
    59 procedure setTintAdd            (f: boolean); inline;
    59 procedure setTintAdd            (f: boolean); inline;
    60 
    60 
       
    61 function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline;
       
    62 
       
    63 // 0 => not offscreen, <0 => left/top of screen >0 => right/below of screen
       
    64 function isDxAreaOffscreen(X, Width: LongInt): LongInt; inline;
       
    65 function isDyAreaOffscreen(Y, Height: LongInt): LongInt; inline;
       
    66 
    61 implementation
    67 implementation
    62 uses uVariables;
    68 uses uVariables;
    63 
    69 
    64 {$IFDEF USE_TOUCH_INTERFACE}
    70 {$IFDEF USE_TOUCH_INTERFACE}
    65 const
    71 const
    66     FADE_ANIM_TIME = 500;
    72     FADE_ANIM_TIME = 500;
    67     MOVE_ANIM_TIME = 500;
    73     MOVE_ANIM_TIME = 500;
    68 {$ENDIF}
    74 {$ENDIF}
    69 
    75 
    70 var LastTint: LongWord = 0;
    76 var LastTint: LongWord = 0;
       
    77 
       
    78 function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline;
       
    79 begin
       
    80     isAreaOffscreen:= (isDxAreaOffscreen(X, Width) <> 0) or (isDyAreaOffscreen(Y, Height) <> 0);
       
    81 end;
       
    82 
       
    83 function isDxAreaOffscreen(X, Width: LongInt): LongInt; inline;
       
    84 begin
       
    85     if X > ViewRightX then exit(1);
       
    86     if X + Width < ViewLeftX then exit(-1);
       
    87     isDxAreaOffscreen:= 0;
       
    88 end;
       
    89 
       
    90 function isDyAreaOffscreen(Y, Height: LongInt): LongInt; inline;
       
    91 begin
       
    92     if Y > ViewBottomY then exit(1);
       
    93     if Y + Height < ViewTopY then exit(-1);
       
    94     isDyAreaOffscreen:= 0;
       
    95 end;
    71 
    96 
    72 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline;
    97 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline;
    73 begin
    98 begin
    74 r.y:= r.y + Height * Position;
    99 r.y:= r.y + Height * Position;
    75 r.h:= Height;
   100 r.h:= Height;
   186 { this contains tweaks in order to avoid land tile borders in blurry land mode }
   211 { this contains tweaks in order to avoid land tile borders in blurry land mode }
   187 procedure DrawTexture2(X, Y: LongInt; Texture: PTexture; Scale, Overlap: GLfloat);
   212 procedure DrawTexture2(X, Y: LongInt; Texture: PTexture; Scale, Overlap: GLfloat);
   188 var
   213 var
   189     TextureBuffer: array [0..3] of TVertex2f;
   214     TextureBuffer: array [0..3] of TVertex2f;
   190 begin
   215 begin
   191 glPushMatrix();
   216 {$IFDEF GL2}
       
   217 hglPushMatrix;
       
   218 hglTranslatef(X, Y, 0);
       
   219 hglScalef(Scale, Scale, 1);
       
   220 {$ELSE}
       
   221 glPushMatrix;
   192 glTranslatef(X, Y, 0);
   222 glTranslatef(X, Y, 0);
   193 glScalef(Scale, Scale, 1);
   223 glScalef(Scale, Scale, 1);
       
   224 {$ENDIF}
   194 
   225 
   195 glBindTexture(GL_TEXTURE_2D, Texture^.id);
   226 glBindTexture(GL_TEXTURE_2D, Texture^.id);
   196 
   227 
   197 TextureBuffer[0].X:= Texture^.tb[0].X + Overlap;
   228 TextureBuffer[0].X:= Texture^.tb[0].X + Overlap;
   198 TextureBuffer[0].Y:= Texture^.tb[0].Y + Overlap;
   229 TextureBuffer[0].Y:= Texture^.tb[0].Y + Overlap;
   201 TextureBuffer[2].X:= Texture^.tb[2].X - Overlap;
   232 TextureBuffer[2].X:= Texture^.tb[2].X - Overlap;
   202 TextureBuffer[2].Y:= Texture^.tb[2].Y - Overlap;
   233 TextureBuffer[2].Y:= Texture^.tb[2].Y - Overlap;
   203 TextureBuffer[3].X:= Texture^.tb[3].X + Overlap;
   234 TextureBuffer[3].X:= Texture^.tb[3].X + Overlap;
   204 TextureBuffer[3].Y:= Texture^.tb[3].Y - Overlap;
   235 TextureBuffer[3].Y:= Texture^.tb[3].Y - Overlap;
   205 
   236 
   206 glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb);
   237 SetVertexPointer(@Texture^.vb, Length(Texture^.vb));
   207 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer);
   238 SetTexCoordPointer(@TextureBuffer, Length(Texture^.vb));
       
   239 
       
   240 {$IFDEF GL2}
       
   241 UpdateModelviewProjection;
   208 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
   242 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
   209 
   243 hglPopMatrix;
   210 glPopMatrix();
   244 {$ELSE}
       
   245 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
       
   246 glPopMatrix;
       
   247 {$ENDIF}
   211 end;
   248 end;
   212 
   249 
   213 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
   250 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
   214 begin
   251 begin
   215     DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
   252     DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)