hedgewars/uRender.pas
author nemo
Thu, 02 Dec 2010 20:29:46 -0500
changeset 4452 258945553b18
parent 4451 1c342980b4aa
child 4976 088d40d8aba2
permissions -rw-r--r--
make Tint(longword) use RGBA
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
     1
{$INCLUDE "options.inc"}
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
     2
unit uRender;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
     3
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
     4
interface
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
     5
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
     6
uses SDLh, uTypes, GLunit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
     7
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
     8
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
     9
procedure DrawFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    10
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    11
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    12
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    13
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    14
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat = 1.0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    15
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    16
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    17
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    18
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    19
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    20
procedure DrawCentered(X, Top: LongInt; Source: PTexture);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    21
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    22
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
    23
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
    24
procedure DrawCircle(X, Y, Radius, Width: LongInt);
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
    25
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    26
procedure Tint(r, g, b, a: Byte); inline;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    27
procedure Tint(c: Longword); inline;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    28
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
    29
var
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
    30
    HHTexture: PTexture;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
    31
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    32
implementation
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    33
uses uVariables;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    34
var
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    35
    lastTint: Longword;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    36
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    37
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    38
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    39
r.y:= r.y + Height * Position;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    40
r.h:= Height;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    41
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    42
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    43
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    44
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    45
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    46
DrawFromRect(X, Y, r^.w, r^.h, r, SourceTexture)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    47
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    48
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    49
procedure DrawFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    50
var rr: TSDL_Rect;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    51
    _l, _r, _t, _b: real;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    52
    VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    53
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    54
if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    55
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    56
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    57
if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    58
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    59
if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) > cScreenHeight / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    60
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    61
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    62
rr.x:= X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    63
rr.y:= Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    64
rr.w:= W;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    65
rr.h:= H;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    66
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    67
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    68
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    69
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    70
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    71
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    72
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    73
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    74
VertexBuffer[0].X:= X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    75
VertexBuffer[0].Y:= Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    76
VertexBuffer[1].X:= rr.w + X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    77
VertexBuffer[1].Y:= Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    78
VertexBuffer[2].X:= rr.w + X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    79
VertexBuffer[2].Y:= rr.h + Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    80
VertexBuffer[3].X:= X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    81
VertexBuffer[3].Y:= rr.h + Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    82
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    83
TextureBuffer[0].X:= _l;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    84
TextureBuffer[0].Y:= _t;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    85
TextureBuffer[1].X:= _r;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    86
TextureBuffer[1].Y:= _t;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    87
TextureBuffer[2].X:= _r;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    88
TextureBuffer[2].Y:= _b;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    89
TextureBuffer[3].X:= _l;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    90
TextureBuffer[3].Y:= _b;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    91
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    92
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    93
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    94
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    95
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    96
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    97
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    98
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    99
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   100
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   101
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   102
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   103
glTranslatef(X, Y, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   104
glScalef(Scale, Scale, 1);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   105
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   106
glBindTexture(GL_TEXTURE_2D, Texture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   107
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   108
glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   109
glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   110
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   111
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   112
glPopMatrix
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
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   116
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   117
    DrawRotatedTextureF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   118
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   119
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   120
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   121
var ft, fb, fl, fr: GLfloat;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   122
    hw, nx, ny: LongInt;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   123
    VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   124
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   125
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   126
if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   127
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   128
if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   129
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   130
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   131
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   132
glTranslatef(X, Y, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   133
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   134
if Dir < 0 then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   135
   glRotatef(Angle, 0, 0, -1)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   136
else
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   137
   glRotatef(Angle, 0, 0,  1);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   138
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   139
glTranslatef(Dir*OffsetX, OffsetY, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   140
glScalef(Scale, Scale, 1);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   141
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   142
// Any reason for this call? And why only in t direction, not s?
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   143
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   144
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   145
if Dir < 0 then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   146
    hw:= w div -2
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   147
else
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   148
    hw:= w div 2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   149
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   150
nx:= round(Texture^.w / w); // number of horizontal frames
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   151
ny:= round(Texture^.h / h); // number of vertical frames
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   152
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   153
ft:= (Frame mod ny) * Texture^.ry / ny;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   154
fb:= ((Frame mod ny) + 1) * Texture^.ry / ny;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   155
fl:= (Frame div ny) * Texture^.rx / nx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   156
fr:= ((Frame div ny) + 1) * Texture^.rx / nx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   157
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   158
glBindTexture(GL_TEXTURE_2D, Texture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   159
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   160
VertexBuffer[0].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   161
VertexBuffer[0].Y:= w / -2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   162
VertexBuffer[1].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   163
VertexBuffer[1].Y:= w / -2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   164
VertexBuffer[2].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   165
VertexBuffer[2].Y:= w / 2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   166
VertexBuffer[3].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   167
VertexBuffer[3].Y:= w / 2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   168
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   169
TextureBuffer[0].X:= fl;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   170
TextureBuffer[0].Y:= ft;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   171
TextureBuffer[1].X:= fr;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   172
TextureBuffer[1].Y:= ft;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   173
TextureBuffer[2].X:= fr;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   174
TextureBuffer[2].Y:= fb;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   175
TextureBuffer[3].X:= fl;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   176
TextureBuffer[3].Y:= fb;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   177
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   178
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   179
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   180
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   181
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   182
glPopMatrix
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   183
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   184
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   185
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   186
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   187
    DrawRotatedTex(SpritesData[Sprite].Texture,
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   188
        SpritesData[Sprite].Width,
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   189
        SpritesData[Sprite].Height,
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   190
        X, Y, Dir, Angle)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   191
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   192
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   193
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   194
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   195
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   196
glTranslatef(X, Y, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   197
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   198
if Dir < 0 then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   199
   glRotatef(Angle, 0, 0, -1)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   200
else
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   201
   glRotatef(Angle, 0, 0,  1);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   202
if Dir < 0 then glScalef(-1.0, 1.0, 1.0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   203
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   204
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   205
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   206
glPopMatrix
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   207
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   208
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   209
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   210
var VertexBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   211
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   212
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   213
if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   214
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   215
if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   216
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   217
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   218
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   219
glTranslatef(X, Y, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   220
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   221
if Dir < 0 then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   222
   begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   223
   hw:= - hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   224
   glRotatef(Angle, 0, 0, -1);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   225
   end else
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   226
   glRotatef(Angle, 0, 0,  1);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   227
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   228
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   229
glBindTexture(GL_TEXTURE_2D, Tex^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   230
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   231
VertexBuffer[0].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   232
VertexBuffer[0].Y:= -hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   233
VertexBuffer[1].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   234
VertexBuffer[1].Y:= -hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   235
VertexBuffer[2].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   236
VertexBuffer[2].Y:= hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   237
VertexBuffer[3].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   238
VertexBuffer[3].Y:= hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   239
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   240
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   241
glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   242
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   243
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   244
glPopMatrix
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   245
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   246
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   247
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   248
var row, col, numFramesFirstCol: LongInt;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   249
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   250
numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   251
row:= Frame mod numFramesFirstCol;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   252
col:= Frame div numFramesFirstCol;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   253
DrawSprite2 (Sprite, X, Y, col, row);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   254
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   255
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   256
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   257
var r: TSDL_Rect;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   258
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   259
r.x:= 0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   260
r.y:= 0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   261
r.w:= SpritesData[Sprite].Width;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   262
r.h:= SpritesData[Sprite].Height;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   263
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   264
if (X < LeftX) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   265
    r.x:= LeftX - X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   266
if (Y < TopY) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   267
    r.y:= TopY - Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   268
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   269
if (Y + SpritesData[Sprite].Height > BottomY) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   270
    r.h:= BottomY - Y + 1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   271
if (X + SpritesData[Sprite].Width > RightX) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   272
    r.w:= RightX - X + 1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   273
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   274
dec(r.h, r.y);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   275
dec(r.w, r.x);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   276
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   277
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   278
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   279
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   280
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   281
var r: TSDL_Rect;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   282
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   283
    r.x:= FrameX * SpritesData[Sprite].Width;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   284
    r.w:= SpritesData[Sprite].Width;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   285
    r.y:= FrameY * SpritesData[Sprite].Height;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   286
    r.h:= SpritesData[Sprite].Height;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   287
    DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   288
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   289
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   290
procedure DrawCentered(X, Top: LongInt; Source: PTexture);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   291
var scale: GLfloat;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   292
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   293
    if (Source^.w + 20) > cScreenWidth then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   294
        scale:= cScreenWidth / (Source^.w + 20)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   295
    else
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   296
        scale:= 1.0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   297
    DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   298
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   299
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   300
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   301
var VertexBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   302
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   303
    glDisable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   304
    glEnable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   305
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   306
    glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   307
    glTranslatef(WorldDx, WorldDy, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   308
    glLineWidth(Width);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   309
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   310
    Tint(r, g, b, a);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   311
    VertexBuffer[0].X:= X0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   312
    VertexBuffer[0].Y:= Y0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   313
    VertexBuffer[1].X:= X1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   314
    VertexBuffer[1].Y:= Y1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   315
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   316
    glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   317
    glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   318
    Tint($FF, $FF, $FF, $FF);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   319
    
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   320
    glPopMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   321
    
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   322
    glEnable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   323
    glDisable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   324
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   325
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   326
procedure DrawFillRect(r: TSDL_Rect);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   327
var VertexBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   328
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   329
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   330
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
   331
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   332
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
   333
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   334
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   335
glDisable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   336
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   337
Tint($00, $00, $00, $80);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   338
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   339
VertexBuffer[0].X:= r.x;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   340
VertexBuffer[0].Y:= r.y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   341
VertexBuffer[1].X:= r.x + r.w;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   342
VertexBuffer[1].Y:= r.y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   343
VertexBuffer[2].X:= r.x + r.w;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   344
VertexBuffer[2].Y:= r.y + r.h;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   345
VertexBuffer[3].X:= r.x;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   346
VertexBuffer[3].Y:= r.y + r.h;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   347
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   348
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   349
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   350
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   351
Tint($FF, $FF, $FF, $FF);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   352
glEnable(GL_TEXTURE_2D)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   353
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   354
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
   355
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
   356
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
   357
    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
   358
    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
   359
    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
   360
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
   361
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
   362
procedure DrawCircle(X, Y, Radius, Width: LongInt); 
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   363
var
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   364
    i: LongInt;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   365
    CircleVertex: array [0..359] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   366
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   367
    for i := 0 to 359 do begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   368
        CircleVertex[i].X := X + Radius*cos(i*pi/180);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   369
        CircleVertex[i].Y := Y + Radius*sin(i*pi/180);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   370
    end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   371
    glDisable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   372
    glEnable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   373
    glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   374
    glLineWidth(Width);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   375
    glVertexPointer(2, GL_FLOAT, 0, @CircleVertex[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   376
    glDrawArrays(GL_LINE_LOOP, 0, 360);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   377
    glPopMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   378
    glEnable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   379
    glDisable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   380
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   381
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   382
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   383
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   384
const VertexBuffer: array [0..3] of TVertex2f = (
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   385
        (x: -16; y: -16),
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   386
        (x:  16; y: -16),
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   387
        (x:  16; y:  16),
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   388
        (x: -16; y:  16));
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   389
var l, r, t, b: real;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   390
    TextureBuffer: array [0..3] of TVertex2f;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   391
begin
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   392
    // don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   393
    if (abs(X) > 32) and ((abs(X) - 16) * cScaleFactor > cScreenWidth) then
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   394
        exit;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   395
    if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) * cScaleFactor > cScreenHeight) then
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   396
        exit;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   397
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   398
    t:= Pos * 32 / HHTexture^.h;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   399
    b:= (Pos + 1) * 32 / HHTexture^.h;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   400
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   401
    if Dir = -1 then
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   402
    begin
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   403
    l:= (Step + 1) * 32 / HHTexture^.w;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   404
    r:= Step * 32 / HHTexture^.w
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   405
    end else
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   406
    begin
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   407
    l:= Step * 32 / HHTexture^.w;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   408
    r:= (Step + 1) * 32 / HHTexture^.w
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   409
    end;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   410
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   411
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   412
    glPushMatrix();
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   413
    glTranslatef(X, Y, 0);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   414
    glRotatef(Angle, 0, 0, 1);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   415
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   416
    glBindTexture(GL_TEXTURE_2D, HHTexture^.id);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   417
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   418
    TextureBuffer[0].X:= l;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   419
    TextureBuffer[0].Y:= t;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   420
    TextureBuffer[1].X:= r;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   421
    TextureBuffer[1].Y:= t;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   422
    TextureBuffer[2].X:= r;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   423
    TextureBuffer[2].Y:= b;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   424
    TextureBuffer[3].X:= l;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   425
    TextureBuffer[3].Y:= b;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   426
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   427
    glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   428
    glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   429
    glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   430
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   431
    glPopMatrix
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   432
end;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   433
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   434
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   435
procedure Tint(r, g, b, a: Byte); inline;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   436
var nc: Longword;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   437
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   438
nc:= (a shl 24) or (b shl 16) or (g shl 8) or r;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   439
if nc = lastTint then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   440
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   441
glColor4ub(r, g, b, a);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   442
lastTint:= nc;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   443
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   444
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   445
procedure Tint(c: Longword); inline;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   446
begin
4452
258945553b18 make Tint(longword) use RGBA
nemo
parents: 4451
diff changeset
   447
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
   448
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   449
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   450
end.