hedgewars/uRender.pas
author alfadur
Sat, 16 Oct 2021 01:06:05 +0300
changeset 15841 c5198f55ee1c
parent 15384 c5934cdeecb6
child 15844 4ede5e84278a
permissions -rw-r--r--
reduce digging damage frequency
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
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 11000
diff changeset
     3
 * Copyright (c) 2004-2015 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
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 10040
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
4976
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
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
    26
uses SDLh, uTypes, GLunit;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
    27
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
    28
procedure initModule;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
    29
procedure freeModule;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    30
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    31
procedure DrawSprite            (Sprite: TSprite; X, Y, Frame: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    32
procedure DrawSprite            (Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    33
procedure DrawSpriteFromRect    (Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline;
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    34
procedure DrawSpriteClipped     (Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    35
procedure DrawSpriteRotated     (Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    36
procedure DrawSpriteRotatedF    (Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
15056
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
    37
procedure DrawSpriteRotatedFReal(Sprite: TSprite; X, Y: Real; Frame, Dir: LongInt; Angle: real);
12119
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
    38
procedure DrawSpritePivotedF(Sprite: TSprite; X, Y, Frame, Dir, PivotX, PivotY: 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
    39
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    40
procedure DrawTexture           (X, Y: LongInt; Texture: PTexture); inline;
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    41
procedure DrawTexture           (X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
10020
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
    42
procedure DrawTexture2          (X, Y: LongInt; Texture: PTexture; Scale, Overlap: GLfloat);
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    43
procedure DrawTextureFromRect   (X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    44
procedure DrawTextureFromRect   (X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    45
procedure DrawTextureFromRectDir(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture; Dir: LongInt);
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    46
procedure DrawTextureCentered   (X, Top: LongInt; Source: PTexture);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    47
procedure DrawTextureF          (Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    48
procedure DrawTextureRotated    (Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    49
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
    50
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    51
procedure DrawCircle            (X, Y, Radius, Width: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    52
procedure DrawCircle            (X, Y, Radius, Width: LongInt; r, g, b, a: Byte);
10871
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
    53
procedure DrawCircleFilled      (X, Y, Radius: 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
    54
9557
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
    55
procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; color: LongWord); inline;
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    56
procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
13572
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
    57
procedure DrawLineWrapped       (X0, Y0, X1, Y1, Width: Single; goesLeft: boolean; Wraps: LongWord; color: LongWord); inline;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
    58
procedure DrawLineWrapped       (X0, Y0, X1, Y1, Width: Single; goesLeft: boolean; Wraps: LongWord; r, g, b, a: Byte);
10360
c243b6a8ad9a some adjustments and support for mirrored world rendering. disabled atm though, I think it is more confusing than helping
sheepluva
parents: 10354
diff changeset
    59
procedure DrawLineOnScreen      (X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
    60
procedure DrawRect              (rect: TSDL_Rect; r, g, b, a: Byte; Fill: boolean);
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    61
procedure DrawHedgehog          (X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    62
procedure DrawScreenWidget      (widget: POnScreenWidget);
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
    63
procedure DrawWater             (Alpha: byte; OffsetY, OffsetX: LongInt);
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
    64
procedure DrawWaves             (Dir, dX, dY, oX: LongInt; tnt: Byte);
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    65
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
    66
procedure RenderClear           ();
11000
b1c8027cc8f7 Fix build w/o S3D and video recording. untested.
nemo
parents: 10952
diff changeset
    67
{$IFDEF USE_S3D_RENDERING}
10869
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
    68
procedure RenderClear           (mode: TRenderMode);
11000
b1c8027cc8f7 Fix build w/o S3D and video recording. untested.
nemo
parents: 10952
diff changeset
    69
{$ENDIF}
10869
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
    70
procedure RenderSetClearColor   (r, g, b, a: real);
14721
89dd60565041 remove one of the 2 tint inlines
nemo
parents: 14303
diff changeset
    71
procedure Tint                  (r, g, b, a: Byte);
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    72
procedure Tint                  (c: Longword); inline;
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
    73
procedure untint(); inline;
12886
a089326f0e16 fix crosshair rendering in GL2 mode
sheepluva
parents: 12885
diff changeset
    74
procedure setTintAdd            (enable: boolean); inline;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    75
10869
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
    76
// call this to finish the rendering of current frame
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
    77
procedure FinishRender();
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
    78
10266
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
    79
function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline;
12119
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
    80
function isCircleOffscreen(X, Y, RadiusSquared: LongInt): boolean; inline;
10266
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
    81
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
    82
// 0 => not offscreen, <0 => left/top of screen >0 => right/below of screen
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
    83
function isDxAreaOffscreen(X, Width: LongInt): LongInt; inline;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
    84
function isDyAreaOffscreen(Y, Height: LongInt): LongInt; inline;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
    85
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
    86
procedure SetScale(f: GLfloat);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
    87
procedure UpdateViewLimits();
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
    88
10869
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
    89
procedure RendererSetup();
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
    90
procedure RendererCleanup();
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
    91
10871
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
    92
procedure ChangeDepth(rm: TRenderMode; d: GLfloat);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
    93
procedure ResetDepth(rm: TRenderMode);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
    94
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
    95
// TODO everything below this should not need a public interface
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
    96
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
    97
procedure EnableTexture(enable:Boolean);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
    98
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
    99
procedure SetTexCoordPointer(p: Pointer;n: Integer); inline;
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
   100
procedure SetVertexPointer(p: Pointer;n: Integer); inline;
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
   101
procedure SetColorPointer(p: Pointer;n: Integer); inline;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   102
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   103
procedure UpdateModelviewProjection(); inline;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   104
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   105
procedure openglPushMatrix      (); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   106
procedure openglPopMatrix       (); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   107
procedure openglTranslatef      (X, Y, Z: GLfloat); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   108
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   109
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   110
implementation
12621
d972b31f8881 fix some fpc hints
sheepluva
parents: 12282
diff changeset
   111
uses {$IFNDEF PAS2C} StrUtils, {$ENDIF}uVariables, uUtils
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   112
     {$IFDEF GL2}, uMatrix, uConsole, uPhysFSLayer, uDebug{$ENDIF}, uConsts;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   113
8145
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
   114
{$IFDEF USE_TOUCH_INTERFACE}
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
   115
const
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
   116
    FADE_ANIM_TIME = 500;
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
   117
    MOVE_ANIM_TIME = 500;
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
   118
{$ENDIF}
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
   119
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   120
{$IFDEF GL2}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   121
var
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   122
    shaderMain: GLuint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   123
    shaderWater: GLuint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   124
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   125
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
   126
var VertexBuffer : array [0 ..59] of TVertex2f;
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
   127
    TextureBuffer: array [0 .. 7] of TVertex2f;
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
   128
    LastTint: LongWord = 0;
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   129
{$IFNDEF GL2}
10326
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
   130
    LastColorPointer , LastTexCoordPointer , LastVertexPointer : Pointer;
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
   131
{$ENDIF}
7028
0f60591f3a16 old typed const moved to their proper unit
koda
parents: 6999
diff changeset
   132
10869
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   133
{$IFDEF USE_S3D_RENDERING}
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   134
    // texture/vertex buffers for left/right/default eye modes
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   135
    texLRDtb, texLvb, texRvb: array [0..3] of TVertex2f;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   136
{$ENDIF}
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   137
10873
84c00d1127d6 still messing with rendering
sheepluva
parents: 10871
diff changeset
   138
procedure openglLoadIdentity    (); forward;
84c00d1127d6 still messing with rendering
sheepluva
parents: 10871
diff changeset
   139
procedure openglTranslProjMatrix(X, Y, Z: GLFloat); forward;
84c00d1127d6 still messing with rendering
sheepluva
parents: 10871
diff changeset
   140
procedure openglScalef          (ScaleX, ScaleY, ScaleZ: GLfloat); forward;
84c00d1127d6 still messing with rendering
sheepluva
parents: 10871
diff changeset
   141
procedure openglRotatef         (RotX, RotY, RotZ: GLfloat; dir: LongInt); forward;
84c00d1127d6 still messing with rendering
sheepluva
parents: 10871
diff changeset
   142
procedure openglTint            (r, g, b, a: Byte); forward;
84c00d1127d6 still messing with rendering
sheepluva
parents: 10871
diff changeset
   143
11000
b1c8027cc8f7 Fix build w/o S3D and video recording. untested.
nemo
parents: 10952
diff changeset
   144
{$IFDEF USE_S3D_RENDERING OR USE_VIDEO_RECORDING}
10870
5efea5942475 rendering tweaks cont.
sheepluva
parents: 10869
diff changeset
   145
procedure CreateFramebuffer(var frame, depth, tex: GLuint); forward;
5efea5942475 rendering tweaks cont.
sheepluva
parents: 10869
diff changeset
   146
procedure DeleteFramebuffer(var frame, depth, tex: GLuint); forward;
11000
b1c8027cc8f7 Fix build w/o S3D and video recording. untested.
nemo
parents: 10952
diff changeset
   147
{$ENDIF}
10870
5efea5942475 rendering tweaks cont.
sheepluva
parents: 10869
diff changeset
   148
10266
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   149
function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   150
begin
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   151
    isAreaOffscreen:= (isDxAreaOffscreen(X, Width) <> 0) or (isDyAreaOffscreen(Y, Height) <> 0);
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   152
end;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   153
12119
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
   154
function isCircleOffscreen(X, Y, RadiusSquared: LongInt): boolean; inline;
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
   155
var dRightX, dBottomY, dLeftX, dTopY: LongInt;
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
   156
begin
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
   157
    dRightX:= (X - ViewRightX);
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
   158
    dBottomY:= (Y - ViewBottomY);
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
   159
    dLeftX:= (ViewLeftX - X);
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
   160
    dTopY:= (ViewTopY - Y);
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
   161
    isCircleOffscreen:= 
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
   162
        ((dRightX > 0) and (sqr(dRightX) > RadiusSquared)) or
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
   163
        ((dBottomY > 0) and (sqr(dBottomY) > RadiusSquared)) or
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
   164
        ((dLeftX > 0) and (sqr(dLeftX) > RadiusSquared)) or
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
   165
        ((dTopY > 0) and (sqr(dTopY) > RadiusSquared))
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
   166
end;
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
   167
10266
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   168
function isDxAreaOffscreen(X, Width: LongInt): LongInt; inline;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   169
begin
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   170
    if X > ViewRightX then exit(1);
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   171
    if X + Width < ViewLeftX then exit(-1);
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   172
    isDxAreaOffscreen:= 0;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   173
end;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   174
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   175
function isDyAreaOffscreen(Y, Height: LongInt): LongInt; inline;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   176
begin
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   177
    if Y > ViewBottomY then exit(1);
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   178
    if Y + Height < ViewTopY then exit(-1);
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   179
    isDyAreaOffscreen:= 0;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   180
end;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   181
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   182
procedure RenderClear();
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   183
begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   184
    glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   185
end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   186
10869
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   187
{$IFDEF USE_S3D_RENDERING}
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   188
procedure RenderClear(mode: TRenderMode);
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   189
var frame: GLuint;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   190
begin
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   191
    if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) then
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   192
        begin
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   193
        case mode of
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   194
            rmLeftEye:  frame:= frameL;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   195
            rmRightEye: frame:= frameR;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   196
            else
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   197
                frame:= defaultFrame;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   198
        end;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   199
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   200
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frame);
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   201
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   202
        RenderClear();
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   203
        end
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   204
    else
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   205
        begin
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   206
        // draw left eye in red channel only
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   207
        if mode = rmLeftEye then
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   208
            begin
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   209
            glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   210
            RenderClear();
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   211
            if cStereoMode = smGreenRed then
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   212
                glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE)
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   213
            else if cStereoMode = smBlueRed then
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   214
                glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE)
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   215
            else if cStereoMode = smCyanRed then
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   216
                glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE)
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   217
            else
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   218
                glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   219
            end
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   220
        else
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   221
            begin
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   222
            // draw right eye in selected channel(s) only
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   223
            if cStereoMode = smRedGreen then
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   224
                glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE)
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   225
            else if cStereoMode = smRedBlue then
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   226
                glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE)
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   227
            else if cStereoMode = smRedCyan then
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   228
                glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE)
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   229
            else
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   230
                glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   231
            end;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   232
        end;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   233
end;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   234
{$ENDIF}
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   235
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   236
procedure RenderSetClearColor(r, g, b, a: real);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   237
begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   238
    glClearColor(r, g, b, a);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   239
end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   240
10869
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   241
procedure FinishRender();
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   242
begin
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   243
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   244
{$IFDEF USE_S3D_RENDERING}
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   245
if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) then
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   246
    begin
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   247
    RenderClear(rmDefault);
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   248
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   249
    SetScale(cDefaultZoomLevel);
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   250
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   251
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   252
    // same for all
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   253
    SetTexCoordPointer(@texLRDtb, Length(texLRDtb));
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   254
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   255
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   256
    // draw left frame
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   257
    glBindTexture(GL_TEXTURE_2D, texl);
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   258
    SetVertexPointer(@texLvb, Length(texLvb));
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   259
    //UpdateModelviewProjection;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   260
    glDrawArrays(GL_TRIANGLE_FAN, 0, Length(texLvb));
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   261
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   262
    // draw right frame
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   263
    glBindTexture(GL_TEXTURE_2D, texl);
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   264
    SetVertexPointer(@texRvb, Length(texRvb));
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   265
    //UpdateModelviewProjection;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   266
    glDrawArrays(GL_TRIANGLE_FAN, 0, Length(texRvb));
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   267
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   268
    SetScale(zoom);
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   269
    end;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   270
{$ENDIF}
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   271
end;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   272
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   273
{$IFDEF GL2}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   274
function CompileShader(shaderFile: string; shaderType: GLenum): GLuint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   275
var
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   276
    shader: GLuint;
11798
984f9c76146d I heard we switched to physfs
unc0rr
parents: 11792
diff changeset
   277
    f: PFSFile;
11800
6e6248c43942 ansistring, not Ansistring
unc0rr
parents: 11798
diff changeset
   278
    source, line: ansistring;
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   279
    sourceA: Pchar;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   280
    lengthA: GLint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   281
    compileResult: GLint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   282
    logLength: GLint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   283
    log: PChar;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   284
begin
11798
984f9c76146d I heard we switched to physfs
unc0rr
parents: 11792
diff changeset
   285
    f:= pfsOpenRead(cPathz[ptShaders] + '/' + shaderFile);
984f9c76146d I heard we switched to physfs
unc0rr
parents: 11792
diff changeset
   286
    checkFails(f <> nil, 'Unable to load ' + shaderFile, true);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   287
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   288
    source:='';
11798
984f9c76146d I heard we switched to physfs
unc0rr
parents: 11792
diff changeset
   289
    while not pfsEof(f) do
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   290
    begin
11798
984f9c76146d I heard we switched to physfs
unc0rr
parents: 11792
diff changeset
   291
        pfsReadLnA(f, line);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   292
        source:= source + line + #10;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   293
    end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   294
11798
984f9c76146d I heard we switched to physfs
unc0rr
parents: 11792
diff changeset
   295
    pfsClose(f);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   296
11800
6e6248c43942 ansistring, not Ansistring
unc0rr
parents: 11798
diff changeset
   297
    WriteLnToConsole('Compiling shader: ' + cPathz[ptShaders] + '/' + shaderFile);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   298
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   299
    sourceA:=PChar(source);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   300
    lengthA:=Length(source);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   301
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   302
    shader:=glCreateShader(shaderType);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   303
    glShaderSource(shader, 1, @sourceA, @lengthA);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   304
    glCompileShader(shader);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   305
    glGetShaderiv(shader, GL_COMPILE_STATUS, @compileResult);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   306
    glGetShaderiv(shader, GL_INFO_LOG_LENGTH, @logLength);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   307
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   308
    if logLength > 1 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   309
    begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   310
        log := GetMem(logLength);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   311
        glGetShaderInfoLog(shader, logLength, nil, log);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   312
        WriteLnToConsole('========== Compiler log  ==========');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   313
        WriteLnToConsole(shortstring(log));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   314
        WriteLnToConsole('===================================');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   315
        FreeMem(log, logLength);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   316
    end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   317
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   318
    if compileResult <> GL_TRUE then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   319
    begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   320
        WriteLnToConsole('Shader compilation failed, halting');
10306
4fca8bcfaff0 clean up halting a little
sheepluva
parents: 10304
diff changeset
   321
        halt(HaltStartupError);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   322
    end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   323
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   324
    CompileShader:= shader;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   325
end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   326
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   327
function CompileProgram(shaderName: string): GLuint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   328
var
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   329
    program_: GLuint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   330
    vs, fs: GLuint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   331
    linkResult: GLint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   332
    logLength: GLint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   333
    log: PChar;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   334
begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   335
    program_:= glCreateProgram();
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   336
    vs:= CompileShader(shaderName + '.vs', GL_VERTEX_SHADER);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   337
    fs:= CompileShader(shaderName + '.fs', GL_FRAGMENT_SHADER);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   338
    glAttachShader(program_, vs);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   339
    glAttachShader(program_, fs);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   340
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   341
    glBindAttribLocation(program_, aVertex, PChar('vertex'));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   342
    glBindAttribLocation(program_, aTexCoord, PChar('texcoord'));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   343
    glBindAttribLocation(program_, aColor, PChar('color'));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   344
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   345
    glLinkProgram(program_);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   346
    glDeleteShader(vs);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   347
    glDeleteShader(fs);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   348
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   349
    glGetProgramiv(program_, GL_LINK_STATUS, @linkResult);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   350
    glGetProgramiv(program_, GL_INFO_LOG_LENGTH, @logLength);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   351
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   352
    if logLength > 1 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   353
    begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   354
        log := GetMem(logLength);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   355
        glGetProgramInfoLog(program_, logLength, nil, log);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   356
        WriteLnToConsole('========== Compiler log  ==========');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   357
        WriteLnToConsole(shortstring(log));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   358
        WriteLnToConsole('===================================');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   359
        FreeMem(log, logLength);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   360
    end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   361
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   362
    if linkResult <> GL_TRUE then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   363
    begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   364
        WriteLnToConsole('Linking program failed, halting');
10306
4fca8bcfaff0 clean up halting a little
sheepluva
parents: 10304
diff changeset
   365
        halt(HaltStartupError);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   366
    end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   367
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   368
    CompileProgram:= program_;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   369
end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   370
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   371
10309
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   372
function glLoadExtension(extension : shortstring) : boolean;
11158
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   373
var logmsg: shortstring;
10309
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   374
begin
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   375
    extension:= extension; // avoid hint
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   376
    glLoadExtension:= false;
11158
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   377
    logmsg:= 'OpenGL - "' + extension + '" skipped';
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   378
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   379
{$IFNDEF IPHONEOS}
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   380
//TODO: pas2c does not handle
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   381
{$IFNDEF PAS2C}
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   382
// FreePascal doesnt come with OpenGL ES 1.1 Extension headers
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   383
{$IF GLunit <> gles11}
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   384
10309
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   385
    glLoadExtension:= glext_LoadExtension(extension);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   386
11158
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   387
    if glLoadExtension then
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   388
        logmsg:= 'OpenGL - "' + extension + '" loaded'
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   389
    else
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   390
        logmsg:= 'OpenGL - "' + extension + '" failed to load';
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   391
10309
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   392
{$ENDIF}
11158
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   393
{$ENDIF}
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   394
{$ENDIF}
797bc8d70e75 simplify code
sheepluva
parents: 11153
diff changeset
   395
    AddFileLog(logmsg);
10309
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   396
end;
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   397
10429
e3cdbba07732 simplify {$IF that pas2c did not seem to understand
sheepluva
parents: 10427
diff changeset
   398
{$IFDEF USE_S3D_RENDERING OR USE_VIDEO_RECORDING}
10309
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   399
procedure CreateFramebuffer(var frame, depth, tex: GLuint);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   400
begin
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   401
    glGenFramebuffersEXT(1, @frame);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   402
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frame);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   403
    glGenRenderbuffersEXT(1, @depth);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   404
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   405
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, cScreenWidth, cScreenHeight);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   406
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   407
    glGenTextures(1, @tex);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   408
    glBindTexture(GL_TEXTURE_2D, tex);
10531
b8e6164a1a18 fix for issue 234 - the framebuffers for side-by-side and top/bottom had alpha channels. so when sprites with alpha were blended into the framebuffer it would blend the sprite pixel alpha with the fb pixel alpha
sheepluva
parents: 10494
diff changeset
   409
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8,  cScreenWidth, cScreenHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, nil);
10309
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   410
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   411
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   412
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   413
end;
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   414
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   415
procedure DeleteFramebuffer(var frame, depth, tex: GLuint);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   416
begin
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   417
    glDeleteTextures(1, @tex);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   418
    glDeleteRenderbuffersEXT(1, @depth);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   419
    glDeleteFramebuffersEXT(1, @frame);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   420
end;
10869
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   421
{$ENDIF}
10309
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   422
10869
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   423
procedure RendererCleanup();
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   424
begin
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   425
{$IFNDEF PAS2C}
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   426
{$IFDEF USE_VIDEO_RECORDING}
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   427
    if defaultFrame <> 0 then
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   428
        DeleteFramebuffer(defaultFrame, depthv, texv);
10309
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   429
{$ENDIF}
10869
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   430
{$IFDEF USE_S3D_RENDERING}
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   431
    if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) then
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   432
        begin
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   433
        DeleteFramebuffer(framel, depthl, texl);
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   434
        DeleteFramebuffer(framer, depthr, texr);
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   435
        end
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   436
{$ENDIF}
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   437
{$ENDIF}
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   438
end;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   439
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   440
procedure RendererSetup();
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   441
var AuxBufNum: LongInt = 0;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   442
    tmpstr: ansistring;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   443
    tmpint: LongInt;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   444
    tmpn: LongInt;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   445
begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   446
    // suppress hint/warning
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   447
    AuxBufNum:= AuxBufNum;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   448
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   449
    // get the max (h and v) size for textures that the gpu can support
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   450
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   451
    if MaxTextureSize <= 0 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   452
        begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   453
        MaxTextureSize:= 1024;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   454
        AddFileLog('OpenGL Warning - driver didn''t provide any valid max texture size; assuming 1024');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   455
        end
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   456
    else if (MaxTextureSize < 1024) and (MaxTextureSize >= 512) then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   457
        begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   458
        cReducedQuality := cReducedQuality or rqNoBackground;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   459
        AddFileLog('Texture size too small for backgrounds, disabling.');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   460
        end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   461
    // everyone loves debugging
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   462
    // find out which gpu we are using (for extension compatibility maybe?)
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   463
    AddFileLog('OpenGL-- Renderer: ' + shortstring(pchar(glGetString(GL_RENDERER))));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   464
    AddFileLog('  |----- Vendor: ' + shortstring(pchar(glGetString(GL_VENDOR))));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   465
    AddFileLog('  |----- Version: ' + shortstring(pchar(glGetString(GL_VERSION))));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   466
    AddFileLog('  |----- Texture Size: ' + inttostr(MaxTextureSize));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   467
{$IFDEF USE_VIDEO_RECORDING}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   468
    glGetIntegerv(GL_AUX_BUFFERS, @AuxBufNum);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   469
    AddFileLog('  |----- Number of auxiliary buffers: ' + inttostr(AuxBufNum));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   470
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   471
{$IFNDEF PAS2C}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   472
    AddFileLog('  \----- Extensions: ');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   473
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   474
    // fetch extentions and store them in string
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   475
    tmpstr := StrPas(PChar(glGetString(GL_EXTENSIONS)));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   476
    tmpn := WordCount(tmpstr, [' ']);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   477
    tmpint := 1;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   478
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   479
    repeat
10952
8ad21fe5d062 don't decrement 0 timer for air mines...
nemo
parents: 10873
diff changeset
   480
        begin
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   481
        // print up to 3 extentions per row
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   482
        // ExtractWord will return empty string if index out of range
11823
0fba6cb098a1 drop SysUtils inclusion from 5 files where it is not needed anymore
sheepluva
parents: 11800
diff changeset
   483
        //AddFileLog(TrimRight(
11824
3f1f8f79fcdb implement Trim() in uUtils
sheepluva
parents: 11823
diff changeset
   484
        AddFileLog(Trim(
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   485
            ExtractWord(tmpint, tmpstr, [' ']) + ' ' +
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   486
            ExtractWord(tmpint+1, tmpstr, [' ']) + ' ' +
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   487
            ExtractWord(tmpint+2, tmpstr, [' '])
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   488
        ));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   489
        tmpint := tmpint + 3;
10952
8ad21fe5d062 don't decrement 0 timer for air mines...
nemo
parents: 10873
diff changeset
   490
        end;
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   491
    until (tmpint > tmpn);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   492
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   493
    AddFileLog('');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   494
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   495
    defaultFrame:= 0;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   496
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   497
{$IFDEF USE_VIDEO_RECORDING}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   498
    if GameType = gmtRecord then
10952
8ad21fe5d062 don't decrement 0 timer for air mines...
nemo
parents: 10873
diff changeset
   499
        begin
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   500
        if glLoadExtension('GL_EXT_framebuffer_object') then
10952
8ad21fe5d062 don't decrement 0 timer for air mines...
nemo
parents: 10873
diff changeset
   501
            begin
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   502
            CreateFramebuffer(defaultFrame, depthv, texv);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   503
            glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, defaultFrame);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   504
            AddFileLog('Using framebuffer for video recording.');
10952
8ad21fe5d062 don't decrement 0 timer for air mines...
nemo
parents: 10873
diff changeset
   505
            end
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   506
        else if AuxBufNum > 0 then
10952
8ad21fe5d062 don't decrement 0 timer for air mines...
nemo
parents: 10873
diff changeset
   507
            begin
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   508
            glDrawBuffer(GL_AUX0);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   509
            glReadBuffer(GL_AUX0);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   510
            AddFileLog('Using auxiliary buffer for video recording.');
10952
8ad21fe5d062 don't decrement 0 timer for air mines...
nemo
parents: 10873
diff changeset
   511
            end
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   512
        else
10952
8ad21fe5d062 don't decrement 0 timer for air mines...
nemo
parents: 10873
diff changeset
   513
            begin
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   514
            glDrawBuffer(GL_BACK);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   515
            glReadBuffer(GL_BACK);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   516
            AddFileLog('Warning: off-screen rendering is not supported; using back buffer but it may not work.');
10952
8ad21fe5d062 don't decrement 0 timer for air mines...
nemo
parents: 10873
diff changeset
   517
            end;
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   518
        end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   519
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   520
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   521
{$IFDEF GL2}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   522
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   523
{$IFNDEF PAS2C}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   524
    if not Load_GL_VERSION_2_0 then
13499
b5f8864a38d3 Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents: 12898
diff changeset
   525
        begin
b5f8864a38d3 Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents: 12898
diff changeset
   526
        WriteLnToConsole('Load_GL_VERSION_2_0 returned false!');
b5f8864a38d3 Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents: 12898
diff changeset
   527
        halt(HaltStartupError);
b5f8864a38d3 Add proper exit codes when halt-ing hwengine due to error
Wuzzy <Wuzzy2@mail.ru>
parents: 12898
diff changeset
   528
        end;
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   529
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   530
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   531
    shaderWater:= CompileProgram('water');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   532
    glUseProgram(shaderWater);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   533
    glUniform1i(glGetUniformLocation(shaderWater, pchar('tex0')), 0);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   534
    uWaterMVPLocation:= glGetUniformLocation(shaderWater, pchar('mvp'));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   535
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   536
    shaderMain:= CompileProgram('default');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   537
    glUseProgram(shaderMain);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   538
    glUniform1i(glGetUniformLocation(shaderMain, pchar('tex0')), 0);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   539
    uMainMVPLocation:= glGetUniformLocation(shaderMain, pchar('mvp'));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   540
    uMainTintLocation:= glGetUniformLocation(shaderMain, pchar('tint'));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   541
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   542
    uCurrentMVPLocation:= uMainMVPLocation;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   543
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   544
    Tint(255, 255, 255, 255);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   545
    UpdateModelviewProjection;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   546
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   547
10427
dd44d2c8fd0e also fix top/bottom and side-by-side rendering (got also broken in webgl branch)
sheepluva
parents: 10360
diff changeset
   548
{$IFDEF USE_S3D_RENDERING}
dd44d2c8fd0e also fix top/bottom and side-by-side rendering (got also broken in webgl branch)
sheepluva
parents: 10360
diff changeset
   549
    if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) then
10952
8ad21fe5d062 don't decrement 0 timer for air mines...
nemo
parents: 10873
diff changeset
   550
        begin
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   551
        // prepare left and right frame buffers and associated textures
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   552
        if glLoadExtension('GL_EXT_framebuffer_object') then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   553
            begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   554
            CreateFramebuffer(framel, depthl, texl);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   555
            CreateFramebuffer(framer, depthr, texr);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   556
10869
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   557
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   558
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   559
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   560
            // reset
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   561
            glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, defaultFrame)
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   562
            end
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   563
        else
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   564
            cStereoMode:= smNone;
