hedgewars/uRender.pas
author unc0rr
Fri, 27 Apr 2012 00:43:48 +0400
changeset 6934 14a230552c2e
parent 6710 42504695122d
child 6982 8d41d22a291d
permissions -rw-r--r--
Cursor for DrawMapScene. Feel free to ajust its look.
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
6700
e04da46ee43c the most important commit of the year
koda
parents: 6695
diff changeset
     3
 * Copyright (c) 2004-2012 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
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    27
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    28
procedure DrawFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    29
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    30
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    31
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    32
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    33
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat = 1.0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    34
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    35
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    36
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    37
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    38
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    39
procedure DrawCentered(X, Top: LongInt; Source: PTexture);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    40
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    41
procedure DrawFillRect(r: TSDL_Rect);
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
    42
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
    43
procedure DrawCircle(X, Y, Radius, Width: LongInt);
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
    44
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
    45
procedure DrawScreenWidget(widget: POnScreenWidget);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    46
procedure Tint(r, g, b, a: Byte); inline;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    47
procedure Tint(c: Longword); inline;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    48
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
    49
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    50
implementation
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    51
uses uVariables;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    52
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    53
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    54
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    55
r.y:= r.y + Height * Position;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    56
r.h:= Height;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    57
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    58
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    59
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    60
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    61
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    62
DrawFromRect(X, Y, r^.w, r^.h, r, SourceTexture)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    63
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    64
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    65
procedure DrawFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    66
var rr: TSDL_Rect;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    67
    _l, _r, _t, _b: real;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    68
    VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    69
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
    70
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
    71
    exit;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    72
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
    73
// 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
    74
