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