10952
8ad21fe5d062 don't decrement 0 timer for air mines...
nemo
parents: 10873
diff changeset
   565
        end;
10869
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   566
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   567
    // set up vertex/texture buffers for frame textures
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   568
    texLRDtb[0].X:= 0.0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   569
    texLRDtb[0].Y:= 0.0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   570
    texLRDtb[1].X:= 1.0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   571
    texLRDtb[1].Y:= 0.0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   572
    texLRDtb[2].X:= 1.0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   573
    texLRDtb[2].Y:= 1.0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   574
    texLRDtb[3].X:= 0.0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   575
    texLRDtb[3].Y:= 1.0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   576
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   577
    if cStereoMode = smHorizontal then
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   578
        begin
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   579
        texLvb[0].X:= cScreenWidth / -2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   580
        texLvb[0].Y:= cScreenHeight;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   581
        texLvb[1].X:= 0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   582
        texLvb[1].Y:= cScreenHeight;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   583
        texLvb[2].X:= 0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   584
        texLvb[2].Y:= 0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   585
        texLvb[3].X:= cScreenWidth / -2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   586
        texLvb[3].Y:= 0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   587
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   588
        texRvb[0].X:= 0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   589
        texRvb[0].Y:= cScreenHeight;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   590
        texRvb[1].X:= cScreenWidth / 2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   591
        texRvb[1].Y:= cScreenHeight;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   592
        texRvb[2].X:= cScreenWidth / 2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   593
        texRvb[2].Y:= 0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   594
        texRvb[3].X:= 0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   595
        texRvb[3].Y:= 0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   596
        end
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   597
    else
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   598
        begin
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   599
        texLvb[0].X:= cScreenWidth / -2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   600
        texLvb[0].Y:= cScreenHeight / 2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   601
        texLvb[1].X:= cScreenWidth / 2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   602
        texLvb[1].Y:= cScreenHeight / 2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   603
        texLvb[2].X:= cScreenWidth / 2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   604
        texLvb[2].Y:= 0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   605
        texLvb[3].X:= cScreenWidth / -2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   606
        texLvb[3].Y:= 0;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   607
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   608
        texRvb[0].X:= cScreenWidth / -2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   609
        texRvb[0].Y:= cScreenHeight;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   610
        texRvb[1].X:= cScreenWidth / 2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   611
        texRvb[1].Y:= cScreenHeight;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   612
        texRvb[2].X:= cScreenWidth / 2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   613
        texRvb[2].Y:= cScreenHeight / 2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   614
        texRvb[3].X:= cScreenWidth / -2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   615
        texRvb[3].Y:= cScreenHeight / 2;