if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    75
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    76
if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) > cScreenHeight / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    77
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    78
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    79
rr.x:= X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    80
rr.y:= Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    81
rr.w:= W;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    82
rr.h:= H;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    83
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    84
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    85
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    86
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    87
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    88
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    89
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    90
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    91
VertexBuffer[0].X:= X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    92
VertexBuffer[0].Y:= Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    93
VertexBuffer[1].X:= rr.w + X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    94
VertexBuffer[1].Y:= Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    95
VertexBuffer[2].X:= rr.w + X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    96
VertexBuffer[2].Y:= rr.h + Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    97
VertexBuffer[3].X:= X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    98
VertexBuffer[3].Y:= rr.h + Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    99
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   100
TextureBuffer[0].X:= _l;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   101
TextureBuffer[0].Y:= _t;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   102
TextureBuffer[1].X:= _r;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   103
TextureBuffer[1].Y:= _t;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   104
TextureBuffer[2].X:= _r;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   105
TextureBuffer[2].Y:= _b;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   106
TextureBuffer[3].X:= _l;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   107
TextureBuffer[3].Y:= _b;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   108
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   109
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   110
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   111
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   112
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   113
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   114
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   115
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   116
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   117
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   118
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   119
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   120
glTranslatef(X, Y, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   121
glScalef(Scale, Scale, 1);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   122
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   123
glBindTexture(GL_TEXTURE_2D, Texture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   124
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   125
glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   126
glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   127
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   128
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   129
glPopMatrix
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   130
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   131
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   132
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   133
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   134
    DrawRotatedTextureF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   135
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   136
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   137
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   138
var ft, fb, fl, fr: GLfloat;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   139
    hw, nx, ny: LongInt;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   140
    VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   141
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   142
// 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
   143
if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   144
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   145
if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   146
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   147
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   148
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   149
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
   150
if Dir = 0 then Dir:= 1;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   151
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
   152
glRotatef(Angle, 0, 0, Dir);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   153
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   154
glTranslatef(Dir*OffsetX, OffsetY, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   155
glScalef(Scale, Scale, 1);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   156
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   157
// Any reason for this call? And why only in t direction, not s?
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   158
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   159
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
   160
hw:= w div (2 div Dir);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   161
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   162
nx:= round(Texture^.w / w); // number of horizontal frames
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   163
ny:= round(Texture^.h / h); // number of vertical frames
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   164
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   165
ft:= (Frame mod ny) * Texture^.ry / ny;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   166
fb:= ((Frame mod ny) + 1) * Texture^.ry / ny;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   167
fl:= (Frame div ny) * Texture^.rx / nx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   168
fr:= ((Frame div ny) + 1) * Texture^.rx / nx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   169
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   170
glBindTexture(GL_TEXTURE_2D, Texture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   171
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   172
VertexBuffer[0].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   173
VertexBuffer[0].Y:= w / -2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   174
VertexBuffer[1].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   175
VertexBuffer[1].Y:= w / -2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   176
VertexBuffer[2].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   177
VertexBuffer[2].Y:= w / 2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   178
VertexBuffer[3].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   179
VertexBuffer[3].Y:= w / 2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   180
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   181
TextureBuffer[0].X:= fl;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   182
TextureBuffer[0].Y:= ft;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   183
TextureBuffer[1].X:= fr;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   184
TextureBuffer[1].Y:= ft;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   185
TextureBuffer[2].X:= fr;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   186
TextureBuffer[2].Y:= fb;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   187
TextureBuffer[3].X:= fl;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   188
TextureBuffer[3].Y:= fb;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   189
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   190
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   191
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   192
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   193
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   194
glPopMatrix
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   195
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   196
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   197
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   198
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   199
    DrawRotatedTex(SpritesData[Sprite].Texture,
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   200
        SpritesData[Sprite].Width,
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   201
        SpritesData[Sprite].Height,
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   202
        X, Y, Dir, Angle)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   203
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   204
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   205
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   206
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   207
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   208
glTranslatef(X, Y, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   209
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   210
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
   211
    glRotatef(Angle, 0, 0, -1)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   212
else
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   213
    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
   214
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
   215
    glScalef(-1.0, 1.0, 1.0);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   216
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   217
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   218
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   219
glPopMatrix
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   220
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   221
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   222
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   223
var VertexBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   224
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   225
// 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
   226
if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   227
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   228
if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   229
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   230
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   231
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   232
glTranslatef(X, Y, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   233
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   234
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
   235
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   236
    hw:= - hw;
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   237
    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
   238
    end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   239
else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   240
    glRotatef(Angle, 0, 0,  1);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   241
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   242
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   243
glBindTexture(GL_TEXTURE_2D, Tex^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   244
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   245
VertexBuffer[0].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   246
VertexBuffer[0].Y:= -hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   247
VertexBuffer[1].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   248
VertexBuffer[1].Y:= -hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   249
VertexBuffer[2].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   250
VertexBuffer[2].Y:= hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   251
VertexBuffer[3].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   252
VertexBuffer[3].Y:= hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   253
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   254
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   255
glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   256
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   257
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   258
glPopMatrix
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   259
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   260
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   261
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   262
var row, col, numFramesFirstCol: LongInt;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   263
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   264
if SpritesData[Sprite].imageHeight = 0 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   265
    exit;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   266
numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   267
row:= Frame mod numFramesFirstCol;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   268
col:= Frame div numFramesFirstCol;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   269
DrawSprite2 (Sprite, X, Y, col, row);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   270
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   271
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   272
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   273
var r: TSDL_Rect;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   274
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   275
r.x:= 0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   276
r.y:= 0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   277
r.w:= SpritesData[Sprite].Width;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   278
r.h:= SpritesData[Sprite].Height;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   279
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   280
if (X < LeftX) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   281
    r.x:= LeftX - X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   282
if (Y < TopY) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   283
    r.y:= TopY - Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   284
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   285
if (Y + SpritesData[Sprite].Height > BottomY) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   286
    r.h:= BottomY - Y + 1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   287
if (X + SpritesData[Sprite].Width > RightX) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   288
    r.w:= RightX - X + 1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   289
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   290
dec(r.h, r.y);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   291
dec(r.w, r.x);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   292
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   293
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   294
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   295
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   296
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   297
var r: TSDL_Rect;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   298
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   299
    r.x:= FrameX * SpritesData[Sprite].Width;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   300
    r.w:= SpritesData[Sprite].Width;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   301
    r.y:= FrameY * SpritesData[Sprite].Height;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   302
    r.h:= SpritesData[Sprite].Height;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   303
    DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   304
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   305
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   306
procedure DrawCentered(X, Top: LongInt; Source: PTexture);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   307
var scale: GLfloat;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   308
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   309
    if (Source^.w + 20) > cScreenWidth then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   310
        scale:= cScreenWidth / (Source^.w + 20)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   311
    else
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   312
        scale:= 1.0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   313
    DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   314
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   315
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   316
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   317
var VertexBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   318
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   319
    glDisable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   320
    glEnable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   321
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   322
    glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   323
    glTranslatef(WorldDx, WorldDy, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   324
    glLineWidth(Width);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   325
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   326
    Tint(r, g, b, a);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   327
    VertexBuffer[0].X:= X0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   328
    VertexBuffer[0].Y:= Y0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   329
    VertexBuffer[1].X:= X1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   330
    VertexBuffer[1].Y:= Y1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   331
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   332
    glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   333
    glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   334
    Tint($FF, $FF, $FF, $FF);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   335
    
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   336
    glPopMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   337
    
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   338
    glEnable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   339
    glDisable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   340
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   341
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   342
procedure DrawFillRect(r: TSDL_Rect);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   343
var VertexBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   344
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   345
// 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
   346
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
   347
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   348
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
   349
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   350
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   351
glDisable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   352
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   353
Tint($00, $00, $00, $80);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   354
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   355
VertexBuffer[0].X:= r.x;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   356
VertexBuffer[0].Y:= r.y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   357
VertexBuffer[1].X:= r.x + r.w;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   358
VertexBuffer[1].Y:= r.y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   359
VertexBuffer[2].X:= r.x + r.w;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   360
VertexBuffer[2].Y:= r.y + r.h;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   361
VertexBuffer[3].X:= r.x;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   362
VertexBuffer[3].Y:= r.y + r.h;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   363
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   364
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   365
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   366
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   367
Tint($FF, $FF, $FF, $FF);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   368
glEnable(GL_TEXTURE_2D)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   369
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   370
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
   371
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
   372
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
   373
    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
   374
    DrawCircle(X, Y, Radius, Width); 
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
   375
    Tint($FF, $FF, $FF, $FF);
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
   376
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
   377
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
   378
procedure DrawCircle(X, Y, Radius, Width: LongInt); 
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   379
var
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   380
    i: LongInt;
5561
dfbe55237c64 Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents: 5559
diff changeset
   381
    CircleVertex: array [0..59] of TVertex2f;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   382
begin
5561
dfbe55237c64 Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents: 5559
diff changeset
   383
    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
   384
        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
   385
        CircleVertex[i].Y := Y + Radius*sin(i*pi/30);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   386
    end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   387
    glDisable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   388
    glEnable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   389
    glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   390
    glLineWidth(Width);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   391
    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
   392
    glDrawArrays(GL_LINE_LOOP, 0, 60);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   393
    glPopMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   394
    glEnable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   395
    glDisable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   396
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   397
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   398
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   399
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   400
const VertexBuffer: array [0..3] of TVertex2f = (
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   401
        (x: -16; y: -16),
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   402
        (x:  16; y: -16),
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   403
        (x:  16; y:  16),
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   404
        (x: -16; y:  16));
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   405
var l, r, t, b: real;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   406
    TextureBuffer: array [0..3] of TVertex2f;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   407
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   408
    // 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
   409
    if (abs(X) > 32) and ((abs(X) - 16) * cScaleFactor > cScreenWidth) then
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   410
        exit;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   411
    if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) * cScaleFactor > cScreenHeight) then
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   412
        exit;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   413
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   414
    t:= Pos * 32 / HHTexture^.h;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   415
    b:= (Pos + 1) * 32 / HHTexture^.h;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   416
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   417
    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
   418
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   419
        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
   420
        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
   421
        end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   422
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   423
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   424
        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
   425
        r:= (Step + 1) * 32 / HHTexture^.w
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   426
    end;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   427
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   428
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   429
    glPushMatrix();
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   430
    glTranslatef(X, Y, 0);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   431
    glRotatef(Angle, 0, 0, 1);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   432
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   433
    glBindTexture(GL_TEXTURE_2D, HHTexture^.id);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   434
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   435
    TextureBuffer[0].X:= l;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   436
    TextureBuffer[0].Y:= t;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   437
    TextureBuffer[1].X:= r;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   438
    TextureBuffer[1].Y:= t;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   439
    TextureBuffer[2].X:= r;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   440
    TextureBuffer[2].Y:= b;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   441
    TextureBuffer[3].X:= l;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   442
    TextureBuffer[3].Y:= b;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   443
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   444
    glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   445
    glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   446
    glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   447
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   448
    glPopMatrix
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   449
end;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   450
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   451
procedure DrawScreenWidget(widget: POnScreenWidget);
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   452
var alpha: byte = $FF;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   453
begin
6689
98a239848ba2 wops, added an extra USE_TOUCH_INTERFACE
Xeli
parents: 6688
diff changeset
   454
{$IFDEF USE_TOUCH_INTERFACE}
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   455
with widget^ do
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   456
    begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   457
    if (fadeAnimStart <> 0) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   458
        begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   459
        if RealTicks > (fadeAnimStart + FADE_ANIM_TIME) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   460
            fadeAnimStart:= 0
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   461
        else
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   462
            if show then 
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   463
                alpha:= Byte(trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF))
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   464
            else 
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   465
                alpha:= Byte($FF - trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF));
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   466
        end;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   467
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   468
    with moveAnim do
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   469
        if animate then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   470
            if RealTicks > (startTime + MOVE_ANIM_TIME) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   471
                begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   472
                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
   473
                animate:= false;
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
   474
                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
   475
                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
   476
                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
   477
                active.y:= active.y + (target.y - source.y);
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   478
                end
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   479
            else
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   480
                begin
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
   481
                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
   482
                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
   483
                end;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   484
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   485
    if show or (fadeAnimStart <> 0) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   486
        begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   487
        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
   488
        DrawTexture(frame.x, frame.y, spritesData[sprite].Texture, buttonScale);
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   489
        Tint($FF, $FF, $FF, $FF);
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   490
        end;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   491
    end;
6689
98a239848ba2 wops, added an extra USE_TOUCH_INTERFACE
Xeli
parents: 6688
diff changeset
   492
{$ENDIF}
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   493
end;
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   494
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   495
procedure Tint(r, g, b, a: Byte); inline;
5559
a937d43a032f Use local scope global var instead
unc0rr
parents: 5441
diff changeset
   496
const 
a937d43a032f Use local scope global var instead
unc0rr
parents: 5441
diff changeset
   497
    lastTint: Longword = 0;
a937d43a032f Use local scope global var instead
unc0rr
parents: 5441
diff changeset
   498
var 
a937d43a032f Use local scope global var instead
unc0rr
parents: 5441
diff changeset
   499
    nc, tw: Longword;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   500
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   501
nc:= (a shl 24) or (b shl 16) or (g shl 8) or r;
5559
a937d43a032f Use local scope global var instead
unc0rr
parents: 5441
diff changeset
   502
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   503
if nc = lastTint then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   504
    exit;
5559
a937d43a032f Use local scope global var instead
unc0rr
parents: 5441
diff changeset
   505
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5235
diff changeset
   506
if cGrayScale then
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5235
diff changeset
   507
    begin
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5235
diff changeset
   508
    tw:= round(r * RGB_LUMINANCE_RED + g * RGB_LUMINANCE_GREEN + b * RGB_LUMINANCE_BLUE);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   509
    if tw > 255 then
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   510
        tw:= 255;
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5235
diff changeset
   511
    r:= tw;
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5235
diff changeset
   512
    g:= tw;
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5235
diff changeset
   513
    b:= tw
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5235
diff changeset
   514
    end;
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5235
diff changeset
   515
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   516
glColor4ub(r, g, b, a);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   517
lastTint:= nc;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   518
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   519
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   520
procedure Tint(c: Longword); inline;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   521
begin
4452
258945553b18 make Tint(longword) use RGBA
nemo
parents: 4451
diff changeset
   522
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
   523
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   524
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   525
end.