hedgewars/uRender.pas
author sheepluva
Mon, 20 Jan 2014 10:16:29 +0100
changeset 10024 7d21f52f0452
parent 10020 67e127027af6
child 10040 4ac87acbaed9
permissions -rw-r--r--
remove DroidSans font from source dir. it is unused afaik and also wrongly included in the source tarballs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     1
(*
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     2
 * Hedgewars, a free turn based strategy game
9998
736015b847e3 update copyright to 2014
sheepluva
parents: 9792
diff changeset
     3
 * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     4
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     8
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    12
 * GNU General Public License for more details.
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    13
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    14
 * You should have received a copy of the GNU General Public License
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    15
 * along with this program; if not, write to the Free Software
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    17
 *)
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    18
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    19
{$INCLUDE "options.inc"}
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    20
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    21
unit uRender;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    22
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    23
interface
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    24
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5235
diff changeset
    25
uses SDLh, uTypes, GLunit, uConsts;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    26
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    27
procedure DrawSprite            (Sprite: TSprite; X, Y, Frame: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    28
procedure DrawSprite            (Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    29
procedure DrawSpriteFromRect    (Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline;
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    30
procedure DrawSpriteClipped     (Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    31
procedure DrawSpriteRotated     (Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    32
procedure DrawSpriteRotatedF    (Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
    33
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    34
procedure DrawTexture           (X, Y: LongInt; Texture: PTexture); inline;
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    35
procedure DrawTexture           (X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
10020
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
    36
procedure DrawTexture2          (X, Y: LongInt; Texture: PTexture; Scale, Overlap: GLfloat);
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    37
procedure DrawTextureFromRect   (X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    38
procedure DrawTextureFromRect   (X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    39
procedure DrawTextureFromRectDir(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture; Dir: LongInt);
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    40
procedure DrawTextureCentered   (X, Top: LongInt; Source: PTexture);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    41
procedure DrawTextureF          (Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    42
procedure DrawTextureRotated    (Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    43
procedure DrawTextureRotatedF   (Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
    44
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    45
procedure DrawCircle            (X, Y, Radius, Width: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    46
procedure DrawCircle            (X, Y, Radius, Width: LongInt; r, g, b, a: Byte);
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
    47
9557
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
    48
procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; color: LongWord); inline;
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    49
procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    50
procedure DrawFillRect          (r: TSDL_Rect);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    51
procedure DrawHedgehog          (X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    52
procedure DrawScreenWidget      (widget: POnScreenWidget);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    53
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    54
procedure Tint                  (r, g, b, a: Byte); inline;
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    55
procedure Tint                  (c: Longword); inline;
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
    56
procedure untint(); inline;
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
    57
procedure setTintAdd            (f: boolean); inline;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    58
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
    59
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    60
implementation
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    61
uses uVariables;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    62
8145
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
    63
{$IFDEF USE_TOUCH_INTERFACE}
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
    64
const
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
    65
    FADE_ANIM_TIME = 500;
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
    66
    MOVE_ANIM_TIME = 500;
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
    67
{$ENDIF}
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
    68
7028
0f60591f3a16 old typed const moved to their proper unit
koda
parents: 6999
diff changeset
    69
var LastTint: LongWord = 0;
0f60591f3a16 old typed const moved to their proper unit
koda
parents: 6999
diff changeset
    70
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    71
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    72
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    73
r.y:= r.y + Height * Position;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    74
r.h:= Height;
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    75
DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    76
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    77
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    78
procedure DrawTextureFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    79
begin
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    80
DrawTextureFromRectDir(X, Y, r^.w, r^.h, r, SourceTexture, 1)
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    81
end;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    82
procedure DrawTextureFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    83
begin
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    84
DrawTextureFromRectDir(X, Y, W, H, r, SourceTexture, 1)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    85
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    86
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    87
procedure DrawTextureFromRectDir(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture; Dir: LongInt);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    88
var rr: TSDL_Rect;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    89
    _l, _r, _t, _b: real;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    90
    VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    91
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
    92
if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
    93
    exit;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    94
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
    95
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    96
if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    97
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    98
if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) > cScreenHeight / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    99
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   100
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   101
rr.x:= X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   102
rr.y:= Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   103
rr.w:= W;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   104
rr.h:= H;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   105
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   106
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   107
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   108
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   109
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   110
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   111
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   112
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   113
if Dir < 0 then
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   114
    begin
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   115
    VertexBuffer[0].X:= X + rr.w/2;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   116
    VertexBuffer[0].Y:= Y;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   117
    VertexBuffer[1].X:= X - rr.w/2;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   118
    VertexBuffer[1].Y:= Y;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   119
    VertexBuffer[2].X:= X - rr.w/2;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   120
    VertexBuffer[2].Y:= rr.h + Y;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   121
    VertexBuffer[3].X:= X + rr.w/2;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   122
    VertexBuffer[3].Y:= rr.h + Y;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   123
    end
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   124
else
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   125
    begin
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   126
    VertexBuffer[0].X:= X;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   127
    VertexBuffer[0].Y:= Y;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   128
    VertexBuffer[1].X:= rr.w + X;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   129
    VertexBuffer[1].Y:= Y;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   130
    VertexBuffer[2].X:= rr.w + X;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   131
    VertexBuffer[2].Y:= rr.h + Y;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   132
    VertexBuffer[3].X:= X;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   133
    VertexBuffer[3].Y:= rr.h + Y;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   134
    end;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   135
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   136
TextureBuffer[0].X:= _l;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   137
TextureBuffer[0].Y:= _t;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   138
TextureBuffer[1].X:= _r;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   139
TextureBuffer[1].Y:= _t;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   140
TextureBuffer[2].X:= _r;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   141
TextureBuffer[2].Y:= _b;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   142
TextureBuffer[3].X:= _l;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   143
TextureBuffer[3].Y:= _b;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   144
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   145
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   146
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   147
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   148
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   149
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   150
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); inline;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   151
begin
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   152
    DrawTexture(X, Y, Texture, 1.0);
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   153
end;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   154
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   155
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   156
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   157
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   158
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   159
glTranslatef(X, Y, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   160
glScalef(Scale, Scale, 1);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   161
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   162
glBindTexture(GL_TEXTURE_2D, Texture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   163
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   164
glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   165
glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   166
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   167
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   168
glPopMatrix
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   169
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   170
10020
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   171
{ this contains tweaks in order to avoid land tile borders in blurry land mode }
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   172
procedure DrawTexture2(X, Y: LongInt; Texture: PTexture; Scale, Overlap: GLfloat);
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   173
var
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   174
    TextureBuffer: array [0..3] of TVertex2f;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   175
begin
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   176
glPushMatrix();
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   177
glTranslatef(X, Y, 0);
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   178
glScalef(Scale, Scale, 1);
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   179
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   180
glBindTexture(GL_TEXTURE_2D, Texture^.id);
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   181
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   182
TextureBuffer[0].X:= Texture^.tb[0].X + Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   183
TextureBuffer[0].Y:= Texture^.tb[0].Y + Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   184
TextureBuffer[1].X:= Texture^.tb[1].X - Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   185
TextureBuffer[1].Y:= Texture^.tb[1].Y + Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   186
TextureBuffer[2].X:= Texture^.tb[2].X - Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   187
TextureBuffer[2].Y:= Texture^.tb[2].Y - Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   188
TextureBuffer[3].X:= Texture^.tb[3].X + Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   189
TextureBuffer[3].Y:= Texture^.tb[3].Y - Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   190
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   191
glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb);
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   192
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer);
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   193
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   194
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   195
glPopMatrix();
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   196
end;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   197
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   198
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   199
begin
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   200
    DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   201
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   202
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   203
procedure DrawTextureRotatedF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   204
var ft, fb, fl, fr: GLfloat;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   205
    hw, nx, ny: LongInt;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   206
    VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   207
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   208
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   209
if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   210
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   211
if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   212
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   213
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   214
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   215
glTranslatef(X, Y, 0);
6323
c1aa6a3c84a7 Dir should not be 0, but set it to 1 if 0 in case I missed some other place this was done. Also correct cloud scaling.
nemo
parents: 6322
diff changeset
   216
if Dir = 0 then Dir:= 1;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   217
6323
c1aa6a3c84a7 Dir should not be 0, but set it to 1 if 0 in case I missed some other place this was done. Also correct cloud scaling.
nemo
parents: 6322
diff changeset
   218
glRotatef(Angle, 0, 0, Dir);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   219
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   220
glTranslatef(Dir*OffsetX, OffsetY, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   221
glScalef(Scale, Scale, 1);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   222
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   223
// Any reason for this call? And why only in t direction, not s?
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   224
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   225
6322
b310f0bc8dde If I'm going to be arbitrary about it, might as well go for the more minimal arbitrariness
nemo
parents: 6318
diff changeset
   226
hw:= w div (2 div Dir);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   227
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   228
nx:= round(Texture^.w / w); // number of horizontal frames
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   229
ny:= round(Texture^.h / h); // number of vertical frames
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   230
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   231
ft:= (Frame mod ny) * Texture^.ry / ny;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   232
fb:= ((Frame mod ny) + 1) * Texture^.ry / ny;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   233
fl:= (Frame div ny) * Texture^.rx / nx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   234
fr:= ((Frame div ny) + 1) * Texture^.rx / nx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   235
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   236
glBindTexture(GL_TEXTURE_2D, Texture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   237
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   238
VertexBuffer[0].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   239
VertexBuffer[0].Y:= w / -2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   240
VertexBuffer[1].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   241
VertexBuffer[1].Y:= w / -2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   242
VertexBuffer[2].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   243
VertexBuffer[2].Y:= w / 2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   244
VertexBuffer[3].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   245
VertexBuffer[3].Y:= w / 2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   246
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   247
TextureBuffer[0].X:= fl;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   248
TextureBuffer[0].Y:= ft;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   249
TextureBuffer[1].X:= fr;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   250
TextureBuffer[1].Y:= ft;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   251
TextureBuffer[2].X:= fr;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   252
TextureBuffer[2].Y:= fb;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   253
TextureBuffer[3].X:= fl;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   254
TextureBuffer[3].Y:= fb;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   255
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   256
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   257
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   258
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   259
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   260
glPopMatrix
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   261
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   262
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   263
procedure DrawSpriteRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   264
begin
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   265
    DrawTextureRotated(SpritesData[Sprite].Texture,
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   266
        SpritesData[Sprite].Width,
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   267
        SpritesData[Sprite].Height,
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   268
        X, Y, Dir, Angle)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   269
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   270
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   271
procedure DrawSpriteRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   272
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   273
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   274
glTranslatef(X, Y, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   275
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   276
if Dir < 0 then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   277
    glRotatef(Angle, 0, 0, -1)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   278
else
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   279
    glRotatef(Angle, 0, 0,  1);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   280
if Dir < 0 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   281
    glScalef(-1.0, 1.0, 1.0);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   282
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   283
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   284
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   285
glPopMatrix
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   286
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   287
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   288
procedure DrawTextureRotated(Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   289
var VertexBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   290
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   291
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   292
if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   293
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   294
if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   295
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   296
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   297
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   298
glTranslatef(X, Y, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   299
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   300
if Dir < 0 then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   301
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   302
    hw:= - hw;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   303
    glRotatef(Angle, 0, 0, -1);
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   304
    end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   305
else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   306
    glRotatef(Angle, 0, 0,  1);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   307
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   308
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   309
glBindTexture(GL_TEXTURE_2D, Texture^.id);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   310
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   311
VertexBuffer[0].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   312
VertexBuffer[0].Y:= -hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   313
VertexBuffer[1].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   314
VertexBuffer[1].Y:= -hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   315
VertexBuffer[2].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   316
VertexBuffer[2].Y:= hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   317
VertexBuffer[3].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   318
VertexBuffer[3].Y:= hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   319
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   320
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   321
glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   322
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   323
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   324
glPopMatrix
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   325
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   326
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   327
procedure DrawSprite(Sprite: TSprite; X, Y, Frame: LongInt);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   328
var row, col, numFramesFirstCol: LongInt;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   329
begin
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   330
    if SpritesData[Sprite].imageHeight = 0 then
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   331
        exit;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   332
    numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   333
    row:= Frame mod numFramesFirstCol;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   334
    col:= Frame div numFramesFirstCol;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   335
    DrawSprite(Sprite, X, Y, col, row);
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   336
end;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   337
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   338
procedure DrawSprite(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   339
var r: TSDL_Rect;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   340
begin
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   341
    r.x:= FrameX * SpritesData[Sprite].Width;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   342
    r.w:= SpritesData[Sprite].Width;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   343
    r.y:= FrameY * SpritesData[Sprite].Height;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   344
    r.h:= SpritesData[Sprite].Height;
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   345
    DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   346
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   347
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   348
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   349
var r: TSDL_Rect;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   350
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   351
r.x:= 0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   352
r.y:= 0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   353
r.w:= SpritesData[Sprite].Width;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   354
r.h:= SpritesData[Sprite].Height;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   355
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   356
if (X < LeftX) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   357
    r.x:= LeftX - X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   358
if (Y < TopY) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   359
    r.y:= TopY - Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   360
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   361
if (Y + SpritesData[Sprite].Height > BottomY) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   362
    r.h:= BottomY - Y + 1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   363
if (X + SpritesData[Sprite].Width > RightX) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   364
    r.w:= RightX - X + 1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   365
9792
59cde1e53ca5 This seems to be enough to fix the bug with sprGirder rendered in stripe
unc0rr
parents: 9666
diff changeset
   366
if (r.h < r.y) or (r.w < r.x) then 
59cde1e53ca5 This seems to be enough to fix the bug with sprGirder rendered in stripe
unc0rr
parents: 9666
diff changeset
   367
    exit;
59cde1e53ca5 This seems to be enough to fix the bug with sprGirder rendered in stripe
unc0rr
parents: 9666
diff changeset
   368
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   369
dec(r.h, r.y);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   370
dec(r.w, r.x);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   371
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   372
DrawTextureFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   373
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   374
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   375
procedure DrawTextureCentered(X, Top: LongInt; Source: PTexture);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   376
var scale: GLfloat;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   377
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   378
    if (Source^.w + 20) > cScreenWidth then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   379
        scale:= cScreenWidth / (Source^.w + 20)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   380
    else
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   381
        scale:= 1.0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   382
    DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   383
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   384
9557
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
   385
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; color: LongWord); inline;
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
   386
begin
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
   387
DrawLine(X0, Y0, X1, Y1, Width, (color shr 24) and $FF, (color shr 16) and $FF, (color shr 8) and $FF, color and $FF)
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
   388
end;
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
   389
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   390
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
8626
cfc44db21d72 Fix DrawLine bug
Urbertar@gmail.com
parents: 8560
diff changeset
   391
var VertexBuffer: array [0..1] of TVertex2f;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   392
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   393
    glDisable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   394
    glEnable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   395
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   396
    glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   397
    glTranslatef(WorldDx, WorldDy, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   398
    glLineWidth(Width);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   399
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   400
    Tint(r, g, b, a);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   401
    VertexBuffer[0].X:= X0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   402
    VertexBuffer[0].Y:= Y0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   403
    VertexBuffer[1].X:= X1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   404
    VertexBuffer[1].Y:= Y1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   405
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   406
    glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   407
    glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   408
    untint;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   409
    
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   410
    glPopMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   411
    
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   412
    glEnable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   413
    glDisable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   414
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   415
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   416
procedure DrawFillRect(r: TSDL_Rect);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   417
var VertexBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   418
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   419
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   420
if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) * cScaleFactor > cScreenWidth) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   421
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   422
if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) * cScaleFactor > cScreenHeight) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   423
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   424
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   425
glDisable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   426
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   427
Tint($00, $00, $00, $80);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   428
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   429
VertexBuffer[0].X:= r.x;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   430
VertexBuffer[0].Y:= r.y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   431
VertexBuffer[1].X:= r.x + r.w;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   432
VertexBuffer[1].Y:= r.y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   433
VertexBuffer[2].X:= r.x + r.w;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   434
VertexBuffer[2].Y:= r.y + r.h;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   435
VertexBuffer[3].X:= r.x;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   436
VertexBuffer[3].Y:= r.y + r.h;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   437
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   438
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   439
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   440
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   441
untint;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   442
glEnable(GL_TEXTURE_2D)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   443
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   444
4420
6be946bcd17a Add a visual gear for drawing circles. Intent is to allow specifying areas on map for lua scripts (such as to indicate a location to go to). Could also be used to, say, circle a hog in CTF. Also add a "Critical" flag for visual gears so a gear flagges as such will always be created.
nemo
parents: 4385
diff changeset
   445
procedure DrawCircle(X, Y, Radius, Width: LongInt; r, g, b, a: Byte); 
4451
1c342980b4aa trying to get tint to behave more as I expect. need to ask Smaxx what he intended here, to avoid too many pointless colour calls
nemo
parents: 4420
diff changeset
   446
begin
1c342980b4aa trying to get tint to behave more as I expect. need to ask Smaxx what he intended here, to avoid too many pointless colour calls
nemo
parents: 4420
diff changeset
   447
    Tint(r, g, b, a);
1c342980b4aa trying to get tint to behave more as I expect. need to ask Smaxx what he intended here, to avoid too many pointless colour calls
nemo
parents: 4420
diff changeset
   448
    DrawCircle(X, Y, Radius, Width); 
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   449
    untint;
4451
1c342980b4aa trying to get tint to behave more as I expect. need to ask Smaxx what he intended here, to avoid too many pointless colour calls
nemo
parents: 4420
diff changeset
   450
end;
1c342980b4aa trying to get tint to behave more as I expect. need to ask Smaxx what he intended here, to avoid too many pointless colour calls
nemo
parents: 4420
diff changeset
   451
1c342980b4aa trying to get tint to behave more as I expect. need to ask Smaxx what he intended here, to avoid too many pointless colour calls
nemo
parents: 4420
diff changeset
   452
procedure DrawCircle(X, Y, Radius, Width: LongInt); 
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   453
var
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   454
    i: LongInt;
5561
dfbe55237c64 Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents: 5559
diff changeset
   455
    CircleVertex: array [0..59] of TVertex2f;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   456
begin
5561
dfbe55237c64 Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents: 5559
diff changeset
   457
    for i := 0 to 59 do begin
dfbe55237c64 Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents: 5559
diff changeset
   458
        CircleVertex[i].X := X + Radius*cos(i*pi/30);
dfbe55237c64 Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents: 5559
diff changeset
   459
        CircleVertex[i].Y := Y + Radius*sin(i*pi/30);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   460
    end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   461
    glDisable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   462
    glEnable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   463
    glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   464
    glLineWidth(Width);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   465
    glVertexPointer(2, GL_FLOAT, 0, @CircleVertex[0]);
5561
dfbe55237c64 Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents: 5559
diff changeset
   466
    glDrawArrays(GL_LINE_LOOP, 0, 60);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   467
    glPopMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   468
    glEnable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   469
    glDisable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   470
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   471
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   472
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   473
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   474
const VertexBuffer: array [0..3] of TVertex2f = (
7069
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
   475
        (X: -16; Y: -16),
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
   476
        (X:  16; Y: -16),
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
   477
        (X:  16; Y:  16),
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
   478
        (X: -16; Y:  16));
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   479
var l, r, t, b: real;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   480
    TextureBuffer: array [0..3] of TVertex2f;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   481
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   482
    // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   483
    if (abs(X) > 32) and ((abs(X) - 16) * cScaleFactor > cScreenWidth) then
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   484
        exit;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   485
    if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) * cScaleFactor > cScreenHeight) then
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   486
        exit;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   487
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   488
    t:= Pos * 32 / HHTexture^.h;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   489
    b:= (Pos + 1) * 32 / HHTexture^.h;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   490
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   491
    if Dir = -1 then
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   492
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   493
        l:= (Step + 1) * 32 / HHTexture^.w;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   494
        r:= Step * 32 / HHTexture^.w
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   495
        end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   496
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   497
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   498
        l:= Step * 32 / HHTexture^.w;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   499
        r:= (Step + 1) * 32 / HHTexture^.w
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   500
    end;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   501
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   502
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   503
    glPushMatrix();
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   504
    glTranslatef(X, Y, 0);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   505
    glRotatef(Angle, 0, 0, 1);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   506
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   507
    glBindTexture(GL_TEXTURE_2D, HHTexture^.id);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   508
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   509
    TextureBuffer[0].X:= l;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   510
    TextureBuffer[0].Y:= t;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   511
    TextureBuffer[1].X:= r;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   512
    TextureBuffer[1].Y:= t;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   513
    TextureBuffer[2].X:= r;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   514
    TextureBuffer[2].Y:= b;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   515
    TextureBuffer[3].X:= l;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   516
    TextureBuffer[3].Y:= b;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   517
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   518
    glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   519
    glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   520
    glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   521
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   522
    glPopMatrix
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   523
end;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   524
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   525
procedure DrawScreenWidget(widget: POnScreenWidget);
6992
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
   526
{$IFDEF USE_TOUCH_INTERFACE}
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   527
var alpha: byte = $FF;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   528
begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   529
with widget^ do
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   530
    begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   531
    if (fadeAnimStart <> 0) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   532
        begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   533
        if RealTicks > (fadeAnimStart + FADE_ANIM_TIME) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   534
            fadeAnimStart:= 0
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   535
        else
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   536
            if show then 
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   537
                alpha:= Byte(trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF))
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   538
            else 
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   539
                alpha:= Byte($FF - trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF));
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   540
        end;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   541
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   542
    with moveAnim do
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   543
        if animate then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   544
            if RealTicks > (startTime + MOVE_ANIM_TIME) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   545
                begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   546
                startTime:= 0;
6710
42504695122d fixed the active region on widgets when they are animated, added active.x:= in uWorld too
Xeli
parents: 6700
diff changeset
   547
                animate:= false;
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
   548
                frame.x:= target.x;
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
   549
                frame.y:= target.y;
6710
42504695122d fixed the active region on widgets when they are animated, added active.x:= in uWorld too
Xeli
parents: 6700
diff changeset
   550
                active.x:= active.x + (target.x - source.x);
42504695122d fixed the active region on widgets when they are animated, added active.x:= in uWorld too
Xeli
parents: 6700
diff changeset
   551
                active.y:= active.y + (target.y - source.y);
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   552
                end
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   553
            else
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   554
                begin
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
   555
                frame.x:= source.x + Round((target.x - source.x) * ((RealTicks - startTime) / MOVE_ANIM_TIME));
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
   556
                frame.y:= source.y + Round((target.y - source.y) * ((RealTicks - startTime) / MOVE_ANIM_TIME));
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   557
                end;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   558
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   559
    if show or (fadeAnimStart <> 0) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   560
        begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   561
        Tint($FF, $FF, $FF, alpha);
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
   562
        DrawTexture(frame.x, frame.y, spritesData[sprite].Texture, buttonScale);
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   563
        untint;
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   564
        end;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   565
    end;
6992
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
   566
{$ELSE}
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
   567
begin
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
   568
widget:= widget; // avoid hint
6689
98a239848ba2 wops, added an extra USE_TOUCH_INTERFACE
Xeli
parents: 6688
diff changeset
   569
{$ENDIF}
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   570
end;
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   571
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   572
procedure Tint(r, g, b, a: Byte); inline;
6982
8d41d22a291d breaking news, we don't support typed consts anymore
koda
parents: 6710
diff changeset
   573
var nc, tw: Longword;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   574
begin
9557
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
   575
    nc:= (r shl 24) or (g shl 16) or (b shl 8) or a;
5559
a937d43a032f Use local scope global var instead
unc0rr
parents: 5441
diff changeset
   576
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   577
    if nc = lastTint then
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   578
        exit;
5559
a937d43a032f Use local scope global var instead
unc0rr
parents: 5441
diff changeset
   579
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   580
    if GrayScale then
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   581
        begin
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   582
        tw:= round(r * RGB_LUMINANCE_RED + g * RGB_LUMINANCE_GREEN + b * RGB_LUMINANCE_BLUE);
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   583
        if tw > 255 then
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   584
            tw:= 255;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   585
        r:= tw;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   586
        g:= tw;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   587
        b:= tw
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   588
        end;
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5235
diff changeset
   589
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   590
    glColor4ub(r, g, b, a);
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   591
    lastTint:= nc;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   592
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   593
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   594
procedure Tint(c: Longword); inline;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   595
begin
9557
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
   596
    if c = lastTint then exit;
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   597
    Tint(((c shr 24) and $FF), ((c shr 16) and $FF), (c shr 8) and $FF, (c and $FF))
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   598
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   599
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   600
procedure untint(); inline;
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   601
begin
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   602
    Tint($FF, $FF, $FF, $FF)
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   603
end;
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   604
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   605
procedure setTintAdd(f: boolean); inline;
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   606
begin
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   607
    if f then
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   608
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD)
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   609
    else
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   610
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   611
end;
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
   612
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   613
end.