f23763bbac1b rendering tweaks/cleanup cont.
sheepluva
parents: 10724
diff changeset
   616
        end;
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   617
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   618
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   619
// set view port to whole window
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   620
glViewport(0, 0, cScreenWidth, cScreenHeight);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   621
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   622
{$IFDEF GL2}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   623
    uMatrix.initModule;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   624
    hglMatrixMode(MATRIX_MODELVIEW);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   625
    // prepare default translation/scaling
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   626
    hglLoadIdentity();
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   627
    hglScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   628
    hglTranslatef(0, -cScreenHeight / 2, 0);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   629
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   630
    EnableTexture(True);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   631
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   632
    glEnableVertexAttribArray(aVertex);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   633
    glEnableVertexAttribArray(aTexCoord);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   634
    glGenBuffers(1, @vBuffer);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   635
    glGenBuffers(1, @tBuffer);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   636
    glGenBuffers(1, @cBuffer);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   637
{$ELSE}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   638
    glMatrixMode(GL_MODELVIEW);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   639
    // prepare default translation/scaling
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   640
    glLoadIdentity();
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   641
    glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   642
    glTranslatef(0, -cScreenHeight / 2, 0);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   643
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   644
    // disable/lower perspective correction (will not need it anyway)
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   645
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   646
    // disable dithering
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   647
    glDisable(GL_DITHER);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   648
    // enable common states by default as they save a lot
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   649
    glEnable(GL_TEXTURE_2D);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   650
    glEnableClientState(GL_VERTEX_ARRAY);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   651
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   652
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   653
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   654
    // enable alpha blending
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   655
    glEnable(GL_BLEND);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   656
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   657
    // disable/lower perspective correction (will not need it anyway)
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   658
end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   659
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   660
procedure openglLoadIdentity(); inline;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   661
begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   662
{$IFDEF GL2}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   663
    hglLoadIdentity();
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   664
{$ELSE}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   665
    glLoadIdentity();
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   666
{$ENDIF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   667
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   668
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   669
procedure openglTranslProjMatrix(X, Y, Z: GLfloat); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   670
begin
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   671
{$IFDEF GL2}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   672
    hglMatrixMode(MATRIX_PROJECTION);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   673
    hglTranslatef(X, Y, Z);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   674
    hglMatrixMode(MATRIX_MODELVIEW);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   675
{$ELSE}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   676
    glMatrixMode(GL_PROJECTION);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   677
    glTranslatef(X, Y, Z);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   678
    glMatrixMode(GL_MODELVIEW);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   679
{$ENDIF}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   680
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   681
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   682
procedure openglPushMatrix(); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   683
begin
10276
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   684
{$IFDEF GL2}
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   685
    hglPushMatrix();
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   686
{$ELSE}
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   687
    glPushMatrix();
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   688
{$ENDIF}
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   689
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   690
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   691
procedure openglPopMatrix(); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   692
begin
10276
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   693
{$IFDEF GL2}
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   694
    hglPopMatrix();
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   695
{$ELSE}
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   696
    glPopMatrix();
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   697
{$ENDIF}
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   698
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   699
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   700
procedure openglTranslatef(X, Y, Z: GLfloat); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   701
begin
10276
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   702
{$IFDEF GL2}
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   703
    hglTranslatef(X, Y, Z);
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   704
{$ELSE}
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   705
    glTranslatef(X, Y, Z);
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   706
{$ENDIF}
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   707
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   708
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   709
procedure openglScalef(ScaleX, ScaleY, ScaleZ: GLfloat); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   710
begin
10276
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   711
{$IFDEF GL2}
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   712
    hglScalef(ScaleX, ScaleY, ScaleZ);
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   713
{$ELSE}
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   714
    glScalef(ScaleX, ScaleY, ScaleZ);
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   715
{$ENDIF}
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   716
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   717
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   718
procedure openglRotatef(RotX, RotY, RotZ: GLfloat; dir: LongInt); inline;
13512
36f3f77e9b1b Switch from http:// to https:// URLs where possible
Wuzzy <Wuzzy2@mail.ru>
parents: 13499
diff changeset
   719
{ workaround for pascal bug https://bugs.freepascal.org/view.php?id=27222 }
10724
eedd0697d55c Fix arm* build failures
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10531
diff changeset
   720
var tmpdir: LongInt;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   721
begin
10724
eedd0697d55c Fix arm* build failures
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10531
diff changeset
   722
tmpdir:=dir;
10276
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   723
{$IFDEF GL2}
10724
eedd0697d55c Fix arm* build failures
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10531
diff changeset
   724
    hglRotatef(RotX, RotY, RotZ, tmpdir);
10276
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   725
{$ELSE}
10724
eedd0697d55c Fix arm* build failures
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents: 10531
diff changeset
   726
    glRotatef(RotX, RotY, RotZ, tmpdir);
10276
89056c7254ef fix hint and gl2 build. NOTE: this does not change that GL2 segfaults right away. that is an issue that dates back at least 50 commits, but most likely even back to the webgl merge. I guess nobody actually tried to run hedgewars in GL2 since back then :P
sheepluva
parents: 10275
diff changeset
   727
{$ENDIF}
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   728
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   729
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   730
procedure openglUseColorOnly(b :boolean); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   731
begin
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   732
    if b then
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   733
        begin
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   734
        {$IFDEF GL2}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   735
        glDisableVertexAttribArray(aTexCoord);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   736
        glEnableVertexAttribArray(aColor);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   737
        {$ELSE}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   738
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   739
        glEnableClientState(GL_COLOR_ARRAY);
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   740
        LastTexCoordPointer:= nil;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   741
        {$ENDIF}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   742
        end
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   743
    else
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   744
        begin
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   745
        {$IFDEF GL2}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   746
        glDisableVertexAttribArray(aColor);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   747
        glEnableVertexAttribArray(aTexCoord);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   748
        {$ELSE}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   749
        glDisableClientState(GL_COLOR_ARRAY);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   750
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   751
        LastColorPointer:= nil;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   752
        {$ENDIF}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   753
        end;
10318
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   754
    EnableTexture(not b);
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   755
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   756
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   757
procedure UpdateModelviewProjection(); inline;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   758
{$IFDEF GL2}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   759
var
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   760
    mvp: TMatrix4x4f;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   761
{$ENDIF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   762
begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   763
{$IFDEF GL2}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   764
    //MatrixMultiply(mvp, mProjection, mModelview);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   765
{$HINTS OFF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   766
    hglMVP(mvp);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   767
{$HINTS ON}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   768
    glUniformMatrix4fv(uCurrentMVPLocation, 1, GL_FALSE, @mvp[0, 0]);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   769
{$ENDIF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   770
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   771
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
   772
procedure SetTexCoordPointer(p: Pointer; n: Integer); inline;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   773
begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   774
{$IFDEF GL2}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   775
    glBindBuffer(GL_ARRAY_BUFFER, tBuffer);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   776
    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   777
    glEnableVertexAttribArray(aTexCoord);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   778
    glVertexAttribPointer(aTexCoord, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   779
{$ELSE}
10326
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
   780
    if p = LastTexCoordPointer then
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
   781
        exit;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   782
    n:= n;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   783
    glTexCoordPointer(2, GL_FLOAT, 0, p);
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   784
    LastTexCoordPointer:= p;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   785
{$ENDIF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   786
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   787
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
   788
procedure SetVertexPointer(p: Pointer; n: Integer); inline;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   789
begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   790
{$IFDEF GL2}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   791
    glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   792
    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   793
    glEnableVertexAttribArray(aVertex);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   794
    glVertexAttribPointer(aVertex, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   795
{$ELSE}
10326
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
   796
    if p = LastVertexPointer then
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
   797
        exit;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   798
    n:= n;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   799
    glVertexPointer(2, GL_FLOAT, 0, p);
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   800
    LastVertexPointer:= p;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   801
{$ENDIF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   802
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   803
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
   804
procedure SetColorPointer(p: Pointer; n: Integer); inline;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   805
begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   806
{$IFDEF GL2}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   807
    glBindBuffer(GL_ARRAY_BUFFER, cBuffer);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   808
    glBufferData(GL_ARRAY_BUFFER, n * 4, p, GL_STATIC_DRAW);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   809
    glEnableVertexAttribArray(aColor);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   810
    glVertexAttribPointer(aColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, pointer(0));
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   811
{$ELSE}
10326
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
   812
    if p = LastColorPointer then
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
   813
        exit;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   814
    n:= n;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   815
    glColorPointer(4, GL_UNSIGNED_BYTE, 0, p);
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   816
    LastColorPointer:= p;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   817
{$ENDIF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   818
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   819
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   820
procedure EnableTexture(enable:Boolean);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   821
begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   822
    {$IFDEF GL2}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   823
    if enable then
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   824
        glUniform1i(glGetUniformLocation(shaderMain, pchar('enableTexture')), 1)
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   825
    else
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   826
        glUniform1i(glGetUniformLocation(shaderMain, pchar('enableTexture')), 0);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   827
    {$ELSE}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   828
    if enable then
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   829
        glEnable(GL_TEXTURE_2D)
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   830
    else
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   831
        glDisable(GL_TEXTURE_2D);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   832
    {$ENDIF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   833
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   834
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   835
procedure UpdateViewLimits();
10318
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   836
var tmp: LongInt;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   837
begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   838
    // cScaleFactor is 2.0 on "no zoom"
10318
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   839
    tmp:= round(0.5 + cScreenWidth / cScaleFactor);
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   840
    ViewRightX :=  tmp;
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   841
    ViewLeftX  := -tmp;
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   842
    tmp:= round(0.5 + cScreenHeight / cScaleFactor);
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   843
    ViewBottomY:=  tmp + cScreenHeight div 2;
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   844
    ViewTopY   := -tmp + cScreenHeight div 2;
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   845
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   846
    // visual debugging fun :D
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   847
    if cViewLimitsDebug then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   848
        begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   849
        // some margin on each side
10318
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   850
        tmp:= trunc(min(cScreenWidth, cScreenHeight) div 2 / cScaleFactor);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   851
        ViewLeftX  := ViewLeftX   + trunc(tmp);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   852
        ViewRightX := ViewRightX  - trunc(tmp);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   853
        ViewBottomY:= ViewBottomY - trunc(tmp);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   854
        ViewTopY   := ViewTopY    + trunc(tmp);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   855
        end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   856
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   857
    ViewWidth := ViewRightX  - ViewLeftX + 1;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   858
    ViewHeight:= ViewBottomY - ViewTopY  + 1;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   859
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   860
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   861
procedure SetScale(f: GLfloat);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   862
begin
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   863
    // leave immediately if scale factor did not change
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   864
    if f = cScaleFactor then
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   865
        exit;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   866
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   867
    // for going back to default scaling just pop matrix
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   868
    if f = cDefaultZoomLevel then
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   869
        begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   870
        openglPopMatrix;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   871
        end
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   872
    else
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   873
        begin
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   874
        if cScaleFactor = cDefaultZoomLevel then
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   875
            begin
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   876
            openglPushMatrix; // save default scaling in matrix;
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   877
            end;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   878
        openglLoadIdentity();
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   879
        openglScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   880
        openglTranslatef(0, -cScreenHeight div 2, 0);
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   881
        end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   882
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   883
    cScaleFactor:= f;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   884
    updateViewLimits();
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   885
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   886
    UpdateModelviewProjection;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   887
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   888
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   889
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   890
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   891
r.y:= r.y + Height * Position;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   892
r.h:= Height;
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   893
DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   894
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   895
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   896
procedure DrawTextureFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   897
begin
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   898
DrawTextureFromRectDir(X, Y, r^.w, r^.h, r, SourceTexture, 1)
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   899
end;
8833
c13ebed437cb update webgl branch
koda
parents: 8330 8626
diff changeset
   900
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   901
procedure DrawTextureFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   902
begin
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   903
DrawTextureFromRectDir(X, Y, W, H, r, SourceTexture, 1)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   904
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   905
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   906
procedure DrawTextureFromRectDir(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture; Dir: LongInt);
10324
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   907
var _l, _r, _t, _b: real;
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   908
    xw, yh: LongInt;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   909
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   910
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
   911
    exit;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   912
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   913
{if isDxAreaOffscreen(X, W) <> 0 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   914
    exit;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   915
if isDyAreaOffscreen(Y, H) <> 0 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   916
    exit;}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   917
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   918
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
   919
if (abs(X) > W) and ((abs(X + W / 2) - W / 2) * 2 > ViewWidth) then
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   920
    exit;
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
   921
if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) * 2 > ViewHeight) then
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
   922
    exit;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   923
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   924
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   925
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx;
10324
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   926
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   927
// if direction is mirrored, switch left and right
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   928
if Dir < 0 then
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   929
    begin
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   930
    _t:= _l;
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   931
    _l:= _r;
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   932
    _r:= _t;
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   933
    end;
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   934
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   935
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   936
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   937
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   938
10324
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   939
xw:= X + W;
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   940
yh:= Y + H;
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   941
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   942
VertexBuffer[0].X:= X;
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   943
VertexBuffer[0].Y:= Y;
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   944
VertexBuffer[1].X:= xw;
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   945
VertexBuffer[1].Y:= Y;
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   946
VertexBuffer[2].X:= xw;
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   947
VertexBuffer[2].Y:= yh;
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   948
VertexBuffer[3].X:= X;
5d90d8ca9657 tweak code of DrawTextureFromRectDir a bit, removing issue with different x offset depending on dir. also removing the workaround wrt that issue in the frozen hog code
sheepluva
parents: 10318
diff changeset
   949
VertexBuffer[3].Y:= yh;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   950
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   951
TextureBuffer[0].X:= _l;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   952
TextureBuffer[0].Y:= _t;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   953
TextureBuffer[1].X:= _r;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   954
TextureBuffer[1].Y:= _t;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   955
TextureBuffer[2].X:= _r;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   956
TextureBuffer[2].Y:= _b;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   957
TextureBuffer[3].X:= _l;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   958
TextureBuffer[3].Y:= _b;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   959
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   960
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   961
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id);
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
   962
SetVertexPointer(@VertexBuffer[0], 4);
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
   963
SetTexCoordPointer(@TextureBuffer[0], 4);
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   964
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
   965
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   966
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   967
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   968
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   969
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
   970
begin
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   971
    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
   972
end;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   973
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   974
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   975
begin
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   976
openglPushMatrix;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   977
openglTranslatef(X, Y, 0);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   978
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   979
if Scale <> 1.0 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   980
    openglScalef(Scale, Scale, 1);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   981
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   982
glBindTexture(GL_TEXTURE_2D, Texture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   983
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   984
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
   985
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
   986
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   987
UpdateModelviewProjection;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   988
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   989
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   990
openglPopMatrix;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   991
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
   992
UpdateModelviewProjection;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   993
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   994
10020
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   995
{ this contains tweaks in order to avoid land tile borders in blurry land mode }
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   996
procedure DrawTexture2(X, Y: LongInt; Texture: PTexture; Scale, Overlap: GLfloat);
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   997
var
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   998
    TextureBuffer: array [0..3] of TVertex2f;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   999
begin
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1000
openglPushMatrix;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1001
openglTranslatef(X, Y, 0);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1002
openglScalef(Scale, Scale, 1);
10020
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
  1003
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
  1004
glBindTexture(GL_TEXTURE_2D, Texture^.id);
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
  1005
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
  1006
TextureBuffer[0].X:= Texture^.tb[0].X + Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
  1007
TextureBuffer[0].Y:= Texture^.tb[0].Y + Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
  1008
TextureBuffer[1].X:= Texture^.tb[1].X - Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
  1009
TextureBuffer[1].Y:= Texture^.tb[1].Y + Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
  1010
TextureBuffer[2].X:= Texture^.tb[2].X - Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
  1011
TextureBuffer[2].Y:= Texture^.tb[2].Y - Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
  1012
TextureBuffer[3].X:= Texture^.tb[3].X + Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
  1013
TextureBuffer[3].Y:= Texture^.tb[3].Y - Overlap;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
  1014
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1015
SetVertexPointer(@Texture^.vb, 4);
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1016
SetTexCoordPointer(@TextureBuffer, 4);
10266
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
  1017
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
  1018
UpdateModelviewProjection;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1019
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1020
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1021
openglPopMatrix;
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  1022
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  1023
UpdateModelviewProjection;
10020
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
  1024
end;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
  1025
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1026
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1027
begin
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
  1028
    DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1029
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1030
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
  1031
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
  1032
var ft, fb, fl, fr: GLfloat;
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1033
    hw, hh, nx, ny: LongInt;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1034
begin
10431
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1035
// visibility check only under trivial conditions
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1036
if (Scale <= 1) then
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1037
    begin
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1038
    if Angle <> 0  then
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1039
        begin
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1040
        if (OffsetX = 0) and (OffsetY = 0) then
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1041
            begin
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1042
            // sized doubled because the sprite might occupy up to 1.4 * of it's
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1043
            // original size in each dimension, because it is rotated
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1044
            if isDxAreaOffscreen(X - w, 2 * w) <> 0 then
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1045
                exit;
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1046
            if isDYAreaOffscreen(Y - h, 2 * h) <> 0 then
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1047
                exit;
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1048
            end;
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1049
        end
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1050
    else
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1051
        begin
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1052
        if isDxAreaOffscreen(X + dir * trunc(OffsetX) - w div 2, w) <> 0 then
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1053
            exit;
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1054
        if isDYAreaOffscreen(Y + trunc(OffsetY) - h div 2, h) <> 0 then
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1055
            exit;
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1056
        end;
d8830bd7cb24 another small rendering tweak/fix
sheepluva
parents: 10429
diff changeset
  1057
    end;
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1058
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
  1059
{
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
  1060
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
  1061
if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * 2 > ViewWidth) then
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1062
    exit;
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
  1063
if (abs(Y) > H) and ((abs(Y + OffsetY - (cScreenHeight / 2)) - W / 2) * 2 > ViewHeight) then
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
  1064
    exit;
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
  1065
}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1066
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1067
openglPushMatrix;
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1068
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1069
openglTranslatef(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
  1070
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
  1071
if Dir = 0 then Dir:= 1;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1072
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1073
if Angle <> 0 then
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1074
    openglRotatef(Angle, 0, 0, Dir);
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1075
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1076
if (OffsetX <> 0) or (OffsetY <> 0) then
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1077
    openglTranslatef(Dir*OffsetX, OffsetY, 0);
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1078
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1079
if Scale <> 1.0 then
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1080
    openglScalef(Scale, Scale, 1);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1081
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1082
// Any reason for this call? And why only in t direction, not s?
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1083
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1084
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1085
if Dir > 0 then
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1086
    hw:=  w div 2
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1087
else
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1088
    hw:= -w div 2;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1089
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1090
hh:= h div 2;
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1091
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1092
nx:= Texture^.w div w; // number of horizontal frames
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
  1093
if nx = 0 then nx:= 1; // one frame is minimum
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1094
ny:= Texture^.h div h; // number of vertical frames
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
  1095
if ny = 0 then ny:= 1;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1096
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1097
ft:= (Frame mod ny) * Texture^.ry / ny;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1098
fb:= ((Frame mod ny) + 1) * Texture^.ry / ny;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1099
fl:= (Frame div ny) * Texture^.rx / nx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1100
fr:= ((Frame div ny) + 1) * Texture^.rx / nx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1101
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1102
glBindTexture(GL_TEXTURE_2D, Texture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1103
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1104
VertexBuffer[0].X:= -hw;
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1105
VertexBuffer[0].Y:= -hh;
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1106
VertexBuffer[1].X:=  hw;
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1107
VertexBuffer[1].Y:= -hh;
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1108
VertexBuffer[2].X:=  hw;
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1109
VertexBuffer[2].Y:=  hh;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1110
VertexBuffer[3].X:= -hw;
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
  1111
VertexBuffer[3].Y:=  hh;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1112
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1113
TextureBuffer[0].X:= fl;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1114
TextureBuffer[0].Y:= ft;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1115
TextureBuffer[1].X:= fr;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1116
TextureBuffer[1].Y:= ft;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1117
TextureBuffer[2].X:= fr;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1118
TextureBuffer[2].Y:= fb;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1119
TextureBuffer[3].X:= fl;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1120
TextureBuffer[3].Y:= fb;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1121
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1122
SetVertexPointer(@VertexBuffer[0], 4);
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1123
SetTexCoordPointer(@TextureBuffer[0], 4);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1124
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1125
UpdateModelviewProjection;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1126
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1127
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1128
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1129
openglPopMatrix;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1130
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  1131
UpdateModelviewProjection;
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  1132
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1133
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1134
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
  1135
procedure DrawSpriteRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1136
begin
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
  1137
    DrawTextureRotated(SpritesData[Sprite].Texture,
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1138
        SpritesData[Sprite].Width,
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1139
        SpritesData[Sprite].Height,
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1140
        X, Y, Dir, Angle)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1141
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1142
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
  1143
procedure DrawSpriteRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1144
begin
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1145
10312
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1146
if Angle <> 0  then
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1147
    begin
15056
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1148
    // Check the bounding circle
12898
8a40ce061d94 Machinegun. also tweaked ignore
alfadur
parents: 12886
diff changeset
  1149
    if isCircleOffscreen(X, Y, (sqr(SpritesData[Sprite].Width) + sqr(SpritesData[Sprite].Height)) div 4) then
10312
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1150
        exit;
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1151
    end
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1152
else
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1153
    begin
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1154
    if isDxAreaOffscreen(X - SpritesData[Sprite].Width div 2, SpritesData[Sprite].Width) <> 0 then
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1155
        exit;
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1156
    if isDYAreaOffscreen(Y - SpritesData[Sprite].Height div 2 , SpritesData[Sprite].Height) <> 0 then
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1157
        exit;
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1158
    end;
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1159
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1160
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1161
openglPushMatrix;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1162
openglTranslatef(X, Y, 0);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1163
10312
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1164
// mirror
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1165
if Dir < 0 then
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1166
    openglScalef(-1.0, 1.0, 1.0);
10312
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1167
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1168
// apply angle after (conditional) mirroring
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1169
if Angle <> 0  then
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
  1170
    openglRotatef(Angle, 0, 0, 1);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1171
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  1172
UpdateModelviewProjection;
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  1173
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1174
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1175
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1176
openglPopMatrix;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1177
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  1178
UpdateModelviewProjection;
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  1179
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1180
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1181
15056
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1182
procedure DrawSpriteRotatedFReal(Sprite: TSprite; X, Y: Real; Frame, Dir: LongInt; Angle: real);
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1183
begin
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1184
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1185
    if Angle <> 0  then
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1186
    begin
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1187
        // Check the bounding circle
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1188
        if isCircleOffscreen(round(X), round(Y), (sqr(SpritesData[Sprite].Width) + sqr(SpritesData[Sprite].Height)) div 4) then
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1189
            exit;
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1190
    end
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1191
    else
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1192
    begin
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1193
        if isDxAreaOffscreen(round(X) - SpritesData[Sprite].Width div 2, SpritesData[Sprite].Width) <> 0 then
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1194
            exit;
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1195
        if isDYAreaOffscreen(round(Y) - SpritesData[Sprite].Height div 2 , SpritesData[Sprite].Height) <> 0 then
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1196
            exit;
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1197
    end;
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1198
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1199
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1200
    openglPushMatrix;
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1201
    openglTranslatef(X, Y, 0);
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1202
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1203
// mirror
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1204
    if Dir < 0 then
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1205
        openglScalef(-1.0, 1.0, 1.0);
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1206
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1207
// apply angle after (conditional) mirroring
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1208
    if Angle <> 0  then
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1209
        openglRotatef(Angle, 0, 0, 1);
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1210
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1211
    UpdateModelviewProjection;
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1212
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1213
    DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1214
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1215
    openglPopMatrix;
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1216
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1217
    UpdateModelviewProjection;
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1218
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1219
end;
a315927a44b2 improve rope rendering
alfadur
parents: 14721
diff changeset
  1220
12119
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1221
procedure DrawSpritePivotedF(Sprite: TSprite; X, Y, Frame, Dir, PivotX, PivotY: LongInt; Angle: real);
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1222
begin
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1223
if Angle <> 0  then
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1224
    begin
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1225
    // Check the bounding circle 
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1226
    // Assuming the pivot point is inside the sprite's rectangle, the farthest possible point is 3/2 of its diagonal away from the center
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1227
    if isCircleOffscreen(X, Y, 9 * (sqr(SpritesData[Sprite].Width) + sqr(SpritesData[Sprite].Height)) div 4) then
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1228
        exit;
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1229
    end
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1230
else
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1231
    begin
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1232
    if isDxAreaOffscreen(X - SpritesData[Sprite].Width div 2, SpritesData[Sprite].Width) <> 0 then
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1233
        exit;
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1234
    if isDYAreaOffscreen(Y - SpritesData[Sprite].Height div 2 , SpritesData[Sprite].Height) <> 0 then
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1235
        exit;
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1236
    end;
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1237
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1238
openglPushMatrix;
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1239
openglTranslatef(X, Y, 0);
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1240
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1241
// mirror
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1242
if Dir < 0 then
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1243
    openglScalef(-1.0, 1.0, 1.0);
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1244
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1245
// apply rotation around the pivot after (conditional) mirroring
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1246
if Angle <> 0  then
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1247
    begin
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1248
    openglTranslatef(PivotX, PivotY, 0);
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1249
    openglRotatef(Angle, 0, 0, 1);
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1250
    openglTranslatef(-PivotX, -PivotY, 0);
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1251
    end;
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1252
15205
e7d7fe9f20e1 add missing GL2 support call
alfadur
parents: 15056
diff changeset
  1253
UpdateModelviewProjection;
e7d7fe9f20e1 add missing GL2 support call
alfadur
parents: 15056
diff changeset
  1254
12119
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1255
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1256
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1257
openglPopMatrix;
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  1258
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  1259
UpdateModelviewProjection;
12119
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1260
end;
3374e0f67f39 code changes to make the new bat animation work
alfadur
parents: 11824
diff changeset
  1261
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
  1262
procedure DrawTextureRotated(Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1263
begin
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1264
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1265
if isDxAreaOffscreen(X, 2 * hw) <> 0 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1266
    exit;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1267
if isDyAreaOffscreen(Y, 2 * hh) <> 0 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1268
    exit;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1269
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
  1270
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1271
{if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1272
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1273
if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1274
    exit;}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1275
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1276
openglPushMatrix;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1277
openglTranslatef(X, Y, 0);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1278
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1279
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
  1280
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
  1281
    hw:= - hw;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1282
    openglRotatef(Angle, 0, 0, -1);
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
  1283
    end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
  1284
else
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1285
    openglRotatef(Angle, 0, 0, 1);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1286
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
  1287
glBindTexture(GL_TEXTURE_2D, Texture^.id);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1288
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1289
VertexBuffer[0].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1290
VertexBuffer[0].Y:= -hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1291
VertexBuffer[1].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1292
VertexBuffer[1].Y:= -hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1293
VertexBuffer[2].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1294
VertexBuffer[2].Y:= hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1295
VertexBuffer[3].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1296
VertexBuffer[3].Y:= hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1297
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1298
SetVertexPointer(@VertexBuffer[0], 4);
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1299
SetTexCoordPointer(@Texture^.tb, 4);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1300
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1301
UpdateModelviewProjection;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1302
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1303
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1304
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1305
openglPopMatrix;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1306
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  1307
UpdateModelviewProjection;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1308
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1309
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  1310
procedure DrawSprite(Sprite: TSprite; X, Y, Frame: LongInt);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1311
var row, col, numFramesFirstCol: LongInt;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1312
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
  1313
    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
  1314
        exit;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  1315
    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
  1316
    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
  1317
    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
  1318
    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
  1319
end;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  1320
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  1321
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
  1322
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
  1323
begin
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  1324
    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
  1325
    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
  1326
    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
  1327
    r.h:= SpritesData[Sprite].Height;
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
  1328
    DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1329
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1330
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1331
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1332
var r: TSDL_Rect;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1333
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1334
r.x:= 0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1335
r.y:= 0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1336
r.w:= SpritesData[Sprite].Width;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1337
r.h:= SpritesData[Sprite].Height;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1338
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1339
if (X < LeftX) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1340
    r.x:= LeftX - X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1341
if (Y < TopY) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1342
    r.y:= TopY - Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1343
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1344
if (Y + SpritesData[Sprite].Height > BottomY) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1345
    r.h:= BottomY - Y + 1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1346
if (X + SpritesData[Sprite].Width > RightX) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1347
    r.w:= RightX - X + 1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1348
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9950
diff changeset
  1349
if (r.h < r.y) or (r.w < r.x) then
9792
59cde1e53ca5 This seems to be enough to fix the bug with sprGirder rendered in stripe
unc0rr
parents: 9666
diff changeset
  1350
    exit;
59cde1e53ca5 This seems to be enough to fix the bug with sprGirder rendered in stripe
unc0rr
parents: 9666
diff changeset
  1351
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1352
dec(r.h, r.y);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1353
dec(r.w, r.x);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1354
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
  1355
DrawTextureFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1356
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1357
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
  1358
procedure DrawTextureCentered(X, Top: LongInt; Source: PTexture);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1359
var scale: GLfloat;
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1360
    left : LongInt;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1361
begin
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1362
    // scale down if larger than screen
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1363
    if (Source^.w + 20) > cScreenWidth then
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1364
        begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1365
        scale:= cScreenWidth / (Source^.w + 20);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1366
        DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1367
        end
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1368
    else
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1369
        begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1370
        left:= X - Source^.w div 2;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1371
        if (not isAreaOffscreen(left, Top, Source^.w, Source^.h)) then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1372
            DrawTexture(left, Top, Source);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1373
        end;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1374
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1375
13572
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1376
// Same as below, but with color as LongWord
9557
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
  1377
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; color: LongWord); inline;
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
  1378
begin
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
  1379
DrawLine(X0, Y0, X1, Y1, Width, (color shr 24) and $FF, (color shr 16) and $FF, (color shr 8) and $FF, color and $FF)
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
  1380
end;
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
  1381
13572
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1382
// Draw line between 2 points
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1383
// X0, Y0: Start point
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1384
// X0, Y1: End point
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1385
// Width: Visual line width
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1386
// r, g, b, a: Color
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1387
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1388
begin
10360
c243b6a8ad9a some adjustments and support for mirrored world rendering. disabled atm though, I think it is more confusing than helping
sheepluva
parents: 10354
diff changeset
  1389
    openglPushMatrix();
c243b6a8ad9a some adjustments and support for mirrored world rendering. disabled atm though, I think it is more confusing than helping
sheepluva
parents: 10354
diff changeset
  1390
    openglTranslatef(WorldDx, WorldDy, 0);
c243b6a8ad9a some adjustments and support for mirrored world rendering. disabled atm though, I think it is more confusing than helping
sheepluva
parents: 10354
diff changeset
  1391
c243b6a8ad9a some adjustments and support for mirrored world rendering. disabled atm though, I think it is more confusing than helping
sheepluva
parents: 10354
diff changeset
  1392
    UpdateModelviewProjection;
c243b6a8ad9a some adjustments and support for mirrored world rendering. disabled atm though, I think it is more confusing than helping
sheepluva
parents: 10354
diff changeset
  1393
c243b6a8ad9a some adjustments and support for mirrored world rendering. disabled atm though, I think it is more confusing than helping
sheepluva
parents: 10354
diff changeset
  1394
    DrawLineOnScreen(X0, Y0, X1, Y1, Width, r, g, b, a);
c243b6a8ad9a some adjustments and support for mirrored world rendering. disabled atm though, I think it is more confusing than helping
sheepluva
parents: 10354
diff changeset
  1395
c243b6a8ad9a some adjustments and support for mirrored world rendering. disabled atm though, I think it is more confusing than helping
sheepluva
parents: 10354
diff changeset
  1396
    openglPopMatrix();
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  1397
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  1398
    UpdateModelviewProjection;
10360
c243b6a8ad9a some adjustments and support for mirrored world rendering. disabled atm though, I think it is more confusing than helping
sheepluva
parents: 10354
diff changeset
  1399
end;
c243b6a8ad9a some adjustments and support for mirrored world rendering. disabled atm though, I think it is more confusing than helping
sheepluva
parents: 10354
diff changeset
  1400
13572
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1401
// Same as below, but with color as a longword
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1402
procedure DrawLineWrapped(X0, Y0, X1, Y1, Width: Single; goesLeft: boolean; Wraps: LongWord; color: LongWord); inline;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1403
begin
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1404
DrawLineWrapped(X0, Y0, X1, Y1, Width, goesLeft, Wraps, (color shr 24) and $FF, (color shr 16) and $FF, (color shr 8) and $FF, color and $FF);
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1405
end;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1406
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1407
// Draw a line between 2 points, but it wraps around the
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1408
// world edge for a given number of times.
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1409
// goesLeft: true if the line direction from the start point is left
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1410
// Wraps: Number of times the line intersects the wrapping world edge
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1411
// r, g, b, a: color
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1412
procedure DrawLineWrapped(X0, Y0, X1, Y1, Width: Single; goesLeft: boolean; Wraps: LongWord; r, g, b, a: Byte);
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1413
var w: LongWord;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1414
    startX, startY, endX, endY: Single;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1415
    // total X and Y distance the line travels if you would unwrap it
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1416
    // with this we know the slope of the line.
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1417
    totalX, totalY: Single;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1418
    // x variable for the line formula
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1419
    x: Single;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1420
begin
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1421
    openglPushMatrix();
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1422
    openglTranslatef(WorldDx, WorldDy, 0);
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1423
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1424
    UpdateModelviewProjection;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1425
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1426
    startX:= X0;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1427
    startY:= Y0;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1428
    if (Wraps = 0) then
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1429
        begin
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1430
        // Wraps=0 is trivial: Just draw one direct connection
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1431
        endX:= X1;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1432
        endY:= Y1;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1433
        DrawLineOnScreen(startX, startY, endX, endY, Width, r, g, b, a);
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1434
        end
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1435
    else
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1436
        begin
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1437
        // A wrapping line is drawn using multiple line segments
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1438
        // which stop at the left and right border. We
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1439
        // calculate the points at which the line intersects with the border.
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1440
        // Then we draws all line segments.
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1441
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1442
        // Calculate position of first wrap point
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1443
        if goesLeft then
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1444
            begin
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1445
            endX:= LeftX;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1446
            totalX:= (RightX - X1) + (X0 - LeftX);
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1447
            x:= X0 - LeftX;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1448
            end
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1449
        else
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1450
            begin
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1451
            endX:= RightX;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1452
            totalX:= (RightX - X0) + (X1 - LeftX);
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1453
            x:= RightX - X0;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1454
            end;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1455
        if (Wraps >= 2) then
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1456
            totalX:= totalX + ((RightX - LeftX) * (Wraps-1));
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1457
        totalY:= Y1 - Y0;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1458
        // Calculate Y of first wrap point using the line formula
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1459
        endY:= Y0 + (totalY / totalX) * x;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1460
        // Draw line segment between starting point and first wrap point
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1461
        DrawLineOnScreen(startX, startY, endX, endY, Width, r, g, b, a);
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1462
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1463
        // Calculate and draw all remaining line segments
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1464
        for w:=1 to Wraps do
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1465
            begin
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1466
            startY:= endY;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1467
            if goesLeft then
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1468
                begin
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1469
                startX:= RightX;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1470
                if w < Wraps then
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1471
                    endX:= LeftX
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1472
                else
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1473
                    endX:= X1;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1474
                end
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1475
            else
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1476
                begin
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1477
                startX:= LeftX;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1478
                if w < Wraps then
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1479
                    endX:= RightX
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1480
                else
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1481
                    endX:= X1;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1482
                end;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1483
            if w < Wraps then
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1484
                begin
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1485
                x:= x + (RightX - LeftX);
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1486
                endY:= Y0 + (totalY / totalX) * x;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1487
                end
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1488
            else
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1489
                endY:= Y1;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1490
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1491
            DrawLineOnScreen(startX, startY, endX, endY, Width, r, g, b, a);
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1492
            end;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1493
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1494
        end;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1495
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1496
    openglPopMatrix();
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1497
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1498
    UpdateModelviewProjection;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1499
end;
a71e6856ffab Fix freeze ray not working through wrap world edge; add DrawLineWrapped
Wuzzy <Wuzzy2@mail.ru>
parents: 13512
diff changeset
  1500
10360
c243b6a8ad9a some adjustments and support for mirrored world rendering. disabled atm though, I think it is more confusing than helping
sheepluva
parents: 10354
diff changeset
  1501
procedure DrawLineOnScreen(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
c243b6a8ad9a some adjustments and support for mirrored world rendering. disabled atm though, I think it is more confusing than helping
sheepluva
parents: 10354
diff changeset
  1502
begin
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1503
    glEnable(GL_LINE_SMOOTH);
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1504
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1505
    EnableTexture(False);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1506
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1507
    glLineWidth(Width);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1508
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1509
    Tint(r, g, b, a);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1510
    VertexBuffer[0].X:= X0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1511
    VertexBuffer[0].Y:= Y0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1512
    VertexBuffer[1].X:= X1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1513
    VertexBuffer[1].Y:= Y1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1514
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1515
    SetVertexPointer(@VertexBuffer[0], 2);
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1516
    glDrawArrays(GL_LINES, 0, 2);
10360
c243b6a8ad9a some adjustments and support for mirrored world rendering. disabled atm though, I think it is more confusing than helping
sheepluva
parents: 10354
diff changeset
  1517
    untint();
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1518
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1519
    EnableTexture(True);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1520
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1521
    glDisable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1522
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1523
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1524
procedure DrawRect(rect: TSDL_Rect; r, g, b, a: Byte; Fill: boolean);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1525
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
  1526
// do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
  1527
if (abs(rect.x) > rect.w) and ((abs(rect.x + rect.w / 2) - rect.w / 2) * 2 > ViewWidth) then
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1528
    exit;
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
  1529
if (abs(rect.y) > rect.h) and ((abs(rect.y + rect.h / 2 - (cScreenHeight / 2)) - rect.h / 2) * 2 > ViewHeight) then
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
  1530
    exit;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1531
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1532
EnableTexture(False);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1533
Tint(r, g, b, a);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1534
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1535
with rect do
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1536
begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1537
    VertexBuffer[0].X:= x;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1538
    VertexBuffer[0].Y:= y;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1539
    VertexBuffer[1].X:= x + w;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1540
    VertexBuffer[1].Y:= y;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1541
    VertexBuffer[2].X:= x + w;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1542
    VertexBuffer[2].Y:= y + h;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1543
    VertexBuffer[3].X:= x;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1544
    VertexBuffer[3].Y:= y + h;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1545
end;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1546
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1547
SetVertexPointer(@VertexBuffer[0], 4);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1548
if Fill then
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1549
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4)
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1550
else
10328
1eaae604d7a4 more tweaking
sheepluva
parents: 10327
diff changeset
  1551
    begin
1eaae604d7a4 more tweaking
sheepluva
parents: 10327
diff changeset
  1552
    glLineWidth(1);
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1553
    glDrawArrays(GL_LINE_LOOP, 0, 4);
10328
1eaae604d7a4 more tweaking
sheepluva
parents: 10327
diff changeset
  1554
    end;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1555
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1556
untint;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1557
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1558
EnableTexture(True);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1559
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1560
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1561
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
  1562
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
  1563
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
  1564
    Tint(r, g, b, a);
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9950
diff changeset
  1565
    DrawCircle(X, Y, Radius, Width);
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1566
    untint;
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
  1567
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
  1568
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
  1569
procedure DrawCircle(X, Y, Radius, Width: LongInt);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1570
var
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1571
    i: LongInt;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1572
begin
10328
1eaae604d7a4 more tweaking
sheepluva
parents: 10327
diff changeset
  1573
    i:= Radius + Width;
1eaae604d7a4 more tweaking
sheepluva
parents: 10327
diff changeset
  1574
    if isDxAreaOffscreen(X - i, 2 * i) <> 0 then
1eaae604d7a4 more tweaking
sheepluva
parents: 10327
diff changeset
  1575
        exit;
1eaae604d7a4 more tweaking
sheepluva
parents: 10327
diff changeset
  1576
    if isDyAreaOffscreen(Y - i, 2 * i) <> 0 then
1eaae604d7a4 more tweaking
sheepluva
parents: 10327
diff changeset
  1577
        exit;
1eaae604d7a4 more tweaking
sheepluva
parents: 10327
diff changeset
  1578
5561
dfbe55237c64 Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents: 5559
diff changeset
  1579
    for i := 0 to 59 do begin
10328
1eaae604d7a4 more tweaking
sheepluva
parents: 10327
diff changeset
  1580
        VertexBuffer[i].X := X + Radius*cos(i*pi/30);
1eaae604d7a4 more tweaking
sheepluva
parents: 10327
diff changeset
  1581
        VertexBuffer[i].Y := Y + Radius*sin(i*pi/30);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1582
    end;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1583
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1584
    EnableTexture(False);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1585
    glEnable(GL_LINE_SMOOTH);
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1586
    //openglPushMatrix;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1587
    glLineWidth(Width);
10328
1eaae604d7a4 more tweaking
sheepluva
parents: 10327
diff changeset
  1588
    SetVertexPointer(@VertexBuffer[0], 60);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1589
    glDrawArrays(GL_LINE_LOOP, 0, 60);
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1590
    //openglPopMatrix;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1591
    EnableTexture(True);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1592
    glDisable(GL_LINE_SMOOTH);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1593
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1594
10871
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1595
procedure DrawCircleFilled(X, Y, Radius: LongInt; r, g, b, a: Byte);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1596
var
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1597
    i: LongInt;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1598
begin
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1599
    VertexBuffer[0].X := X;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1600
    VertexBuffer[0].Y := Y;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1601
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1602
    for i := 1 to 19 do begin
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1603
        VertexBuffer[i].X := X + Radius*cos(i*pi/9);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1604
        VertexBuffer[i].Y := Y + Radius*sin(i*pi/9);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1605
    end;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1606
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1607
    EnableTexture(False);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1608
    Tint(r, g, b, a);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1609
    SetVertexPointer(@VertexBuffer[0], 20);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1610
    glDrawArrays(GL_TRIANGLE_FAN, 0, 20);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1611
    Untint();
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1612
    EnableTexture(True);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  1613
end;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1614
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1615
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1616
const VertexBuffer: array [0..3] of TVertex2f = (
7069
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
  1617
        (X: -16; Y: -16),
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
  1618
        (X:  16; Y: -16),
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
  1619
        (X:  16; Y:  16),
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
  1620
        (X: -16; Y:  16));
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1621
var l, r, t, b: real;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1622
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
  1623
    // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
  1624
    if (abs(X) > 32) and ((abs(X) - 16) * 2 > ViewWidth) then
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1625
        exit;
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
  1626
    if (abs(Y) > 32) and ((abs(Y - cScreenHeight / 2) - 16) * 2 > ViewHeight) then
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1627
        exit;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1628
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1629
    t:= Pos * 32 / HHTexture^.h;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1630
    b:= (Pos + 1) * 32 / HHTexture^.h;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1631
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1632
    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
  1633
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
  1634
        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
  1635
        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
  1636
        end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
  1637
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
  1638
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
  1639
        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
  1640
        r:= (Step + 1) * 32 / HHTexture^.w
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1641
    end;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1642
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1643
    openglPushMatrix();
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1644
    openglTranslatef(X, Y, 0);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1645
    openglRotatef(Angle, 0, 0, 1);
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1646
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1647
    glBindTexture(GL_TEXTURE_2D, HHTexture^.id);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1648
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1649
    TextureBuffer[0].X:= l;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1650
    TextureBuffer[0].Y:= t;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1651
    TextureBuffer[1].X:= r;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1652
    TextureBuffer[1].Y:= t;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1653
    TextureBuffer[2].X:= r;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1654
    TextureBuffer[2].Y:= b;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1655
    TextureBuffer[3].X:= l;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1656
    TextureBuffer[3].Y:= b;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1657
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1658
    SetVertexPointer(@VertexBuffer[0], 4);
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1659
    SetTexCoordPointer(@TextureBuffer[0], 4);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1660
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1661
    UpdateModelviewProjection;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1662
10327
c3770d87311b reuse buffers
sheepluva
parents: 10326
diff changeset
  1663
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1664
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1665
    openglPopMatrix;
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  1666
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  1667
    UpdateModelviewProjection;
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1668
end;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1669
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1670
procedure DrawScreenWidget(widget: POnScreenWidget);
6992
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
  1671
{$IFDEF USE_TOUCH_INTERFACE}
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1672
var alpha: byte = $FF;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1673
begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1674
with widget^ do
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1675
    begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1676
    if (fadeAnimStart <> 0) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1677
        begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1678
        if RealTicks > (fadeAnimStart + FADE_ANIM_TIME) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1679
            fadeAnimStart:= 0
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1680
        else
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
  1681
            if show then
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1682
                alpha:= Byte(trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF))
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
  1683
            else
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1684
                alpha:= Byte($FF - trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF));
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1685
        end;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1686
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1687
    with moveAnim do
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1688
        if animate then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1689
            if RealTicks > (startTime + MOVE_ANIM_TIME) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1690
                begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1691
                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
  1692
                animate:= false;
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
  1693
                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
  1694
                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
  1695
                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
  1696
                active.y:= active.y + (target.y - source.y);
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1697
                end
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1698
            else
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1699
                begin
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
  1700
                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
  1701
                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
  1702
                end;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1703
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1704
    if show or (fadeAnimStart <> 0) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1705
        begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1706
        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
  1707
        DrawTexture(frame.x, frame.y, spritesData[sprite].Texture, buttonScale);
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1708
        untint;
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1709
        end;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1710
    end;
6992
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
  1711
{$ELSE}
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
  1712
begin
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
  1713
widget:= widget; // avoid hint
6689
98a239848ba2 wops, added an extra USE_TOUCH_INTERFACE
Xeli
parents: 6688
diff changeset
  1714
{$ENDIF}
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1715
end;
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1716
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1717
procedure BeginWater;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1718
begin
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1719
{$IFDEF GL2}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1720
    glUseProgram(shaderWater);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1721
    uCurrentMVPLocation:=uWaterMVPLocation;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1722
    UpdateModelviewProjection;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1723
{$ENDIF}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1724
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1725
    openglUseColorOnly(true);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1726
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1727
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1728
procedure EndWater;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1729
begin
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1730
{$IFDEF GL2}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1731
    glUseProgram(shaderMain);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1732
    uCurrentMVPLocation:=uMainMVPLocation;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1733
    UpdateModelviewProjection;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1734
{$ENDIF}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1735
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1736
    openglUseColorOnly(false);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1737
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1738
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1739
procedure PrepareVbForWater(
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1740
    WithWalls: Boolean;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1741
    InTopY, OutTopY, InLeftX, OutLeftX, InRightX, OutRightX, BottomY: LongInt;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1742
    out first, count: LongInt);
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1743
10331
cb6c33839d2a cleanup and lol
sheepluva
parents: 10330
diff changeset
  1744
var firsti, afteri, lol: LongInt;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1745
begin
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1746
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1747
    // We will draw both bottom water and the water walls with a single call,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1748
    // by rendering a GL_TRIANGLE_STRIP of eight points.
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1749
    //
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1750
    // GL_TRIANGLE_STRIP works like this: "always create triangle between
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1751
    // newest point and the two points that were specified before it."
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1752
    //
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1753
    // To get the result we want we will order the points like this:
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1754
    //                                                                     ^ -Y
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1755
    //                                                                     |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1756
    //       0-------1         7-------6   <--------------------- OutTopY -|
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1757
    //       |      /|         |     _/|                                   |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1758
    //       |     / |         |    /  |                                   |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1759
    //       |    /  |         |  _/   |                                   |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1760
    //       |   /   |         | /     |                                   |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1761
    //       |  /  _.3---------5{      |   <--------------------- InTopY --|
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1762
    //       | / _/   `---.___   `--._ |                                   |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1763
    //       |/_/             `---.___\|                                   |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1764
    //       2-------------------------4   <--------------------- BottomY -|
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1765
    //                                                                     |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1766
    //       ^       ^         ^       ^                                   V +Y
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1767
    //       |       |         |       |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1768
    //       |       |         |       |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1769
    //       |       |         |       |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1770
    //       |       |         |       |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1771
    //       |       |         |       |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1772
    //       |       |         |       |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1773
    //       |       |         |       |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1774
    //  OutLeftX  InLeftX  InRightX  OutRightX
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1775
    //       |       |         |       |
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1776
    // <---------------------------------------->
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1777
    //     -X                              +X
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1778
    //
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1779
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1780
firsti:= -1;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1781
afteri:=  0;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1782
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1783
if InTopY < 0 then
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1784
    InTopY:= 0;
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1785
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1786
if not WithWalls then
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1787
    begin
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1788
    // if no walls are needed, then bottom water surface spans full length
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1789
    InLeftX := OutLeftX;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1790
    InRightX:= OutRightX;
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1791
    end
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1792
else
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1793
    begin
10873
84c00d1127d6 still messing with rendering
sheepluva
parents: 10871
diff changeset
  1794
84c00d1127d6 still messing with rendering
sheepluva
parents: 10871
diff changeset
  1795
    // animate water walls raise animation at start of game
84c00d1127d6 still messing with rendering
sheepluva
parents: 10871
diff changeset
  1796
    if GameTicks < 2000 then
84c00d1127d6 still messing with rendering
sheepluva
parents: 10871
diff changeset
  1797
        lol:= 2000 - GameTicks
84c00d1127d6 still messing with rendering
sheepluva
parents: 10871
diff changeset
  1798
    else
84c00d1127d6 still messing with rendering
sheepluva
parents: 10871
diff changeset
  1799
        lol:= 0;
84c00d1127d6 still messing with rendering
sheepluva
parents: 10871
diff changeset
  1800
10333
e1253205eb7e fix search&replace whoopsy
sheepluva
parents: 10331
diff changeset
  1801
    if InLeftX > ViewLeftX then
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1802
        begin
10331
cb6c33839d2a cleanup and lol
sheepluva
parents: 10330
diff changeset
  1803
        VertexBuffer[0].X:= OutLeftX - lol;
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1804
        VertexBuffer[0].Y:= OutTopY;
10331
cb6c33839d2a cleanup and lol
sheepluva
parents: 10330
diff changeset
  1805
        VertexBuffer[1].X:= InLeftX - lol;
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1806
        VertexBuffer[1].Y:= OutTopY;
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1807
        // shares vertices 2 and 3 with bottom water
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1808
        firsti:= 0;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1809
        afteri:= 4;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1810
        end;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1811
10333
e1253205eb7e fix search&replace whoopsy
sheepluva
parents: 10331
diff changeset
  1812
    if InRightX < ViewRightX then
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1813
        begin
10331
cb6c33839d2a cleanup and lol
sheepluva
parents: 10330
diff changeset
  1814
        VertexBuffer[6].X:= OutRightX + lol;
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1815
        VertexBuffer[6].Y:= OutTopY;
10331
cb6c33839d2a cleanup and lol
sheepluva
parents: 10330
diff changeset
  1816
        VertexBuffer[7].X:= InRightX + lol;
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1817
        VertexBuffer[7].Y:= OutTopY;
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1818
        // shares vertices 4 and 5 with bottom water
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1819
        if firsti < 0 then
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1820
            firsti:= 4;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1821
        afteri:= 8;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1822
        end;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1823
    end;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1824
10333
e1253205eb7e fix search&replace whoopsy
sheepluva
parents: 10331
diff changeset
  1825
if InTopY < ViewBottomY then
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1826
    begin
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1827
    // shares vertices 2-5 with water walls
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1828
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1829
    // starts at vertex 2
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1830
    if (firsti < 0) or (firsti > 2) then
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1831
        firsti:= 2;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1832
    // ends at vertex 5
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1833
    if afteri < 6 then
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1834
        afteri:= 6;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1835
    end;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1836
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1837
if firsti < 0 then
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1838
    begin
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1839
    // nothing to draw at all!
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1840
    first:= -1;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1841
    count:= 0;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1842
    exit;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1843
    end;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
  1844
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1845
if firsti < 4 then
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1846
    begin
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1847
    VertexBuffer[2].X:= OutLeftX;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1848
    VertexBuffer[2].Y:= BottomY;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1849
    VertexBuffer[3].X:= InLeftX;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1850
    VertexBuffer[3].Y:= InTopY;
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1851
    end;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1852
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1853
if afteri > 4 then
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1854
    begin
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1855
    VertexBuffer[4].X:= OutRightX;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1856
    VertexBuffer[4].Y:= BottomY;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1857
    VertexBuffer[5].X:= InRightX;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1858
    VertexBuffer[5].Y:= InTopY;
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1859
    end;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1860
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1861
// first index to draw in vertex buffer
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1862
first:= firsti;
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1863
// number of points to draw
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1864
count:= afteri - firsti;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1865
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1866
end;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1867
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1868
procedure DrawWater(Alpha: byte; OffsetY, OffsetX: LongInt);
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1869
var first, count: LongInt;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1870
begin
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1871
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1872
if (WorldEdge <> weSea) then
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1873
    PrepareVbForWater(false,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1874
        OffsetY + WorldDy + cWaterLine, 0,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1875
        0, ViewLeftX,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1876
        0, ViewRightX,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1877
        ViewBottomY,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1878
        first, count)
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1879
else
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1880
    PrepareVbForWater(true,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1881
        OffsetY + WorldDy + cWaterLine, ViewTopY,
14303
6015b74eea55 overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents: 13572
diff changeset
  1882
        leftX  + WorldDx - OffsetX, ViewLeftX,
6015b74eea55 overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents: 13572
diff changeset
  1883
        rightX + WorldDx + OffsetX, ViewRightX,
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1884
        ViewBottomY,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1885
        first, count);
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1886
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1887
// quit if there's nothing to draw (nothing in view)
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1888
if count < 1 then
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1889
    exit;
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1890
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1891
// drawing time
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1892
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1893
UpdateModelviewProjection;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1894
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1895
BeginWater;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1896
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1897
if SuddenDeathDmg then
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1898
    begin // only set alpha if it differs from what we want
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1899
    if SDWaterColorArray[0].a <> Alpha then
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1900
        begin
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1901
        SDWaterColorArray[0].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1902
        SDWaterColorArray[1].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1903
        SDWaterColorArray[2].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1904
        SDWaterColorArray[3].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1905
        SDWaterColorArray[4].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1906
        SDWaterColorArray[5].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1907
        SDWaterColorArray[6].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1908
        SDWaterColorArray[7].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1909
        end;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1910
    SetColorPointer(@SDWaterColorArray[0], 8);
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1911
    end
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1912
else
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1913
    begin
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1914
    if WaterColorArray[0].a <> Alpha then
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1915
        begin
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1916
        WaterColorArray[0].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1917
        WaterColorArray[1].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1918
        WaterColorArray[2].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1919
        WaterColorArray[3].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1920
        WaterColorArray[4].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1921
        WaterColorArray[5].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1922
        WaterColorArray[6].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1923
        WaterColorArray[7].a := Alpha;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1924
        end;
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1925
    SetColorPointer(@WaterColorArray[0], 8);
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1926
    end;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1927
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1928
SetVertexPointer(@VertexBuffer[0], 8);
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1929
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1930
glDrawArrays(GL_TRIANGLE_STRIP, first, count);
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1931
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1932
EndWater;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1933
10325
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1934
{$IFNDEF GL2}
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1935
// must not be Tint() as color array seems to stay active and color reset is required
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1936
glColor4ub($FF, $FF, $FF, $FF);
7315870716f2 tweak/refactor how water is drawn
sheepluva
parents: 10324
diff changeset
  1937
{$ENDIF}
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1938
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1939
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1940
procedure DrawWaves(Dir, dX, dY, oX: LongInt; tnt: Byte);
12189
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1941
var first, count, topy, lx, rx, spriteHeight, spriteWidth, waterSpeed: LongInt;
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1942
    waterFrames, waterFrameTicks, frame : LongWord;
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1943
    lw, nWaves, shift, realHeight: GLfloat;
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1944
    sprite: TSprite;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1945
begin
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1946
// note: spriteHeight is the Height of the wave sprite while
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1947
//       cWaveHeight describes how many pixels of it will be above waterline
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1948
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1949
if SuddenDeathDmg then
12189
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1950
    begin
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1951
    sprite:= sprSDWater;
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1952
    waterFrames:= watSDFrames;
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1953
    waterFrameTicks:= watSDFrameTicks;
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1954
    waterSpeed:= watSDMove;
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1955
    end
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1956
else
12189
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1957
    begin
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1958
    sprite:= sprWater;
12189
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1959
    waterFrames:= watFrames;
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1960
    waterFrameTicks:= watFrameTicks;
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1961
    waterSpeed:= watMove;
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1962
    end;
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1963
 
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1964
spriteHeight:= SpritesData[sprite].Height;
12189
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  1965
realHeight:= SpritesData[sprite].Texture^.ry / waterFrames;
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1966
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1967
// shift parameters by wave height
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1968
// ( ox and dy are used to create different horizontal and vertical offsets
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1969
//   between wave layers )
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1970
dY:= -cWaveHeight + dy;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1971
ox:= -cWaveHeight + ox;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1972
14303
6015b74eea55 overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents: 13572
diff changeset
  1973
lx:= leftX  + WorldDx - ox;
6015b74eea55 overall, using LongInt for leftX/rightX results in fewer casts, since most comparisons are against ints.
nemo
parents: 13572
diff changeset
  1974
rx:= rightX + WorldDx + ox;
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1975
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1976
topy:= cWaterLine + WorldDy + dY;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1977
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1978
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1979
if (WorldEdge <> weSea) then
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1980
    PrepareVbForWater(false,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1981
        topy, 0,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1982
        0, ViewLeftX,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1983
        0, ViewRightX,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1984
        topy + spriteHeight,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1985
        first, count)
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1986
else
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1987
    PrepareVbForWater(true,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1988
        topy, ViewTopY,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1989
        lx, lx - spriteHeight,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1990
        rx, rx + spriteHeight,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1991
        topy + spriteHeight,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1992
        first, count);
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1993
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1994
// quit if there's nothing to draw (nothing in view)
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1995
if count < 1 then
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1996
    exit;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1997
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1998
if SuddenDeathDmg then
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  1999
    Tint(LongInt(tnt) * SDWaterColorArray[1].r div 255 + 255 - tnt,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2000
         LongInt(tnt) * SDWaterColorArray[1].g div 255 + 255 - tnt,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2001
         LongInt(tnt) * SDWaterColorArray[1].b div 255 + 255 - tnt,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2002
         255
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2003
    )
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2004
else
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2005
    Tint(LongInt(tnt) * WaterColorArray[1].r div 255 + 255 - tnt,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2006
         LongInt(tnt) * WaterColorArray[1].g div 255 + 255 - tnt,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2007
         LongInt(tnt) * WaterColorArray[1].b div 255 + 255 - tnt,
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2008
         255
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2009
    );
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2010
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2011
if WorldEdge = weSea then
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2012
    begin
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2013
    lw:= playWidth;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2014
    dX:= ox;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2015
    end
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2016
else
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2017
    begin
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2018
    lw:= ViewWidth;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2019
    dx:= dx - WorldDx;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2020
    end;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2021
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2022
spriteWidth:= SpritesData[sprite].Width;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2023
nWaves:= lw / spriteWidth;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2024
    shift:= - nWaves / 2;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2025
12189
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  2026
if waterFrames > 1 then
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  2027
	frame:= RealTicks div waterFrameTicks mod waterFrames
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  2028
else
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  2029
	frame:= 0;
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  2030
12282
c0ace4bf45fa Change water speed range for better precision
KoBeWi <kobewi4e@gmail.com>
parents: 12281
diff changeset
  2031
TextureBuffer[3].X:= shift + ((LongInt((RealTicks * waterSpeed div 100) shr 6) * Dir + dX) mod spriteWidth) / (spriteWidth - 1);
12189
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  2032
TextureBuffer[3].Y:= frame * realHeight;
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2033
TextureBuffer[5].X:= TextureBuffer[3].X + nWaves;
12189
31184d9b9bfc Water can now be animated
KoBeWi <kobewi4e@gmail.com>
parents: 12119
diff changeset
  2034
TextureBuffer[5].Y:= frame * realHeight;
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2035
TextureBuffer[4].X:= TextureBuffer[5].X;
12281
6bf23d89dc43 Fix broken sprites on animated water edges
KoBeWi <kobewi4e@gmail.com>
parents: 12190
diff changeset
  2036
TextureBuffer[4].Y:= (frame+1) * realHeight;
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2037
TextureBuffer[2].X:= TextureBuffer[3].X;
12281
6bf23d89dc43 Fix broken sprites on animated water edges
KoBeWi <kobewi4e@gmail.com>
parents: 12190
diff changeset
  2038
TextureBuffer[2].Y:= (frame+1) * realHeight;
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2039
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2040
if (WorldEdge = weSea) then
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2041
    begin
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2042
    nWaves:= (topy - ViewTopY) / spriteWidth;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2043
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2044
    // left side
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2045
    TextureBuffer[1].X:= TextureBuffer[3].X - nWaves;
12281
6bf23d89dc43 Fix broken sprites on animated water edges
KoBeWi <kobewi4e@gmail.com>
parents: 12190
diff changeset
  2046
    TextureBuffer[1].Y:= frame * realHeight;
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2047
    TextureBuffer[0].X:= TextureBuffer[1].X;
12281
6bf23d89dc43 Fix broken sprites on animated water edges
KoBeWi <kobewi4e@gmail.com>
parents: 12190
diff changeset
  2048
    TextureBuffer[0].Y:= (frame+1) * realHeight;
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2049
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2050
    // right side
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2051
    TextureBuffer[7].X:= TextureBuffer[5].X + nWaves;
12281
6bf23d89dc43 Fix broken sprites on animated water edges
KoBeWi <kobewi4e@gmail.com>
parents: 12190
diff changeset
  2052
    TextureBuffer[7].Y:= frame * realHeight;
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2053
    TextureBuffer[6].X:= TextureBuffer[7].X;
12281
6bf23d89dc43 Fix broken sprites on animated water edges
KoBeWi <kobewi4e@gmail.com>
parents: 12190
diff changeset
  2054
    TextureBuffer[6].Y:= (frame+1) * realHeight;
10330
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2055
    end;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2056
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2057
glBindTexture(GL_TEXTURE_2D, SpritesData[sprite].Texture^.id);
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2058
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2059
SetVertexPointer(@VertexBuffer[0], 8);
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2060
SetTexCoordPointer(@TextureBuffer[0], 8);
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2061
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2062
glDrawArrays(GL_TRIANGLE_STRIP, first, count);
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2063
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2064
untint;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2065
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2066
end;
3ec09243cb55 move DrawWaves to uRender
sheepluva
parents: 10328
diff changeset
  2067
10255
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  2068
procedure openglTint(r, g, b, a: Byte); inline;
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  2069
{$IFDEF GL2}
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  2070
const
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  2071
    scale:Real = 1.0/255.0;
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  2072
{$ENDIF}
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  2073
begin
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  2074
    {$IFDEF GL2}
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  2075
    glUniform4f(uMainTintLocation, r*scale, g*scale, b*scale, a*scale);
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  2076
    {$ELSE}
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  2077
    glColor4ub(r, g, b, a);
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  2078
    {$ENDIF}
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  2079
end;
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  2080
14721
89dd60565041 remove one of the 2 tint inlines
nemo
parents: 14303
diff changeset
  2081
procedure Tint(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
  2082
var
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  2083
    nc, tw: Longword;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  2084
begin
9557
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
  2085
    nc:= (r shl 24) or (g shl 16) or (b shl 8) or a;
5559
a937d43a032f Use local scope global var instead
unc0rr
parents: 5441
diff changeset
  2086
10326
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
  2087
    if nc = LastTint then
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  2088
        exit;
5559
a937d43a032f Use local scope global var instead
unc0rr
parents: 5441
diff changeset
  2089
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  2090
    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
  2091
        begin
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  2092
        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
  2093
        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
  2094
            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
  2095
        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
  2096
        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
  2097
        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
  2098
        end;
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5235
diff changeset
  2099
10255
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  2100
    openglTint(r, g, b, a);
10326
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
  2101
    LastTint:= nc;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  2102
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  2103
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  2104
procedure Tint(c: Longword); inline;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  2105
begin
10326
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
  2106
    if c = LastTint then exit;
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  2107
    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
  2108
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  2109
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  2110
procedure untint(); inline;
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  2111
begin
10326
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
  2112
    if cWhiteColor = LastTint then exit;
10255
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  2113
    openglTint($FF, $FF, $FF, $FF);
10326
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
  2114
    LastTint:= cWhiteColor;
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  2115
end;
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  2116
12886
a089326f0e16 fix crosshair rendering in GL2 mode
sheepluva
parents: 12885
diff changeset
  2117
procedure setTintAdd(enable: boolean); inline;
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  2118
begin
12886
a089326f0e16 fix crosshair rendering in GL2 mode
sheepluva
parents: 12885
diff changeset
  2119
    {$IFDEF GL2}
a089326f0e16 fix crosshair rendering in GL2 mode
sheepluva
parents: 12885
diff changeset
  2120
        if enable then
a089326f0e16 fix crosshair rendering in GL2 mode
sheepluva
parents: 12885
diff changeset
  2121
            glUniform1i(glGetUniformLocation(shaderMain, pchar('tintAdd')), 1)
a089326f0e16 fix crosshair rendering in GL2 mode
sheepluva
parents: 12885
diff changeset
  2122
        else
a089326f0e16 fix crosshair rendering in GL2 mode
sheepluva
parents: 12885
diff changeset
  2123
            glUniform1i(glGetUniformLocation(shaderMain, pchar('tintAdd')), 0);
a089326f0e16 fix crosshair rendering in GL2 mode
sheepluva
parents: 12885
diff changeset
  2124
    {$ELSE}
a089326f0e16 fix crosshair rendering in GL2 mode
sheepluva
parents: 12885
diff changeset
  2125
    if enable then
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  2126
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD)
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  2127
    else
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  2128
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
12886
a089326f0e16 fix crosshair rendering in GL2 mode
sheepluva
parents: 12885
diff changeset
  2129
    {$ENDIF}
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  2130
end;
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  2131
10871
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2132
procedure ChangeDepth(rm: TRenderMode; d: GLfloat);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2133
var tmp: LongInt;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2134
begin
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2135
{$IFNDEF USE_S3D_RENDERING}
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2136
    rm:= rm; d:= d; tmp:= tmp; // avoid hint
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2137
{$ELSE}
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2138
    d:= d / 5;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2139
    if rm = rmDefault then
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2140
        exit
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2141
    else if rm = rmLeftEye then
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2142
        d:= -d;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2143
    cStereoDepth:= cStereoDepth + d;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2144
    openglTranslProjMatrix(d, 0, 0);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2145
    tmp:= round(d / cScaleFactor * cScreenWidth);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2146
    ViewLeftX := ViewLeftX  - tmp;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2147
    ViewRightX:= ViewRightX - tmp;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2148
{$ENDIF}
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2149
end;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2150
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2151
procedure ResetDepth(rm: TRenderMode);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2152
var tmp: LongInt;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2153
begin
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2154
{$IFNDEF USE_S3D_RENDERING}
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2155
    rm:= rm; tmp:= tmp; // avoid hint
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2156
{$ELSE}
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2157
    if rm = rmDefault then
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2158
        exit;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2159
    openglTranslProjMatrix(-cStereoDepth, 0, 0);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2160
    tmp:= round(cStereoDepth / cScaleFactor * cScreenWidth);
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2161
    ViewLeftX := ViewLeftX  + tmp;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2162
    ViewRightX:= ViewRightX + tmp;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2163
    cStereoDepth:= 0;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2164
{$ENDIF}
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2165
end;
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2166
570af168cc74 rendering tweaks cont.
sheepluva
parents: 10870
diff changeset
  2167
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  2168
procedure initModule;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  2169
begin
10326
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
  2170
    LastTint:= cWhiteColor + 1;
12885
dab60d247b75 also put GL2 fixes into default
sheepluva
parents: 12621
diff changeset
  2171
{$IFNDEF GL2}
10326
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
  2172
    LastColorPointer    := nil;
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
  2173
    LastTexCoordPointer := nil;
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
  2174
    LastVertexPointer   := nil;
1748eed62a95 render tweaks
sheepluva
parents: 10325
diff changeset
  2175
{$ENDIF}
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  2176
end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  2177
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  2178
procedure freeModule;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  2179
begin
15381
c117e17b90bc flag some of the renderstringtex which are taking up a ton of processing time with --stats-only and pas2c
nemo
parents: 15205
diff changeset
  2180
    if cOnlyStats then exit;
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  2181
{$IFDEF GL2}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  2182
    glDeleteProgram(shaderMain);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  2183
    glDeleteProgram(shaderWater);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  2184
    glDeleteBuffers(1, @vBuffer);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  2185
    glDeleteBuffers(1, @tBuffer);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  2186
    glDeleteBuffers(1, @cBuffer);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  2187
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  2188
end;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  2189
end.