hedgewars/uRender.pas
author sheepluva
Wed, 18 Jun 2014 01:37:28 +0200
changeset 10324 5d90d8ca9657
parent 10318 c2e81eea375f
child 10325 7315870716f2
permissions -rw-r--r--
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
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
9998
736015b847e3 update copyright to 2014
sheepluva
parents: 9792
diff changeset
     3
 * Copyright (c) 2004-2014 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);
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
    37
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    38
procedure DrawTexture           (X, Y: LongInt; Texture: PTexture); inline;
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    39
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
    40
procedure DrawTexture2          (X, Y: LongInt; Texture: PTexture; Scale, Overlap: GLfloat);
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    41
procedure DrawTextureFromRect   (X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    42
procedure DrawTextureFromRect   (X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
    43
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
    44
procedure DrawTextureCentered   (X, Top: LongInt; Source: PTexture);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    45
procedure DrawTextureF          (Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    46
procedure DrawTextureRotated    (Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    47
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
    48
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    49
procedure DrawCircle            (X, Y, Radius, Width: LongInt);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    50
procedure DrawCircle            (X, Y, Radius, Width: LongInt; r, g, b, a: Byte);
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
    51
9557
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
    52
procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; color: LongWord); inline;
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    53
procedure DrawLine              (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
    54
procedure DrawRect              (rect: TSDL_Rect; r, g, b, a: Byte; Fill: boolean);
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    55
procedure DrawHedgehog          (X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    56
procedure DrawScreenWidget      (widget: POnScreenWidget);
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
    57
procedure DrawWaterBody         (pVertexBuffer: Pointer);
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    58
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
    59
procedure RenderClear           ();
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
    60
procedure RenderSetClearColor      (r, g, b, a: real);
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    61
procedure Tint                  (r, g, b, a: Byte); inline;
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
    62
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
    63
procedure untint(); inline;
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
    64
procedure setTintAdd            (f: boolean); inline;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
    65
10266
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
    66
function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
    67
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
    68
// 0 => not offscreen, <0 => left/top of screen >0 => right/below of screen
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
    69
function isDxAreaOffscreen(X, Width: LongInt): LongInt; inline;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
    70
function isDyAreaOffscreen(Y, Height: LongInt): LongInt; inline;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
    71
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
    72
procedure SetScale(f: GLfloat);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
    73
procedure UpdateViewLimits();
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
    74
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
    75
procedure RenderSetup();
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
    76
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
    77
// 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
    78
10309
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
    79
procedure CreateFramebuffer(var frame, depth, tex: GLuint);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
    80
procedure DeleteFramebuffer(var frame, depth, tex: GLuint);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
    81
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
    82
procedure EnableTexture(enable:Boolean);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
    83
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
    84
procedure SetTexCoordPointer(p: Pointer;n: Integer);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
    85
procedure SetVertexPointer(p: Pointer;n: Integer);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
    86
procedure SetColorPointer(p: Pointer;n: Integer);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
    87
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
    88
procedure UpdateModelviewProjection(); inline;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
    89
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
    90
procedure openglLoadIdentity    (); inline;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
    91
procedure openglTranslProjMatrix(X, Y, Z: GLFloat); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
    92
procedure openglPushMatrix      (); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
    93
procedure openglPopMatrix       (); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
    94
procedure openglTranslatef      (X, Y, Z: GLfloat); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
    95
procedure openglScalef          (ScaleX, ScaleY, ScaleZ: GLfloat); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
    96
procedure openglRotatef         (RotX, RotY, RotZ: GLfloat; dir: LongInt); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
    97
procedure openglTint            (r, g, b, a: Byte); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
    98
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
    99
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   100
implementation
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   101
uses {$IFNDEF PAS2C} StrUtils, {$ENDIF}SysUtils, uVariables, uUtils, uConsts
10309
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   102
     {$IFDEF GL2}, uMatrix, uConsole{$ENDIF}
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   103
     {$IF NOT DEFINED(SDL2) AND DEFINED(USE_VIDEO_RECORDING)}, glut {$ENDIF};
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   104
8145
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
   105
{$IFDEF USE_TOUCH_INTERFACE}
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
   106
const
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
   107
    FADE_ANIM_TIME = 500;
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
   108
    MOVE_ANIM_TIME = 500;
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
   109
{$ENDIF}
6408c0ba4ba1 Move global variables to units that use them
Joe Doyle (Ginto8) <ginto8@gmail.com>
parents: 7069
diff changeset
   110
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   111
{$IFDEF GL2}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   112
var
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   113
    shaderMain: GLuint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   114
    shaderWater: GLuint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   115
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   116
7028
0f60591f3a16 old typed const moved to their proper unit
koda
parents: 6999
diff changeset
   117
var LastTint: LongWord = 0;
0f60591f3a16 old typed const moved to their proper unit
koda
parents: 6999
diff changeset
   118
10266
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   119
function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   120
begin
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   121
    isAreaOffscreen:= (isDxAreaOffscreen(X, Width) <> 0) or (isDyAreaOffscreen(Y, Height) <> 0);
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   122
end;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   123
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   124
function isDxAreaOffscreen(X, Width: LongInt): LongInt; inline;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   125
begin
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   126
    if X > ViewRightX then exit(1);
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   127
    if X + Width < ViewLeftX then exit(-1);
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   128
    isDxAreaOffscreen:= 0;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   129
end;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   130
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   131
function isDyAreaOffscreen(Y, Height: LongInt): LongInt; inline;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   132
begin
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   133
    if Y > ViewBottomY then exit(1);
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   134
    if Y + Height < ViewTopY then exit(-1);
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   135
    isDyAreaOffscreen:= 0;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   136
end;
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   137
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   138
procedure RenderClear();
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   139
begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   140
    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
   141
end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   142
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   143
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
   144
begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   145
    glClearColor(r, g, b, a);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   146
end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   147
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   148
{$IFDEF GL2}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   149
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
   150
var
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   151
    shader: GLuint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   152
    f: Textfile;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   153
    source, line: AnsiString;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   154
    sourceA: Pchar;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   155
    lengthA: GLint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   156
    compileResult: GLint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   157
    logLength: GLint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   158
    log: PChar;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   159
begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   160
    Assign(f, PathPrefix + cPathz[ptShaders] + '/' + shaderFile);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   161
    filemode:= 0; // readonly
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   162
    Reset(f);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   163
    if IOResult <> 0 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   164
    begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   165
        AddFileLog('Unable to load ' + shaderFile);
10306
4fca8bcfaff0 clean up halting a little
sheepluva
parents: 10304
diff changeset
   166
        halt(HaltStartupError);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   167
    end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   168
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   169
    source:='';
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   170
    while not eof(f) do
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   171
    begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   172
        ReadLn(f, line);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   173
        source:= source + line + #10;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   174
    end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   175
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   176
    Close(f);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   177
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   178
    WriteLnToConsole('Compiling shader: ' + PathPrefix + cPathz[ptShaders] + '/' + shaderFile);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   179
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   180
    sourceA:=PChar(source);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   181
    lengthA:=Length(source);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   182
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   183
    shader:=glCreateShader(shaderType);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   184
    glShaderSource(shader, 1, @sourceA, @lengthA);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   185
    glCompileShader(shader);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   186
    glGetShaderiv(shader, GL_COMPILE_STATUS, @compileResult);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   187
    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
   188
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   189
    if logLength > 1 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   190
    begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   191
        log := GetMem(logLength);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   192
        glGetShaderInfoLog(shader, logLength, nil, log);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   193
        WriteLnToConsole('========== Compiler log  ==========');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   194
        WriteLnToConsole(shortstring(log));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   195
        WriteLnToConsole('===================================');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   196
        FreeMem(log, logLength);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   197
    end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   198
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   199
    if compileResult <> GL_TRUE then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   200
    begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   201
        WriteLnToConsole('Shader compilation failed, halting');
10306
4fca8bcfaff0 clean up halting a little
sheepluva
parents: 10304
diff changeset
   202
        halt(HaltStartupError);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   203
    end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   204
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   205
    CompileShader:= shader;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   206
end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   207
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   208
function CompileProgram(shaderName: string): GLuint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   209
var
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   210
    program_: GLuint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   211
    vs, fs: GLuint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   212
    linkResult: GLint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   213
    logLength: GLint;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   214
    log: PChar;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   215
begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   216
    program_:= glCreateProgram();
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   217
    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
   218
    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
   219
    glAttachShader(program_, vs);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   220
    glAttachShader(program_, fs);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   221
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   222
    glBindAttribLocation(program_, aVertex, PChar('vertex'));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   223
    glBindAttribLocation(program_, aTexCoord, PChar('texcoord'));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   224
    glBindAttribLocation(program_, aColor, PChar('color'));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   225
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   226
    glLinkProgram(program_);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   227
    glDeleteShader(vs);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   228
    glDeleteShader(fs);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   229
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   230
    glGetProgramiv(program_, GL_LINK_STATUS, @linkResult);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   231
    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
   232
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   233
    if logLength > 1 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   234
    begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   235
        log := GetMem(logLength);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   236
        glGetProgramInfoLog(program_, logLength, nil, log);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   237
        WriteLnToConsole('========== Compiler log  ==========');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   238
        WriteLnToConsole(shortstring(log));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   239
        WriteLnToConsole('===================================');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   240
        FreeMem(log, logLength);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   241
    end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   242
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   243
    if linkResult <> GL_TRUE then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   244
    begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   245
        WriteLnToConsole('Linking program failed, halting');
10306
4fca8bcfaff0 clean up halting a little
sheepluva
parents: 10304
diff changeset
   246
        halt(HaltStartupError);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   247
    end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   248
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   249
    CompileProgram:= program_;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   250
end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   251
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   252
10309
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   253
function glLoadExtension(extension : shortstring) : boolean;
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   254
begin
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   255
//TODO: pas2c does not handle {$IF (GLunit = gles11) OR DEFINED(PAS2C)}
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   256
{$IFNDEF PAS2C}
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   257
{$IF GLunit = gles11}
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   258
    // FreePascal doesnt come with OpenGL ES 1.1 Extension headers
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   259
    extension:= extension; // avoid hint
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   260
    glLoadExtension:= false;
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   261
    AddFileLog('OpenGL - "' + extension + '" skipped')
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   262
{$ELSE}
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   263
    glLoadExtension:= glext_LoadExtension(extension);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   264
    if glLoadExtension then
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   265
        AddFileLog('OpenGL - "' + extension + '" loaded')
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   266
    else
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   267
        AddFileLog('OpenGL - "' + extension + '" failed to load');
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   268
{$ENDIF}
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   269
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   270
{$ELSE} // pas2c part
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   271
    glLoadExtension:= false;
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   272
{$ENDIF}
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   273
end;
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   274
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   275
{$IF DEFINED(USE_S3D_RENDERING) OR DEFINED(USE_VIDEO_RECORDING)}
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   276
procedure CreateFramebuffer(var frame, depth, tex: GLuint);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   277
begin
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   278
    glGenFramebuffersEXT(1, @frame);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   279
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frame);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   280
    glGenRenderbuffersEXT(1, @depth);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   281
    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   282
    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, cScreenWidth, cScreenHeight);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   283
    glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   284
    glGenTextures(1, @tex);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   285
    glBindTexture(GL_TEXTURE_2D, tex);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   286
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,  cScreenWidth, cScreenHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   287
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   288
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   289
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   290
end;
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   291
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   292
procedure DeleteFramebuffer(var frame, depth, tex: GLuint);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   293
begin
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   294
    glDeleteTextures(1, @tex);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   295
    glDeleteRenderbuffersEXT(1, @depth);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   296
    glDeleteFramebuffersEXT(1, @frame);
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   297
end;
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   298
e338ccbbe100 fix videorec build
sheepluva
parents: 10306
diff changeset
   299
{$ENDIF}
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   300
procedure RenderSetup();
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   301
var AuxBufNum: LongInt = 0;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   302
    tmpstr: ansistring;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   303
    tmpint: LongInt;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   304
    tmpn: LongInt;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   305
begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   306
    // suppress hint/warning
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   307
    AuxBufNum:= AuxBufNum;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   308
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   309
    // 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
   310
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   311
    if MaxTextureSize <= 0 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   312
        begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   313
        MaxTextureSize:= 1024;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   314
        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
   315
        end
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   316
    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
   317
        begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   318
        cReducedQuality := cReducedQuality or rqNoBackground;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   319
        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
   320
        end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   321
    // everyone loves debugging
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   322
    // 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
   323
    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
   324
    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
   325
    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
   326
    AddFileLog('  |----- Texture Size: ' + inttostr(MaxTextureSize));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   327
{$IFDEF USE_VIDEO_RECORDING}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   328
    glGetIntegerv(GL_AUX_BUFFERS, @AuxBufNum);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   329
    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
   330
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   331
{$IFNDEF PAS2C}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   332
    AddFileLog('  \----- Extensions: ');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   333
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   334
    // 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
   335
    tmpstr := StrPas(PChar(glGetString(GL_EXTENSIONS)));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   336
    tmpn := WordCount(tmpstr, [' ']);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   337
    tmpint := 1;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   338
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   339
    repeat
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   340
    begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   341
        // 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
   342
        // ExtractWord will return empty string if index out of range
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   343
        AddFileLog(TrimRight(
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   344
            ExtractWord(tmpint, tmpstr, [' ']) + ' ' +
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   345
            ExtractWord(tmpint+1, tmpstr, [' ']) + ' ' +
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   346
            ExtractWord(tmpint+2, tmpstr, [' '])
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   347
        ));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   348
        tmpint := tmpint + 3;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   349
    end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   350
    until (tmpint > tmpn);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   351
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   352
    AddFileLog('');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   353
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   354
    defaultFrame:= 0;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   355
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   356
{$IFDEF USE_VIDEO_RECORDING}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   357
    if GameType = gmtRecord then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   358
    begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   359
        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
   360
        begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   361
            CreateFramebuffer(defaultFrame, depthv, texv);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   362
            glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, defaultFrame);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   363
            AddFileLog('Using framebuffer for video recording.');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   364
        end
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   365
        else if AuxBufNum > 0 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   366
        begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   367
            glDrawBuffer(GL_AUX0);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   368
            glReadBuffer(GL_AUX0);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   369
            AddFileLog('Using auxiliary buffer for video recording.');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   370
        end
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   371
        else
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   372
        begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   373
            glDrawBuffer(GL_BACK);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   374
            glReadBuffer(GL_BACK);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   375
            AddFileLog('Warning: off-screen rendering is not supported; using back buffer but it may not work.');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   376
        end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   377
    end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   378
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   379
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   380
{$IFDEF GL2}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   381
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   382
{$IFDEF PAS2C}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   383
    err := glewInit();
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   384
    if err <> GLEW_OK then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   385
    begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   386
        WriteLnToConsole('Failed to initialize GLEW.');
10306
4fca8bcfaff0 clean up halting a little
sheepluva
parents: 10304
diff changeset
   387
        halt(HaltStartupError);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   388
    end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   389
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   390
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   391
{$IFNDEF PAS2C}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   392
    if not Load_GL_VERSION_2_0 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   393
        halt;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   394
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   395
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   396
    shaderWater:= CompileProgram('water');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   397
    glUseProgram(shaderWater);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   398
    glUniform1i(glGetUniformLocation(shaderWater, pchar('tex0')), 0);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   399
    uWaterMVPLocation:= glGetUniformLocation(shaderWater, pchar('mvp'));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   400
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   401
    shaderMain:= CompileProgram('default');
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   402
    glUseProgram(shaderMain);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   403
    glUniform1i(glGetUniformLocation(shaderMain, pchar('tex0')), 0);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   404
    uMainMVPLocation:= glGetUniformLocation(shaderMain, pchar('mvp'));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   405
    uMainTintLocation:= glGetUniformLocation(shaderMain, pchar('tint'));
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   406
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   407
    uCurrentMVPLocation:= uMainMVPLocation;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   408
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   409
    Tint(255, 255, 255, 255);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   410
    UpdateModelviewProjection;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   411
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   412
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   413
{$IFNDEF USE_S3D_RENDERING}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   414
    if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   415
    begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   416
        // 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
   417
        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
   418
            begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   419
            CreateFramebuffer(framel, depthl, texl);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   420
            CreateFramebuffer(framer, depthr, texr);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   421
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   422
            // reset
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   423
            glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, defaultFrame)
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   424
            end
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   425
        else
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   426
            cStereoMode:= smNone;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   427
    end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   428
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   429
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   430
// set view port to whole window
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   431
glViewport(0, 0, cScreenWidth, cScreenHeight);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   432
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   433
{$IFDEF GL2}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   434
    uMatrix.initModule;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   435
    hglMatrixMode(MATRIX_MODELVIEW);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   436
    // prepare default translation/scaling
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   437
    hglLoadIdentity();
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   438
    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
   439
    hglTranslatef(0, -cScreenHeight / 2, 0);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   440
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   441
    EnableTexture(True);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   442
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   443
    glEnableVertexAttribArray(aVertex);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   444
    glEnableVertexAttribArray(aTexCoord);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   445
    glGenBuffers(1, @vBuffer);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   446
    glGenBuffers(1, @tBuffer);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   447
    glGenBuffers(1, @cBuffer);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   448
{$ELSE}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   449
    glMatrixMode(GL_MODELVIEW);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   450
    // prepare default translation/scaling
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   451
    glLoadIdentity();
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   452
    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
   453
    glTranslatef(0, -cScreenHeight / 2, 0);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   454
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   455
    // 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
   456
    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
   457
    // disable dithering
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   458
    glDisable(GL_DITHER);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   459
    // 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
   460
    glEnable(GL_TEXTURE_2D);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   461
    glEnableClientState(GL_VERTEX_ARRAY);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   462
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   463
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   464
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   465
    // enable alpha blending
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   466
    glEnable(GL_BLEND);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   467
    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
   468
    // 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
   469
end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   470
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   471
procedure openglLoadIdentity(); inline;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   472
begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   473
{$IFDEF GL2}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   474
    hglLoadIdentity();
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   475
{$ELSE}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   476
    glLoadIdentity();
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   477
{$ENDIF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   478
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   479
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   480
procedure openglTranslProjMatrix(X, Y, Z: GLfloat); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   481
begin
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   482
{$IFDEF GL2}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   483
    hglMatrixMode(MATRIX_PROJECTION);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   484
    hglTranslatef(X, Y, Z);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   485
    hglMatrixMode(MATRIX_MODELVIEW);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   486
{$ELSE}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   487
    glMatrixMode(GL_PROJECTION);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   488
    glTranslatef(X, Y, Z);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   489
    glMatrixMode(GL_MODELVIEW);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   490
{$ENDIF}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   491
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   492
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   493
procedure openglPushMatrix(); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   494
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
   495
{$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
   496
    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
   497
{$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
   498
    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
   499
{$ENDIF}
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   500
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   501
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   502
procedure openglPopMatrix(); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   503
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
   504
{$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
   505
    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
   506
{$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
   507
    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
   508
{$ENDIF}
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   509
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   510
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   511
procedure openglTranslatef(X, Y, Z: GLfloat); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   512
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
   513
{$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
   514
    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
   515
{$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
   516
    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
   517
{$ENDIF}
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   518
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   519
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   520
procedure openglScalef(ScaleX, ScaleY, ScaleZ: GLfloat); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   521
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
   522
{$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
   523
    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
   524
{$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
   525
    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
   526
{$ENDIF}
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   527
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   528
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   529
procedure openglRotatef(RotX, RotY, RotZ: GLfloat; dir: LongInt); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   530
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
   531
{$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
   532
    hglRotatef(RotX, RotY, RotZ, dir);
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
   533
{$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
   534
    glRotatef(RotX, RotY, RotZ, dir);
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
   535
{$ENDIF}
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   536
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   537
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   538
procedure openglUseColorOnly(b :boolean); inline;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   539
begin
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   540
    if b then
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   541
        begin
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   542
        {$IFDEF GL2}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   543
        glDisableVertexAttribArray(aTexCoord);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   544
        glEnableVertexAttribArray(aColor);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   545
        {$ELSE}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   546
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   547
        glEnableClientState(GL_COLOR_ARRAY);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   548
        {$ENDIF}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   549
        end
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   550
    else
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   551
        begin
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   552
        {$IFDEF GL2}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   553
        glDisableVertexAttribArray(aColor);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   554
        glEnableVertexAttribArray(aTexCoord);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   555
        {$ELSE}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   556
        glDisableClientState(GL_COLOR_ARRAY);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   557
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   558
        {$ENDIF}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   559
        end;
10318
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   560
    EnableTexture(not b);
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   561
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   562
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   563
procedure UpdateModelviewProjection(); inline;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   564
{$IFDEF GL2}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   565
var
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   566
    mvp: TMatrix4x4f;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   567
{$ENDIF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   568
begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   569
{$IFDEF GL2}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   570
    //MatrixMultiply(mvp, mProjection, mModelview);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   571
{$HINTS OFF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   572
    hglMVP(mvp);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   573
{$HINTS ON}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   574
    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
   575
{$ENDIF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   576
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   577
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   578
procedure SetTexCoordPointer(p: Pointer; n: Integer);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   579
begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   580
{$IFDEF GL2}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   581
    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
   582
    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
   583
    glEnableVertexAttribArray(aTexCoord);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   584
    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
   585
{$ELSE}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   586
    n:= n;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   587
    glTexCoordPointer(2, GL_FLOAT, 0, p);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   588
{$ENDIF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   589
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   590
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   591
procedure SetVertexPointer(p: Pointer; n: Integer);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   592
begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   593
{$IFDEF GL2}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   594
    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
   595
    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
   596
    glEnableVertexAttribArray(aVertex);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   597
    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
   598
{$ELSE}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   599
    n:= n;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   600
    glVertexPointer(2, GL_FLOAT, 0, p);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   601
{$ENDIF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   602
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   603
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   604
procedure SetColorPointer(p: Pointer; n: Integer);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   605
begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   606
{$IFDEF GL2}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   607
    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
   608
    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
   609
    glEnableVertexAttribArray(aColor);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   610
    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
   611
{$ELSE}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   612
    n:= n;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   613
    glColorPointer(4, GL_UNSIGNED_BYTE, 0, p);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   614
{$ENDIF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   615
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   616
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   617
procedure EnableTexture(enable:Boolean);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   618
begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   619
    {$IFDEF GL2}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   620
    if enable then
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   621
        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
   622
    else
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   623
        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
   624
    {$ELSE}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   625
    if enable then
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   626
        glEnable(GL_TEXTURE_2D)
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   627
    else
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   628
        glDisable(GL_TEXTURE_2D);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   629
    {$ENDIF}
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   630
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   631
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   632
procedure UpdateViewLimits();
10318
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   633
var tmp: LongInt;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   634
begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   635
    // cScaleFactor is 2.0 on "no zoom"
10318
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   636
    tmp:= round(0.5 + cScreenWidth / cScaleFactor);
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   637
    ViewRightX :=  tmp;
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   638
    ViewLeftX  := -tmp;
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   639
    tmp:= round(0.5 + cScreenHeight / cScaleFactor);
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   640
    ViewBottomY:=  tmp + cScreenHeight div 2;
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   641
    ViewTopY   := -tmp + cScreenHeight div 2;
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   642
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   643
    // visual debugging fun :D
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   644
    if cViewLimitsDebug then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   645
        begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   646
        // some margin on each side
10318
c2e81eea375f little visual tweak to weSea rendering
sheepluva
parents: 10312
diff changeset
   647
        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
   648
        ViewLeftX  := ViewLeftX   + trunc(tmp);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   649
        ViewRightX := ViewRightX  - trunc(tmp);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   650
        ViewBottomY:= ViewBottomY - trunc(tmp);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   651
        ViewTopY   := ViewTopY    + trunc(tmp);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   652
        end;
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
    ViewWidth := ViewRightX  - ViewLeftX + 1;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   655
    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
   656
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   657
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   658
procedure SetScale(f: GLfloat);
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   659
begin
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   660
    // 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
   661
    if f = cScaleFactor then
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   662
        exit;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   663
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   664
    // 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
   665
    if f = cDefaultZoomLevel then
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   666
        begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   667
        openglPopMatrix;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   668
        end
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   669
    else
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   670
        begin
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   671
        openglPushMatrix; // save default scaling in matrix
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   672
        openglLoadIdentity();
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   673
        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
   674
        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
   675
        end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   676
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   677
    cScaleFactor:= f;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   678
    updateViewLimits();
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   679
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   680
    UpdateModelviewProjection;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   681
end;
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
   682
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   683
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   684
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   685
r.y:= r.y + Height * Position;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   686
r.h:= Height;
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   687
DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   688
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   689
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   690
procedure DrawTextureFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   691
begin
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   692
DrawTextureFromRectDir(X, Y, r^.w, r^.h, r, SourceTexture, 1)
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   693
end;
8833
c13ebed437cb update webgl branch
koda
parents: 8330 8626
diff changeset
   694
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   695
procedure DrawTextureFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   696
begin
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   697
DrawTextureFromRectDir(X, Y, W, H, r, SourceTexture, 1)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   698
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   699
8560
134a098235fa Messing around w/ Freezer
nemo
parents: 8145
diff changeset
   700
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
   701
var _l, _r, _t, _b: real;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   702
    VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
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
   703
    xw, yh: LongInt;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   704
begin
6580
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   705
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
   706
    exit;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   707
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   708
{if isDxAreaOffscreen(X, W) <> 0 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   709
    exit;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   710
if isDyAreaOffscreen(Y, H) <> 0 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   711
    exit;}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   712
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   713
// 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
   714
if (abs(X) > W) and ((abs(X + W / 2) - W / 2) * 2 > ViewWidth) then
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   715
    exit;
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
   716
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
   717
    exit;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   718
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   719
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   720
_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
   721
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
   722
// 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
   723
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
   724
    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
   725
    _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
   726
    _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
   727
    _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
   728
    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
   729
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   730
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   731
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   732
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   733
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   734
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
   735
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
   736
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
   737
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
   738
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
   739
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
   740
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
   741
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
   742
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
   743
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
   744
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
   745
VertexBuffer[3].Y:= yh;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   746
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   747
TextureBuffer[0].X:= _l;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   748
TextureBuffer[0].Y:= _t;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   749
TextureBuffer[1].X:= _r;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   750
TextureBuffer[1].Y:= _t;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   751
TextureBuffer[2].X:= _r;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   752
TextureBuffer[2].Y:= _b;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   753
TextureBuffer[3].X:= _l;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   754
TextureBuffer[3].Y:= _b;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   755
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   756
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   757
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   758
glDrawArrays(GL_TRIANGLE_FAN, 0, High(VertexBuffer) - Low(VertexBuffer) + 1);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   759
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   760
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   761
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
   762
begin
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   763
    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
   764
end;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   765
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   766
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   767
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   768
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   769
openglPushMatrix;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   770
openglTranslatef(X, Y, 0);
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   771
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   772
if Scale <> 1.0 then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   773
    openglScalef(Scale, Scale, 1);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   774
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   775
glBindTexture(GL_TEXTURE_2D, Texture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   776
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   777
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
   778
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
   779
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   780
UpdateModelviewProjection;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   781
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   782
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
   783
openglPopMatrix;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   784
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   785
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   786
10020
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   787
{ 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
   788
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
   789
var
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   790
    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
   791
begin
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   792
openglPushMatrix;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   793
openglTranslatef(X, Y, 0);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   794
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
   795
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   796
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
   797
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   798
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
   799
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
   800
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
   801
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
   802
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
   803
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
   804
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
   805
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
   806
10266
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   807
SetVertexPointer(@Texture^.vb, Length(Texture^.vb));
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   808
SetTexCoordPointer(@TextureBuffer, Length(Texture^.vb));
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   809
a90a55ec5b98 some minor tweaks and stuff
sheepluva
parents: 10255
diff changeset
   810
UpdateModelviewProjection;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   811
10020
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   812
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
   813
openglPopMatrix;
10020
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   814
end;
67e127027af6 small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents: 9998
diff changeset
   815
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   816
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   817
begin
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   818
    DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   819
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   820
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   821
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
   822
var ft, fb, fl, fr: GLfloat;
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   823
    hw, hh, nx, ny: LongInt;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   824
    VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   825
begin
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   826
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
   827
// note: not taking scale into account
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
   828
if isAreaOffscreen(X, Y, w, h) then
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   829
    exit;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   830
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
   831
{
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   832
// 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
   833
if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * 2 > ViewWidth) then
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   834
    exit;
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
   835
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
   836
    exit;
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
   837
}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   838
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   839
openglPushMatrix;
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   840
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   841
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
   842
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
   843
if Dir = 0 then Dir:= 1;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   844
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   845
if Angle <> 0 then
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   846
    openglRotatef(Angle, 0, 0, Dir);
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   847
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   848
if (OffsetX <> 0) or (OffsetY <> 0) then
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   849
    openglTranslatef(Dir*OffsetX, OffsetY, 0);
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   850
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   851
if Scale <> 1.0 then
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   852
    openglScalef(Scale, Scale, 1);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   853
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   854
// Any reason for this call? And why only in t direction, not s?
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   855
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   856
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   857
if Dir > 0 then
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   858
    hw:=  w div 2
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   859
else
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   860
    hw:= -w div 2;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   861
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   862
hh:= h div 2;
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   863
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   864
nx:= Texture^.w div w; // number of horizontal frames
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
   865
if nx = 0 then nx:= 1; // one frame is minimum
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   866
ny:= Texture^.h div h; // number of vertical frames
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
   867
if ny = 0 then ny:= 1;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   868
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   869
ft:= (Frame mod ny) * Texture^.ry / ny;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   870
fb:= ((Frame mod ny) + 1) * Texture^.ry / ny;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   871
fl:= (Frame div ny) * Texture^.rx / nx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   872
fr:= ((Frame div ny) + 1) * Texture^.rx / nx;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   873
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   874
glBindTexture(GL_TEXTURE_2D, Texture^.id);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   875
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   876
VertexBuffer[0].X:= -hw;
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   877
VertexBuffer[0].Y:= -hh;
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   878
VertexBuffer[1].X:=  hw;
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   879
VertexBuffer[1].Y:= -hh;
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   880
VertexBuffer[2].X:=  hw;
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   881
VertexBuffer[2].Y:=  hh;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   882
VertexBuffer[3].X:= -hw;
10301
6a225b469eef some rendering tweaks
sheepluva
parents: 10276
diff changeset
   883
VertexBuffer[3].Y:=  hh;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   884
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   885
TextureBuffer[0].X:= fl;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   886
TextureBuffer[0].Y:= ft;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   887
TextureBuffer[1].X:= fr;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   888
TextureBuffer[1].Y:= ft;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   889
TextureBuffer[2].X:= fr;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   890
TextureBuffer[2].Y:= fb;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   891
TextureBuffer[3].X:= fl;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   892
TextureBuffer[3].Y:= fb;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   893
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   894
SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   895
SetTexCoordPointer(@TextureBuffer[0], Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   896
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   897
UpdateModelviewProjection;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   898
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   899
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   900
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   901
openglPopMatrix;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   902
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   903
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   904
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   905
procedure DrawSpriteRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   906
begin
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   907
    DrawTextureRotated(SpritesData[Sprite].Texture,
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   908
        SpritesData[Sprite].Width,
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   909
        SpritesData[Sprite].Height,
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   910
        X, Y, Dir, Angle)
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   911
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   912
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   913
procedure DrawSpriteRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   914
begin
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   915
10312
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   916
if Angle <> 0  then
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   917
    begin
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   918
    // sized doubled because the sprite might occupy up to 1.4 * of it's
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   919
    // original size in each dimension, because it is rotated
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   920
    if isDxAreaOffscreen(X - SpritesData[Sprite].Width, 2 * SpritesData[Sprite].Width) <> 0 then
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   921
        exit;
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   922
    if isDYAreaOffscreen(Y - SpritesData[Sprite].Height, 2 * SpritesData[Sprite].Height) <> 0 then
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   923
        exit;
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   924
    end
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   925
else
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   926
    begin
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   927
    if isDxAreaOffscreen(X - SpritesData[Sprite].Width div 2, SpritesData[Sprite].Width) <> 0 then
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   928
        exit;
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   929
    if isDYAreaOffscreen(Y - SpritesData[Sprite].Height div 2 , SpritesData[Sprite].Height) <> 0 then
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   930
        exit;
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   931
    end;
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   932
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   933
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   934
openglPushMatrix;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   935
openglTranslatef(X, Y, 0);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   936
10312
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   937
// mirror
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   938
if Dir < 0 then
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   939
    openglScalef(-1.0, 1.0, 1.0);
10312
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   940
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   941
// apply angle after (conditional) mirroring
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   942
if Angle <> 0  then
eda8d563f677 various tweaks
sheepluva
parents: 10311
diff changeset
   943
    openglRotatef(Angle, 0, 0, 1);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   944
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   945
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   946
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   947
openglPopMatrix;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   948
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   949
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   950
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   951
procedure DrawTextureRotated(Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   952
var VertexBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   953
begin
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   954
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   955
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
   956
    exit;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   957
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
   958
    exit;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
   959
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
   960
// 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
   961
{if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   962
    exit;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   963
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
   964
    exit;}
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   965
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   966
openglPushMatrix;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   967
openglTranslatef(X, Y, 0);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   968
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   969
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
   970
    begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   971
    hw:= - hw;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   972
    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
   973
    end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
   974
else
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   975
    openglRotatef(Angle, 0, 0, 1);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   976
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
   977
glBindTexture(GL_TEXTURE_2D, Texture^.id);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   978
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   979
VertexBuffer[0].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   980
VertexBuffer[0].Y:= -hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   981
VertexBuffer[1].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   982
VertexBuffer[1].Y:= -hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   983
VertexBuffer[2].X:= hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   984
VertexBuffer[2].Y:= hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   985
VertexBuffer[3].X:= -hw;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   986
VertexBuffer[3].Y:= hh;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   987
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   988
SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   989
SetTexCoordPointer(@Texture^.tb, Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   990
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   991
UpdateModelviewProjection;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   992
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   993
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   994
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
   995
openglPopMatrix;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
   996
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   997
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
   998
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
   999
procedure DrawSprite(Sprite: TSprite; X, Y, Frame: LongInt);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1000
var row, col, numFramesFirstCol: LongInt;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1001
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
  1002
    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
  1003
        exit;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  1004
    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
  1005
    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
  1006
    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
  1007
    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
  1008
end;
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  1009
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  1010
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
  1011
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
  1012
begin
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  1013
    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
  1014
    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
  1015
    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
  1016
    r.h:= SpritesData[Sprite].Height;
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
  1017
    DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1018
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1019
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1020
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1021
var r: TSDL_Rect;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1022
begin
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1023
r.x:= 0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1024
r.y:= 0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1025
r.w:= SpritesData[Sprite].Width;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1026
r.h:= SpritesData[Sprite].Height;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1027
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1028
if (X < LeftX) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1029
    r.x:= LeftX - X;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1030
if (Y < TopY) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1031
    r.y:= TopY - Y;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1032
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1033
if (Y + SpritesData[Sprite].Height > BottomY) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1034
    r.h:= BottomY - Y + 1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1035
if (X + SpritesData[Sprite].Width > RightX) then
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1036
    r.w:= RightX - X + 1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1037
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9950
diff changeset
  1038
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
  1039
    exit;
59cde1e53ca5 This seems to be enough to fix the bug with sprGirder rendered in stripe
unc0rr
parents: 9666
diff changeset
  1040
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1041
dec(r.h, r.y);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1042
dec(r.w, r.x);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1043
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
  1044
DrawTextureFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture)
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1045
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1046
6999
486db9d26e4b rename a few Draw* routines
koda
parents: 6992
diff changeset
  1047
procedure DrawTextureCentered(X, Top: LongInt; Source: PTexture);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1048
var scale: GLfloat;
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1049
    left : LongInt;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1050
begin
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1051
    // scale down if larger than screen
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1052
    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
  1053
        begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1054
        scale:= cScreenWidth / (Source^.w + 20);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1055
        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
  1056
        end
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1057
    else
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1058
        begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1059
        left:= X - Source^.w div 2;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1060
        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
  1061
            DrawTexture(left, Top, Source);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1062
        end;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1063
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1064
9557
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
  1065
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; color: LongWord); inline;
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
  1066
begin
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
  1067
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
  1068
end;
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
  1069
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1070
procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
8626
cfc44db21d72 Fix DrawLine bug
Urbertar@gmail.com
parents: 8560
diff changeset
  1071
var VertexBuffer: array [0..1] of TVertex2f;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1072
begin
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1073
    glEnable(GL_LINE_SMOOTH);
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1074
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1075
    EnableTexture(False);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1076
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1077
    openglPushMatrix;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1078
    openglTranslatef(WorldDx, WorldDy, 0);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1079
    glLineWidth(Width);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1080
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1081
    UpdateModelviewProjection;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1082
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1083
    Tint(r, g, b, a);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1084
    VertexBuffer[0].X:= X0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1085
    VertexBuffer[0].Y:= Y0;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1086
    VertexBuffer[1].X:= X1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1087
    VertexBuffer[1].Y:= Y1;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1088
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1089
    SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1090
    glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1091
    untint;
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9950
diff changeset
  1092
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1093
    openglPopMatrix;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1094
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1095
    EnableTexture(True);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1096
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1097
    glDisable(GL_LINE_SMOOTH);
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1098
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1099
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1100
procedure DrawRect(rect: TSDL_Rect; r, g, b, a: Byte; Fill: boolean);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1101
var VertexBuffer: array [0..3] of TVertex2f;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1102
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
  1103
// 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
  1104
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
  1105
    exit;
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
  1106
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
  1107
    exit;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1108
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1109
EnableTexture(False);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1110
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1111
Tint(r, g, b, a);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1112
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1113
with rect do
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1114
begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1115
    VertexBuffer[0].X:= x;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1116
    VertexBuffer[0].Y:= y;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1117
    VertexBuffer[1].X:= x + w;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1118
    VertexBuffer[1].Y:= y;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1119
    VertexBuffer[2].X:= x + w;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1120
    VertexBuffer[2].Y:= y + h;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1121
    VertexBuffer[3].X:= x;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1122
    VertexBuffer[3].Y:= y + h;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1123
end;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1124
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1125
SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1126
if Fill then
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1127
    glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer))
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1128
else
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1129
    glDrawArrays(GL_LINE_LOOP, 0, Length(VertexBuffer));
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1130
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1131
untint;
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1132
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1133
EnableTexture(True);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1134
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1135
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1136
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
  1137
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
  1138
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
  1139
    Tint(r, g, b, a);
10015
4feced261c68 partial merge of the webgl branch
koda
parents: 9998 9950
diff changeset
  1140
    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
  1141
    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
  1142
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
  1143
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
  1144
procedure DrawCircle(X, Y, Radius, Width: LongInt);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1145
var
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1146
    i: LongInt;
5561
dfbe55237c64 Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents: 5559
diff changeset
  1147
    CircleVertex: array [0..59] of TVertex2f;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1148
begin
5561
dfbe55237c64 Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents: 5559
diff changeset
  1149
    for i := 0 to 59 do begin
dfbe55237c64 Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents: 5559
diff changeset
  1150
        CircleVertex[i].X := X + Radius*cos(i*pi/30);
dfbe55237c64 Shrink number of circle points to 60, reenable seduction circle (no longer crashes)
nemo
parents: 5559
diff changeset
  1151
        CircleVertex[i].Y := Y + Radius*sin(i*pi/30);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1152
    end;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1153
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1154
    EnableTexture(False);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1155
    glEnable(GL_LINE_SMOOTH);
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1156
    openglPushMatrix;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1157
    glLineWidth(Width);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1158
    SetVertexPointer(@CircleVertex[0], 60);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1159
    glDrawArrays(GL_LINE_LOOP, 0, 60);
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1160
    openglPopMatrix;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1161
    EnableTexture(True);
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1162
    glDisable(GL_LINE_SMOOTH);
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1163
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1164
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1165
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1166
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1167
const VertexBuffer: array [0..3] of TVertex2f = (
7069
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
  1168
        (X: -16; Y: -16),
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
  1169
        (X:  16; Y: -16),
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
  1170
        (X:  16; Y:  16),
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7028
diff changeset
  1171
        (X: -16; Y:  16));
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1172
var l, r, t, b: real;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1173
    TextureBuffer: array [0..3] of TVertex2f;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1174
begin
5565
1a326ba319c9 smaller code cleanup
koda
parents: 5561
diff changeset
  1175
    // 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
  1176
    if (abs(X) > 32) and ((abs(X) - 16) * 2 > ViewWidth) then
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1177
        exit;
10311
30b5fab302f6 tweak engine segfault capabilities
sheepluva
parents: 10309
diff changeset
  1178
    if (abs(Y) > 32) and ((abs(Y - cScreenHeight / 2) - 16) * 2 > ViewHeight) then
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1179
        exit;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1180
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1181
    t:= Pos * 32 / HHTexture^.h;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1182
    b:= (Pos + 1) * 32 / HHTexture^.h;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1183
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1184
    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
  1185
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
  1186
        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
  1187
        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
  1188
        end
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
  1189
    else
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
  1190
        begin
6155187bf599 A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents: 6394
diff changeset
  1191
        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
  1192
        r:= (Step + 1) * 32 / HHTexture^.w
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1193
    end;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1194
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1195
    openglPushMatrix();
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1196
    openglTranslatef(X, Y, 0);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1197
    openglRotatef(Angle, 0, 0, 1);
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1198
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1199
    glBindTexture(GL_TEXTURE_2D, HHTexture^.id);
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1200
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1201
    TextureBuffer[0].X:= l;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1202
    TextureBuffer[0].Y:= t;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1203
    TextureBuffer[1].X:= r;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1204
    TextureBuffer[1].Y:= t;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1205
    TextureBuffer[2].X:= r;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1206
    TextureBuffer[2].Y:= b;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1207
    TextureBuffer[3].X:= l;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1208
    TextureBuffer[3].Y:= b;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1209
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1210
    SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1211
    SetTexCoordPointer(@TextureBuffer[0], Length(VertexBuffer));
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1212
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1213
    UpdateModelviewProjection;
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1214
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1215
    glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1216
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1217
    openglPopMatrix;
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1218
end;
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1219
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1220
procedure DrawScreenWidget(widget: POnScreenWidget);
6992
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
  1221
{$IFDEF USE_TOUCH_INTERFACE}
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1222
var alpha: byte = $FF;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1223
begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1224
with widget^ do
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1225
    begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1226
    if (fadeAnimStart <> 0) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1227
        begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1228
        if RealTicks > (fadeAnimStart + FADE_ANIM_TIME) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1229
            fadeAnimStart:= 0
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1230
        else
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
  1231
            if show then
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1232
                alpha:= Byte(trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF))
8330
aaefa587e277 update branch with default
koda
parents: 8026 8145
diff changeset
  1233
            else
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1234
                alpha:= Byte($FF - trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF));
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1235
        end;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1236
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1237
    with moveAnim do
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1238
        if animate then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1239
            if RealTicks > (startTime + MOVE_ANIM_TIME) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1240
                begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1241
                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
  1242
                animate:= false;
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
  1243
                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
  1244
                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
  1245
                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
  1246
                active.y:= active.y + (target.y - source.y);
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1247
                end
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1248
            else
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1249
                begin
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6689
diff changeset
  1250
                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
  1251
                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
  1252
                end;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1253
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1254
    if show or (fadeAnimStart <> 0) then
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1255
        begin
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1256
        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
  1257
        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
  1258
        untint;
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1259
        end;
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1260
    end;
6992
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
  1261
{$ELSE}
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
  1262
begin
b8f3d8991e92 marked a couple of functions as inline
koda
parents: 6986
diff changeset
  1263
widget:= widget; // avoid hint
6689
98a239848ba2 wops, added an extra USE_TOUCH_INTERFACE
Xeli
parents: 6688
diff changeset
  1264
{$ENDIF}
6688
b2084a00a4cf added translate/fade animations for OnScreenWidgets
Xeli
parents: 6580
diff changeset
  1265
end;
4385
f679ffa2dc8c Introduce uGearsRender
unc0rr
parents: 4378
diff changeset
  1266
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1267
procedure BeginWater;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1268
begin
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1269
{$IFDEF GL2}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1270
    glUseProgram(shaderWater);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1271
    uCurrentMVPLocation:=uWaterMVPLocation;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1272
    UpdateModelviewProjection;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1273
    glDisableVertexAttribArray(aTexCoord);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1274
    glEnableVertexAttribArray(aColor);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1275
{$ENDIF}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1276
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1277
    openglUseColorOnly(true);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1278
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1279
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1280
procedure EndWater;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1281
begin
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1282
{$IFDEF GL2}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1283
    glUseProgram(shaderMain);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1284
    uCurrentMVPLocation:=uMainMVPLocation;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1285
    UpdateModelviewProjection;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1286
    glDisableVertexAttribArray(aColor);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1287
    glEnableVertexAttribArray(aTexCoord);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1288
{$ENDIF}
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1289
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1290
    openglUseColorOnly(false);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1291
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1292
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
  1293
procedure DrawWaterBody(pVertexBuffer: Pointer);
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1294
begin
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1295
        UpdateModelviewProjection;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1296
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1297
        BeginWater;
10302
ea0b0e2efd95 huh? me? nono, don't mind me. I'm just here to clean up.
sheepluva
parents: 10301
diff changeset
  1298
10275
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1299
        if SuddenDeathDmg then
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1300
            SetColorPointer(@SDWaterColorArray[0], 4)
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1301
        else
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1302
            SetColorPointer(@WaterColorArray[0], 4);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1303
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1304
        SetVertexPointer(pVertexBuffer, 4);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1305
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1306
        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1307
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1308
        EndWater;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1309
end;
6c91047f59b6 RAR: cleaning up a bit of the IFDEF-clusterf*ck
sheepluva
parents: 10266
diff changeset
  1310
10255
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1311
procedure openglTint(r, g, b, a: Byte); inline;
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1312
{$IFDEF GL2}
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1313
const
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1314
    scale:Real = 1.0/255.0;
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1315
{$ENDIF}
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1316
begin
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1317
    {$IFDEF GL2}
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1318
    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
  1319
    {$ELSE}
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1320
    glColor4ub(r, g, b, a);
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1321
    {$ENDIF}
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1322
end;
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1323
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1324
procedure Tint(r, g, b, a: Byte); inline;
8026
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1325
var
4a4f21070479 merge xymeng's gsoc engine with a few updates (and further checks on symbol definitions)
koda
parents: 7069
diff changeset
  1326
    nc, tw: Longword;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1327
begin
9557
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
  1328
    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
  1329
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  1330
    if nc = lastTint then
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  1331
        exit;
5559
a937d43a032f Use local scope global var instead
unc0rr
parents: 5441
diff changeset
  1332
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  1333
    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
  1334
        begin
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  1335
        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
  1336
        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
  1337
            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
  1338
        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
  1339
        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
  1340
        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
  1341
        end;
5441
39962b855540 Add grayscale option for 3d, helps with colour clashing
nemo
parents: 5235
diff changeset
  1342
10255
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1343
    openglTint(r, g, b, a);
6986
409dd3851309 add support for default pascal mode by removing default arguments value (maybe this also helps the parser)
koda
parents: 6982
diff changeset
  1344
    lastTint:= nc;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1345
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1346
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1347
procedure Tint(c: Longword); inline;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1348
begin
9557
a5005b7ca305 differentiate borders a bit
nemo
parents: 9080
diff changeset
  1349
    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
  1350
    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
  1351
end;
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1352
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1353
procedure untint(); inline;
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1354
begin
10255
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1355
    if cWhiteColor = lastTint then exit;
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1356
    openglTint($FF, $FF, $FF, $FF);
fdc342ebdc31 tweak untint a little (especially in connection with GrayScale)
sheepluva
parents: 10108
diff changeset
  1357
    lastTint:= cWhiteColor;
9666
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1358
end;
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1359
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1360
procedure setTintAdd(f: boolean); inline;
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1361
begin
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1362
    if f then
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1363
        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
  1364
    else
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1365
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1366
end;
8dcb25112d96 - Bring back white dot in the center of crosshair. Crosshair is blurred now!
unc0rr
parents: 9557
diff changeset
  1367
10304
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1368
procedure initModule;
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
end;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1371
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1372
procedure freeModule;
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1373
begin
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1374
{$IFDEF GL2}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1375
    glDeleteProgram(shaderMain);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1376
    glDeleteProgram(shaderWater);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1377
    glDeleteBuffers(1, @vBuffer);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1378
    glDeleteBuffers(1, @tBuffer);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1379
    glDeleteBuffers(1, @cBuffer);
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1380
{$ENDIF}
7e40820b7ed6 fix gl2 build, further rendering cleanup WIP, also new chat command: /debugvl
sheepluva
parents: 10302
diff changeset
  1381
end;
4378
91655618a510 Introduce uRender
unC0Rr
parents:
diff changeset
  1382
end.