hedgewars/uRender.pas
author Michael Hartman <omh1280@gmail.com>
Sun, 30 Dec 2012 09:23:30 -0500
branchwebgl
changeset 8334 abb48dd39e26
parent 8330 aaefa587e277
child 8833 c13ebed437cb
permissions -rw-r--r--
Added shaders and -GL2 option
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     1
(*
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     2
 * Hedgewars, a free turn based strategy game
6700
e04da46ee43c the most important commit of the year
koda
parents: 6695
diff changeset
     3
 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     4
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     8
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    12
 * GNU General Public License for more details.
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    13
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    14
 * You should have received a copy of the GNU General Public License
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    15
 * along with this program; if not, write to the Free Software
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    17
 *)
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    18
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    19
{$INCLUDE "options.inc"}
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
    20
{$IF GLunit = GL}{$DEFINE GLunit:=GL,GLext}{$ENDIF}
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4452
diff changeset
    21
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    22
unit uRender;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    23
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    24
interface
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    25
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
    26
uses SDLh, uTypes, GLunit, uConsts, uStore, uMatrix;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    27
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    28
procedure DrawSprite            (Sprite: TSprite; X, Y, Frame: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    29
procedure DrawSprite            (Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    30
procedure DrawSpriteFromRect    (Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    31
procedure DrawSpriteClipped     (Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    32
procedure DrawSpriteRotated     (Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    33
procedure DrawSpriteRotatedF    (Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
    34
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    35
procedure DrawTexture           (X, Y: LongInt; Texture: PTexture); inline;
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    36
procedure DrawTexture           (X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    37
procedure DrawTextureFromRect   (X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    38
procedure DrawTextureFromRect   (X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    39
procedure DrawTextureCentered   (X, Top: LongInt; Source: PTexture);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    40
procedure DrawTextureF          (Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    41
procedure DrawTextureRotated    (Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    42
procedure DrawTextureRotatedF   (Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
    43
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    44
procedure DrawCircle            (X, Y, Radius, Width: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    45
procedure DrawCircle            (X, Y, Radius, Width: LongInt; r, g, b, a: Byte);
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
    46
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    47
procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    48
procedure DrawFillRect          (r: TSDL_Rect);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    49
procedure DrawHedgehog          (X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    50
procedure DrawScreenWidget      (widget: POnScreenWidget);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    51
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    52
procedure Tint                  (r, g, b, a: Byte); inline;
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    53
procedure Tint                  (c: Longword); inline;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    54
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    55
implementation
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    56
uses uVariables;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    57
8145
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
    58
{$IFDEF USE_TOUCH_INTERFACE}
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
    59
const
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
    60
    FADE_ANIM_TIME = 500;
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
    61
    MOVE_ANIM_TIME = 500;
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
    62
{$ENDIF}
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
    63
7028
0f60591f3a16 old typed const moved to their proper unit
koda
parents: 6999
diff changeset
    64
var LastTint: LongWord = 0;
0f60591f3a16 old typed const moved to their proper unit
koda
parents: 6999
diff changeset
    65
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    66
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    67
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    68
r.y:= r.y + Height * Position;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    69
r.h:= Height;
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    70
DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    71
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    72
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    73
procedure DrawTextureFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    74
begin
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    75
DrawTextureFromRect(X, Y, r^.w, r^.h, r, SourceTexture)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    76
end;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
    77
{
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    78
procedure DrawTextureFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    79
var rr: TSDL_Rect;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    80
    _l, _r, _t, _b: real;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    81
    VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    82
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
    83
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
    84
    exit;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    85
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
    86
// 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
    87
if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    88
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    89
if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) > cScreenHeight / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    90
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    91
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    92
rr.x:= X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    93
rr.y:= Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    94
rr.w:= W;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    95
rr.h:= H;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    96
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    97
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    98
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    99
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   100
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   101
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   102
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   103
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   104
VertexBuffer[0].X:= X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   105
VertexBuffer[0].Y:= Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   106
VertexBuffer[1].X:= rr.w + X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   107
VertexBuffer[1].Y:= Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   108
VertexBuffer[2].X:= rr.w + X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   109
VertexBuffer[2].Y:= rr.h + Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   110
VertexBuffer[3].X:= X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   111
VertexBuffer[3].Y:= rr.h + Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   112
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   113
TextureBuffer[0].X:= _l;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   114
TextureBuffer[0].Y:= _t;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   115
TextureBuffer[1].X:= _r;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   116
TextureBuffer[1].Y:= _t;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   117
TextureBuffer[2].X:= _r;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   118
TextureBuffer[2].Y:= _b;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   119
TextureBuffer[3].X:= _l;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   120
TextureBuffer[3].Y:= _b;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   121
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   122
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   123
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   124
glDrawArrays(GL_TRIANGLE_FAN, 0, High(VertexBuffer) - Low(VertexBuffer) + 1);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   125
end;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   126
}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   127
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   128
procedure DrawTextureFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
   129
var
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   130
    rr: TSDL_Rect;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   131
    VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   132
    //VertexBuffer, TextureBuffer: TVertexRect;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   133
    _l, _r, _t, _b: GLfloat;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   134
begin
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   135
if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   136
    exit;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   137
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   138
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   139
if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   140
    exit;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   141
if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) > cScreenHeight / cScaleFactor) then
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   142
    exit;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   143
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   144
rr.x:= X;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   145
rr.y:= Y;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   146
rr.w:= W;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   147
rr.h:= H;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   148
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   149
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   150
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   151
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   152
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   153
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   154
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   155
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   156
VertexBuffer[0].X:= X;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   157
VertexBuffer[0].Y:= Y;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   158
VertexBuffer[1].X:= rr.w + X;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   159
VertexBuffer[1].Y:= Y;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   160
VertexBuffer[2].X:= rr.w + X;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   161
VertexBuffer[2].Y:= rr.h + Y;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   162
VertexBuffer[3].X:= X;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   163
VertexBuffer[3].Y:= rr.h + Y;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   164
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   165
TextureBuffer[0].X:= _l;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   166
TextureBuffer[0].Y:= _t;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   167
TextureBuffer[1].X:= _r;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   168
TextureBuffer[1].Y:= _t;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   169
TextureBuffer[2].X:= _r;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   170
TextureBuffer[2].Y:= _b;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   171
TextureBuffer[3].X:= _l;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   172
TextureBuffer[3].Y:= _b;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   173
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   174
SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   175
SetTexCoordPointer(@TextureBuffer[0], Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   176
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   177
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   178
UpdateModelviewProjection;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   179
{$ENDIF}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   180
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   181
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   182
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   183
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   184
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); inline;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   185
begin
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   186
    DrawTexture(X, Y, Texture, 1.0);
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   187
end;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   188
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   189
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   190
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   191
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   192
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   193
hglPushMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   194
hglTranslatef(X, Y, 0);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   195
hglScalef(Scale, Scale, 1);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   196
{$ELSE}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   197
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   198
glTranslatef(X, Y, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   199
glScalef(Scale, Scale, 1);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   200
{$ENDIF}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   201
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   202
glBindTexture(GL_TEXTURE_2D, Texture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   203
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   204
SetVertexPointer(@Texture^.vb, Length(Texture^.vb));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   205
SetTexCoordPointer(@Texture^.tb, Length(Texture^.vb));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   206
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   207
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   208
UpdateModelviewProjection;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   209
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   210
hglPopMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   211
{$ELSE}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   212
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   213
glPopMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   214
{$ENDIF}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   215
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   216
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   217
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   218
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   219
begin
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   220
    DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   221
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   222
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   223
procedure DrawTextureRotatedF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   224
var ft, fb, fl, fr: GLfloat;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   225
    hw, nx, ny: LongInt;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   226
    VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   227
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   228
// 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
   229
if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   230
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   231
if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   232
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   233
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   234
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   235
hglPushMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   236
hglTranslatef(X, Y, 0);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   237
{$ELSE}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   238
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   239
glTranslatef(X, Y, 0);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   240
{$ENDIF}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   241
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
   242
if Dir = 0 then Dir:= 1;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   243
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   244
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   245
hglRotatef(Angle, 0, 0, Dir);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   246
hglTranslatef(Dir*OffsetX, OffsetY, 0);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   247
hglScalef(Scale, Scale, 1);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   248
{$ELSE}
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
   249
glRotatef(Angle, 0, 0, Dir);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   250
glTranslatef(Dir*OffsetX, OffsetY, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   251
glScalef(Scale, Scale, 1);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   252
{$ENDIF}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   253
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   254
// Any reason for this call? And why only in t direction, not s?
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   255
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   256
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
   257
hw:= w div (2 div Dir);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   258
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   259
nx:= round(Texture^.w / w); // number of horizontal frames
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   260
ny:= round(Texture^.h / h); // number of vertical frames
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   261
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   262
ft:= (Frame mod ny) * Texture^.ry / ny;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   263
fb:= ((Frame mod ny) + 1) * Texture^.ry / ny;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   264
fl:= (Frame div ny) * Texture^.rx / nx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   265
fr:= ((Frame div ny) + 1) * Texture^.rx / nx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   266
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   267
glBindTexture(GL_TEXTURE_2D, Texture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   268
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   269
VertexBuffer[0].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   270
VertexBuffer[0].Y:= w / -2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   271
VertexBuffer[1].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   272
VertexBuffer[1].Y:= w / -2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   273
VertexBuffer[2].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   274
VertexBuffer[2].Y:= w / 2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   275
VertexBuffer[3].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   276
VertexBuffer[3].Y:= w / 2;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   277
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   278
TextureBuffer[0].X:= fl;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   279
TextureBuffer[0].Y:= ft;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   280
TextureBuffer[1].X:= fr;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   281
TextureBuffer[1].Y:= ft;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   282
TextureBuffer[2].X:= fr;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   283
TextureBuffer[2].Y:= fb;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   284
TextureBuffer[3].X:= fl;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   285
TextureBuffer[3].Y:= fb;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   286
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   287
SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   288
SetTexCoordPointer(@TextureBuffer[0], Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   289
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   290
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   291
UpdateModelviewProjection;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   292
{$ENDIF}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   293
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   294
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   295
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   296
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   297
hglPopMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   298
{$ELSE}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   299
glPopMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   300
{$ENDIF}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   301
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   302
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   303
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   304
procedure DrawSpriteRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   305
begin
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   306
    DrawTextureRotated(SpritesData[Sprite].Texture,
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   307
        SpritesData[Sprite].Width,
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   308
        SpritesData[Sprite].Height,
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   309
        X, Y, Dir, Angle)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   310
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   311
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   312
procedure DrawSpriteRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   313
begin
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   314
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   315
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   316
hglPushMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   317
hglTranslatef(X, Y, 0);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   318
{$ELSE}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   319
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   320
glTranslatef(X, Y, 0);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   321
{$ENDIF}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   322
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   323
if Dir < 0 then
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   324
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   325
    hglRotatef(Angle, 0, 0, -1)
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   326
{$ELSE}
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   327
    glRotatef(Angle, 0, 0, -1)
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   328
{$ENDIF}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   329
else
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   330
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   331
    hglRotatef(Angle, 0, 0,  1);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   332
{$ELSE}
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   333
    glRotatef(Angle, 0, 0,  1);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   334
{$ENDIF}
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   335
if Dir < 0 then
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   336
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   337
    hglScalef(-1.0, 1.0, 1.0);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   338
{$ELSE}
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   339
    glScalef(-1.0, 1.0, 1.0);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   340
{$ENDIF}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   341
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   342
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   343
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   344
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   345
hglPopMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   346
{$ELSE}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   347
glPopMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   348
{$ENDIF}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   349
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   350
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   351
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   352
procedure DrawTextureRotated(Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   353
var VertexBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   354
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   355
// 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
   356
if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   357
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   358
if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   359
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   360
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   361
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   362
hglPushMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   363
hglTranslatef(X, Y, 0);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   364
{$ELSE}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   365
glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   366
glTranslatef(X, Y, 0);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   367
{$ENDIF}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   368
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   369
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
   370
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   371
    hw:= - hw;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   372
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   373
    hglRotatef(Angle, 0, 0, -1);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   374
{$ELSE}
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   375
    glRotatef(Angle, 0, 0, -1);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   376
{$ENDIF}
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   377
    end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   378
else
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   379
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   380
    hglRotatef(Angle, 0, 0,  1);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   381
{$ELSE}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   382
    glRotatef(Angle, 0, 0, 1);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   383
{$ENDIF}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   384
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   385
glBindTexture(GL_TEXTURE_2D, Texture^.id);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   386
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   387
VertexBuffer[0].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   388
VertexBuffer[0].Y:= -hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   389
VertexBuffer[1].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   390
VertexBuffer[1].Y:= -hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   391
VertexBuffer[2].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   392
VertexBuffer[2].Y:= hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   393
VertexBuffer[3].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   394
VertexBuffer[3].Y:= hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   395
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   396
SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   397
SetTexCoordPointer(@Texture^.tb, Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   398
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   399
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   400
UpdateModelviewProjection;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   401
{$ENDIF}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   402
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   403
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   404
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   405
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   406
hglPopMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   407
{$ELSE}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   408
glPopMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   409
{$ENDIF}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   410
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   411
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   412
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   413
procedure DrawSprite(Sprite: TSprite; X, Y, Frame: LongInt);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   414
var row, col, numFramesFirstCol: LongInt;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   415
begin
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   416
    if SpritesData[Sprite].imageHeight = 0 then
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   417
        exit;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   418
    numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   419
    row:= Frame mod numFramesFirstCol;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   420
    col:= Frame div numFramesFirstCol;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   421
    DrawSprite(Sprite, X, Y, col, row);
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   422
end;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   423
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   424
procedure DrawSprite(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   425
var r: TSDL_Rect;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   426
begin
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   427
    r.x:= FrameX * SpritesData[Sprite].Width;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   428
    r.w:= SpritesData[Sprite].Width;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   429
    r.y:= FrameY * SpritesData[Sprite].Height;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   430
    r.h:= SpritesData[Sprite].Height;
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   431
    DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   432
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   433
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   434
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   435
var r: TSDL_Rect;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   436
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   437
r.x:= 0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   438
r.y:= 0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   439
r.w:= SpritesData[Sprite].Width;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   440
r.h:= SpritesData[Sprite].Height;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   441
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   442
if (X < LeftX) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   443
    r.x:= LeftX - X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   444
if (Y < TopY) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   445
    r.y:= TopY - Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   446
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   447
if (Y + SpritesData[Sprite].Height > BottomY) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   448
    r.h:= BottomY - Y + 1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   449
if (X + SpritesData[Sprite].Width > RightX) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   450
    r.w:= RightX - X + 1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   451
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   452
dec(r.h, r.y);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   453
dec(r.w, r.x);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   454
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   455
DrawTextureFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   456
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   457
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   458
procedure DrawTextureCentered(X, Top: LongInt; Source: PTexture);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   459
var scale: GLfloat;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   460
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   461
    if (Source^.w + 20) > cScreenWidth then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   462
        scale:= cScreenWidth / (Source^.w + 20)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   463
    else
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   464
        scale:= 1.0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   465
    DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   466
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   467
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   468
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   469
var VertexBuffer: array [0..1] of TVertex2f;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   470
begin
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   471
    glEnable(GL_LINE_SMOOTH);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   472
{$IFNDEF GL2}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   473
    glDisable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   474
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   475
    glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   476
    glTranslatef(WorldDx, WorldDy, 0);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   477
    glLineWidth(Width);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   478
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   479
    Tint(r, g, b, a);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   480
    VertexBuffer[0].X:= X0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   481
    VertexBuffer[0].Y:= Y0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   482
    VertexBuffer[1].X:= X1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   483
    VertexBuffer[1].Y:= Y1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   484
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   485
    SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   486
    glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   487
    Tint($FF, $FF, $FF, $FF);
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
   488
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   489
    glPopMatrix;
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
   490
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   491
    glEnable(GL_TEXTURE_2D);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   492
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   493
{$ELSE}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   494
    EnableTexture(False);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   495
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   496
    hglPushMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   497
    hglTranslatef(WorldDx, WorldDy, 0);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   498
    glLineWidth(Width);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   499
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   500
    UpdateModelviewProjection;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   501
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   502
    Tint(r, g, b, a);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   503
    VertexBuffer[0].X:= X0;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   504
    VertexBuffer[0].Y:= Y0;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   505
    VertexBuffer[1].X:= X1;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   506
    VertexBuffer[1].Y:= Y1;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   507
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   508
    SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   509
    glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   510
    Tint($FF, $FF, $FF, $FF);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   511
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   512
    hglPopMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   513
    EnableTexture(True);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   514
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   515
{$ENDIF}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   516
    glDisable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   517
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   518
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   519
procedure DrawFillRect(r: TSDL_Rect);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   520
var VertexBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   521
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   522
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   523
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   524
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
   525
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   526
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
   527
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   528
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   529
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   530
EnableTexture(False);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   531
{$ELSE}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   532
glDisable(GL_TEXTURE_2D);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   533
{$ENDIF}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   534
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   535
Tint($00, $00, $00, $80);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   536
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   537
VertexBuffer[0].X:= r.x;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   538
VertexBuffer[0].Y:= r.y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   539
VertexBuffer[1].X:= r.x + r.w;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   540
VertexBuffer[1].Y:= r.y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   541
VertexBuffer[2].X:= r.x + r.w;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   542
VertexBuffer[2].Y:= r.y + r.h;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   543
VertexBuffer[3].X:= r.x;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   544
VertexBuffer[3].Y:= r.y + r.h;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   545
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   546
SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   547
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   548
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   549
Tint($FF, $FF, $FF, $FF);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   550
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   551
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   552
EnableTexture(True);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   553
{$ELSE}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   554
glEnable(GL_TEXTURE_2D)
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   555
{$ENDIF}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   556
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   557
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   558
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
   559
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
   560
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
   561
    Tint(r, g, b, a);
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
   562
    DrawCircle(X, Y, Radius, Width);
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
   563
    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
   564
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
   565
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
   566
procedure DrawCircle(X, Y, Radius, Width: LongInt);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   567
var
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   568
    i: LongInt;
5561
dfbe55237c64 Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents: 5559
diff changeset
   569
    CircleVertex: array [0..59] of TVertex2f;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   570
begin
5561
dfbe55237c64 Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents: 5559
diff changeset
   571
    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
   572
        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
   573
        CircleVertex[i].Y := Y + Radius*sin(i*pi/30);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   574
    end;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   575
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   576
{$IFNDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   577
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   578
    glDisable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   579
    glEnable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   580
    glPushMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   581
    glLineWidth(Width);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   582
    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
   583
    glDrawArrays(GL_LINE_LOOP, 0, 60);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   584
    glPopMatrix;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   585
    glEnable(GL_TEXTURE_2D);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   586
    glDisable(GL_LINE_SMOOTH);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   587
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   588
{$ELSE}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   589
    EnableTexture(False);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   590
    glEnable(GL_LINE_SMOOTH);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   591
    hglPushMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   592
    glLineWidth(Width);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   593
    SetVertexPointer(@CircleVertex[0], 60);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   594
    glDrawArrays(GL_LINE_LOOP, 0, 60);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   595
    hglPopMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   596
    EnableTexture(True);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   597
    glDisable(GL_LINE_SMOOTH);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   598
{$ENDIF}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   599
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   600
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   601
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   602
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   603
const VertexBuffer: array [0..3] of TVertex2f = (
7069
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
   604
        (X: -16; Y: -16),
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
   605
        (X:  16; Y: -16),
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
   606
        (X:  16; Y:  16),
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
   607
        (X: -16; Y:  16));
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   608
var l, r, t, b: real;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   609
    TextureBuffer: array [0..3] of TVertex2f;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   610
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   611
    // 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
   612
    if (abs(X) > 32) and ((abs(X) - 16) * cScaleFactor > cScreenWidth) then
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   613
        exit;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   614
    if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) * cScaleFactor > cScreenHeight) then
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   615
        exit;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   616
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   617
    t:= Pos * 32 / HHTexture^.h;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   618
    b:= (Pos + 1) * 32 / HHTexture^.h;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   619
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   620
    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
   621
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   622
        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
   623
        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
   624
        end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   625
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   626
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   627
        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
   628
        r:= (Step + 1) * 32 / HHTexture^.w
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   629
    end;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   630
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   631
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   632
    hglPushMatrix();
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   633
    hglTranslatef(X, Y, 0);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   634
    hglRotatef(Angle, 0, 0, 1);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   635
{$ELSE}
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   636
    glPushMatrix();
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   637
    glTranslatef(X, Y, 0);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   638
    glRotatef(Angle, 0, 0, 1);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   639
{$ENDIF}
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   640
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   641
    glBindTexture(GL_TEXTURE_2D, HHTexture^.id);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   642
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   643
    TextureBuffer[0].X:= l;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   644
    TextureBuffer[0].Y:= t;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   645
    TextureBuffer[1].X:= r;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   646
    TextureBuffer[1].Y:= t;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   647
    TextureBuffer[2].X:= r;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   648
    TextureBuffer[2].Y:= b;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   649
    TextureBuffer[3].X:= l;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   650
    TextureBuffer[3].Y:= b;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   651
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   652
    SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   653
    SetTexCoordPointer(@TextureBuffer[0], Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   654
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   655
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   656
    UpdateModelviewProjection;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   657
{$ENDIF}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   658
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   659
    glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   660
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   661
{$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   662
    hglPopMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   663
{$ELSE}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   664
    glPopMatrix;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   665
{$ENDIF}
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   666
end;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   667
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   668
procedure DrawScreenWidget(widget: POnScreenWidget);
6992
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
   669
{$IFDEF USE_TOUCH_INTERFACE}
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   670
var alpha: byte = $FF;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   671
begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   672
with widget^ do
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   673
    begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   674
    if (fadeAnimStart <> 0) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   675
        begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   676
        if RealTicks > (fadeAnimStart + FADE_ANIM_TIME) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   677
            fadeAnimStart:= 0
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   678
        else
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
   679
            if show then
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   680
                alpha:= Byte(trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF))
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
   681
            else
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   682
                alpha:= Byte($FF - trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF));
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   683
        end;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   684
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   685
    with moveAnim do
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   686
        if animate then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   687
            if RealTicks > (startTime + MOVE_ANIM_TIME) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   688
                begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   689
                startTime:= 0;
6710
42504695122d fixed the active region on widgets when they are animated, added active.x:= in uWorld too
Xeli
parents: 6700
diff changeset
   690
                animate:= false;
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
   691
                frame.x:= target.x;
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
   692
                frame.y:= target.y;
6710
42504695122d fixed the active region on widgets when they are animated, added active.x:= in uWorld too
Xeli
parents: 6700
diff changeset
   693
                active.x:= active.x + (target.x - source.x);
42504695122d fixed the active region on widgets when they are animated, added active.x:= in uWorld too
Xeli
parents: 6700
diff changeset
   694
                active.y:= active.y + (target.y - source.y);
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   695
                end
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   696
            else
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   697
                begin
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
   698
                frame.x:= source.x + Round((target.x - source.x) * ((RealTicks - startTime) / MOVE_ANIM_TIME));
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
   699
                frame.y:= source.y + Round((target.y - source.y) * ((RealTicks - startTime) / MOVE_ANIM_TIME));
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   700
                end;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   701
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   702
    if show or (fadeAnimStart <> 0) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   703
        begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   704
        Tint($FF, $FF, $FF, alpha);
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
   705
        DrawTexture(frame.x, frame.y, spritesData[sprite].Texture, buttonScale);
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   706
        Tint($FF, $FF, $FF, $FF);
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   707
        end;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   708
    end;
6992
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
   709
{$ELSE}
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
   710
begin
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   711
{widget:= widget; // avoid hint}
6689
98a239848ba2 wops, added an extra USE_TOUCH_INTERFACE
Xeli
parents: 6688
diff changeset
   712
{$ENDIF}
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
   713
end;
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
   714
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   715
procedure Tint(r, g, b, a: Byte); inline;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   716
var
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   717
    nc, tw: Longword;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   718
    scale:Real = 1.0/255.0;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   719
begin
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   720
    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
   721
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   722
    if nc = lastTint then
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   723
        exit;
5559
a937d43a032f Use local scope global var instead
unc0rr
parents: 5441
diff changeset
   724
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   725
    if GrayScale then
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   726
        begin
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   727
        tw:= round(r * RGB_LUMINANCE_RED + g * RGB_LUMINANCE_GREEN + b * RGB_LUMINANCE_BLUE);
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   728
        if tw > 255 then
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   729
            tw:= 255;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   730
        r:= tw;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   731
        g:= tw;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   732
        b:= tw
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   733
        end;
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5235
diff changeset
   734
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   735
    {$IFDEF GL2}
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   736
    glUniform4f(uMainTintLocation, r*scale, g*scale, b*scale, a*scale);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   737
    //glColor4ub(r, g, b, a);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   738
    {$ELSE}
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   739
    glColor4ub(r, g, b, a);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   740
    {$ENDIF}
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   741
    lastTint:= nc;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   742
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   743
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   744
procedure Tint(c: Longword); inline;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   745
begin
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   746
    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
   747
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   748
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   749
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   750
end.