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