hedgewars/uRender.pas
changeset 10275 6c91047f59b6
parent 10266 a90a55ec5b98
child 10276 89056c7254ef
equal deleted inserted replaced
10274:07adc8b6288c 10275:6c91047f59b6
    49 procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; color: LongWord); inline;
    49 procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; color: LongWord); inline;
    50 procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
    50 procedure DrawLine              (X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
    51 procedure DrawFillRect          (r: TSDL_Rect);
    51 procedure DrawFillRect          (r: TSDL_Rect);
    52 procedure DrawHedgehog          (X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
    52 procedure DrawHedgehog          (X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
    53 procedure DrawScreenWidget      (widget: POnScreenWidget);
    53 procedure DrawScreenWidget      (widget: POnScreenWidget);
    54 
    54 procedure DrawWaterBody         (pVertexBuffer: Pointer; length: LongInt);
    55 procedure openglTint            (r, g, b, a: Byte); inline;
    55 
    56 procedure Tint                  (r, g, b, a: Byte); inline;
    56 procedure Tint                  (r, g, b, a: Byte); inline;
    57 procedure Tint                  (c: Longword); inline;
    57 procedure Tint                  (c: Longword); inline;
    58 procedure untint(); inline;
    58 procedure untint(); inline;
    59 procedure setTintAdd            (f: boolean); inline;
    59 procedure setTintAdd            (f: boolean); inline;
    60 
    60 
    62 
    62 
    63 // 0 => not offscreen, <0 => left/top of screen >0 => right/below of screen
    63 // 0 => not offscreen, <0 => left/top of screen >0 => right/below of screen
    64 function isDxAreaOffscreen(X, Width: LongInt): LongInt; inline;
    64 function isDxAreaOffscreen(X, Width: LongInt): LongInt; inline;
    65 function isDyAreaOffscreen(Y, Height: LongInt): LongInt; inline;
    65 function isDyAreaOffscreen(Y, Height: LongInt): LongInt; inline;
    66 
    66 
       
    67 
       
    68 procedure openglTranslProjMatrix(X, Y, Z: GLFloat); inline;
       
    69 procedure openglPushMatrix      (); inline;
       
    70 procedure openglPopMatrix       (); inline;
       
    71 procedure openglTranslatef      (X, Y, Z: GLfloat); inline;
       
    72 procedure openglScalef          (ScaleX, ScaleY, ScaleZ: GLfloat); inline;
       
    73 procedure openglRotatef         (RotX, RotY, RotZ: GLfloat; dir: LongInt); inline;
       
    74 procedure openglTint            (r, g, b, a: Byte); inline;
       
    75 
       
    76 
    67 implementation
    77 implementation
    68 uses uVariables;
    78 uses uVariables;
    69 
    79 
    70 {$IFDEF USE_TOUCH_INTERFACE}
    80 {$IFDEF USE_TOUCH_INTERFACE}
    71 const
    81 const
    90 function isDyAreaOffscreen(Y, Height: LongInt): LongInt; inline;
   100 function isDyAreaOffscreen(Y, Height: LongInt): LongInt; inline;
    91 begin
   101 begin
    92     if Y > ViewBottomY then exit(1);
   102     if Y > ViewBottomY then exit(1);
    93     if Y + Height < ViewTopY then exit(-1);
   103     if Y + Height < ViewTopY then exit(-1);
    94     isDyAreaOffscreen:= 0;
   104     isDyAreaOffscreen:= 0;
       
   105 end;
       
   106 
       
   107 procedure openglTranslProjMatrix(X, Y, Z: GLfloat); inline;
       
   108 begin
       
   109 {$IFDEF GL2}
       
   110     hglMatrixMode(MATRIX_PROJECTION);
       
   111     hglTranslatef(X, Y, Z);
       
   112     hglMatrixMode(MATRIX_MODELVIEW);
       
   113 {$ELSE}
       
   114     glMatrixMode(GL_PROJECTION);
       
   115     glTranslatef(X, Y, Z);
       
   116     glMatrixMode(GL_MODELVIEW);
       
   117 {$ENDIF}
       
   118 end;
       
   119 
       
   120 procedure openglPushMatrix(); inline;
       
   121 begin
       
   122 {$IFDEF GL2}h{$ENDIF}glPushMatrix();
       
   123 end;
       
   124 
       
   125 procedure openglPopMatrix(); inline;
       
   126 begin
       
   127 {$IFDEF GL2}h{$ENDIF}glPopMatrix();
       
   128 end;
       
   129 
       
   130 procedure openglTranslatef(X, Y, Z: GLfloat); inline;
       
   131 begin
       
   132 {$IFDEF GL2}h{$ENDIF}glTranslatef(X, Y, Z);
       
   133 end;
       
   134 
       
   135 procedure openglScalef(ScaleX, ScaleY, ScaleZ: GLfloat); inline;
       
   136 begin
       
   137 {$IFDEF GL2}h{$ENDIF}glScalef(ScaleX, ScaleY, ScaleZ);
       
   138 end;
       
   139 
       
   140 procedure openglRotatef(RotX, RotY, RotZ: GLfloat; dir: LongInt); inline;
       
   141 begin
       
   142 {$IFDEF GL2}h{$ENDIF}glRotatef(RotX, RotY, RotZ, dir);
       
   143 end;
       
   144 
       
   145 procedure openglUseColorOnly(b :boolean); inline;
       
   146 begin
       
   147     if b then
       
   148         begin
       
   149         {$IFDEF GL2}
       
   150         glDisableVertexAttribArray(aTexCoord);
       
   151         glEnableVertexAttribArray(aColor);
       
   152         {$ELSE}
       
   153         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
       
   154         glEnableClientState(GL_COLOR_ARRAY);
       
   155         {$ENDIF}
       
   156         end
       
   157     else
       
   158         begin
       
   159         {$IFDEF GL2}
       
   160         glDisableVertexAttribArray(aColor);
       
   161         glEnableVertexAttribArray(aTexCoord);
       
   162         {$ELSE}
       
   163         glDisableClientState(GL_COLOR_ARRAY);
       
   164         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
       
   165         {$ENDIF}
       
   166         end;
    95 end;
   167 end;
    96 
   168 
    97 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline;
   169 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline;
    98 begin
   170 begin
    99 r.y:= r.y + Height * Position;
   171 r.y:= r.y + Height * Position;
   180 end;
   252 end;
   181 
   253 
   182 procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
   254 procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
   183 begin
   255 begin
   184 
   256 
   185 {$IFDEF GL2}
   257 openglPushMatrix;
   186 hglPushMatrix;
   258 openglTranslatef(X, Y, 0);
   187 hglTranslatef(X, Y, 0);
   259 openglScalef(Scale, Scale, 1);
   188 hglScalef(Scale, Scale, 1);
       
   189 {$ELSE}
       
   190 glPushMatrix;
       
   191 glTranslatef(X, Y, 0);
       
   192 glScalef(Scale, Scale, 1);
       
   193 {$ENDIF}
       
   194 
   260 
   195 glBindTexture(GL_TEXTURE_2D, Texture^.id);
   261 glBindTexture(GL_TEXTURE_2D, Texture^.id);
   196 
   262 
   197 SetVertexPointer(@Texture^.vb, Length(Texture^.vb));
   263 SetVertexPointer(@Texture^.vb, Length(Texture^.vb));
   198 SetTexCoordPointer(@Texture^.tb, Length(Texture^.vb));
   264 SetTexCoordPointer(@Texture^.tb, Length(Texture^.vb));
   199 
   265 
   200 {$IFDEF GL2}
   266 {$IFDEF GL2}
   201 UpdateModelviewProjection;
   267 UpdateModelviewProjection;
       
   268 {$ENDIF}
       
   269 
   202 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
   270 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
   203 hglPopMatrix;
   271 openglPopMatrix;
   204 {$ELSE}
       
   205 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
       
   206 glPopMatrix;
       
   207 {$ENDIF}
       
   208 
   272 
   209 end;
   273 end;
   210 
   274 
   211 { this contains tweaks in order to avoid land tile borders in blurry land mode }
   275 { this contains tweaks in order to avoid land tile borders in blurry land mode }
   212 procedure DrawTexture2(X, Y: LongInt; Texture: PTexture; Scale, Overlap: GLfloat);
   276 procedure DrawTexture2(X, Y: LongInt; Texture: PTexture; Scale, Overlap: GLfloat);
   213 var
   277 var
   214     TextureBuffer: array [0..3] of TVertex2f;
   278     TextureBuffer: array [0..3] of TVertex2f;
   215 begin
   279 begin
   216 {$IFDEF GL2}
   280 openglPushMatrix;
   217 hglPushMatrix;
   281 openglTranslatef(X, Y, 0);
   218 hglTranslatef(X, Y, 0);
   282 openglScalef(Scale, Scale, 1);
   219 hglScalef(Scale, Scale, 1);
       
   220 {$ELSE}
       
   221 glPushMatrix;
       
   222 glTranslatef(X, Y, 0);
       
   223 glScalef(Scale, Scale, 1);
       
   224 {$ENDIF}
       
   225 
   283 
   226 glBindTexture(GL_TEXTURE_2D, Texture^.id);
   284 glBindTexture(GL_TEXTURE_2D, Texture^.id);
   227 
   285 
   228 TextureBuffer[0].X:= Texture^.tb[0].X + Overlap;
   286 TextureBuffer[0].X:= Texture^.tb[0].X + Overlap;
   229 TextureBuffer[0].Y:= Texture^.tb[0].Y + Overlap;
   287 TextureBuffer[0].Y:= Texture^.tb[0].Y + Overlap;
   237 SetVertexPointer(@Texture^.vb, Length(Texture^.vb));
   295 SetVertexPointer(@Texture^.vb, Length(Texture^.vb));
   238 SetTexCoordPointer(@TextureBuffer, Length(Texture^.vb));
   296 SetTexCoordPointer(@TextureBuffer, Length(Texture^.vb));
   239 
   297 
   240 {$IFDEF GL2}
   298 {$IFDEF GL2}
   241 UpdateModelviewProjection;
   299 UpdateModelviewProjection;
       
   300 {$ENDIF}
       
   301 
   242 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
   302 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
   243 hglPopMatrix;
   303 openglPopMatrix;
   244 {$ELSE}
       
   245 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
       
   246 glPopMatrix;
       
   247 {$ENDIF}
       
   248 end;
   304 end;
   249 
   305 
   250 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
   306 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
   251 begin
   307 begin
   252     DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
   308     DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
   261 if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then
   317 if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then
   262     exit;
   318     exit;
   263 if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then
   319 if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then
   264     exit;
   320     exit;
   265 
   321 
   266 {$IFDEF GL2}
   322 openglPushMatrix;
   267 hglPushMatrix;
   323 openglTranslatef(X, Y, 0);
   268 hglTranslatef(X, Y, 0);
       
   269 {$ELSE}
       
   270 glPushMatrix;
       
   271 glTranslatef(X, Y, 0);
       
   272 {$ENDIF}
       
   273 
   324 
   274 if Dir = 0 then Dir:= 1;
   325 if Dir = 0 then Dir:= 1;
   275 
   326 
   276 {$IFDEF GL2}
   327 openglRotatef(Angle, 0, 0, Dir);
   277 hglRotatef(Angle, 0, 0, Dir);
   328 
   278 hglTranslatef(Dir*OffsetX, OffsetY, 0);
   329 openglTranslatef(Dir*OffsetX, OffsetY, 0);
   279 hglScalef(Scale, Scale, 1);
   330 openglScalef(Scale, Scale, 1);
   280 {$ELSE}
       
   281 glRotatef(Angle, 0, 0, Dir);
       
   282 glTranslatef(Dir*OffsetX, OffsetY, 0);
       
   283 glScalef(Scale, Scale, 1);
       
   284 {$ENDIF}
       
   285 
   331 
   286 // Any reason for this call? And why only in t direction, not s?
   332 // Any reason for this call? And why only in t direction, not s?
   287 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   333 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   288 
   334 
   289 hw:= w div (2 div Dir);
   335 hw:= w div (2 div Dir);
   323 UpdateModelviewProjection;
   369 UpdateModelviewProjection;
   324 {$ENDIF}
   370 {$ENDIF}
   325 
   371 
   326 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   372 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   327 
   373 
   328 {$IFDEF GL2}
   374 openglPopMatrix;
   329 hglPopMatrix;
       
   330 {$ELSE}
       
   331 glPopMatrix;
       
   332 {$ENDIF}
       
   333 
   375 
   334 end;
   376 end;
   335 
   377 
   336 procedure DrawSpriteRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
   378 procedure DrawSpriteRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
   337 begin
   379 begin
   342 end;
   384 end;
   343 
   385 
   344 procedure DrawSpriteRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
   386 procedure DrawSpriteRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
   345 begin
   387 begin
   346 
   388 
   347 {$IFDEF GL2}
   389 openglPushMatrix;
   348 hglPushMatrix;
   390 openglTranslatef(X, Y, 0);
   349 hglTranslatef(X, Y, 0);
       
   350 {$ELSE}
       
   351 glPushMatrix;
       
   352 glTranslatef(X, Y, 0);
       
   353 {$ENDIF}
       
   354 
   391 
   355 if Dir < 0 then
   392 if Dir < 0 then
   356 {$IFDEF GL2}
   393     begin
   357     hglRotatef(Angle, 0, 0, -1)
   394     openglRotatef(Angle, 0, 0, -1);
   358 {$ELSE}
   395     openglScalef(-1.0, 1.0, 1.0);
   359     glRotatef(Angle, 0, 0, -1)
   396     end
   360 {$ENDIF}
       
   361 else
   397 else
   362 {$IFDEF GL2}
   398     openglRotatef(Angle, 0, 0,  1);
   363     hglRotatef(Angle, 0, 0,  1);
       
   364 {$ELSE}
       
   365     glRotatef(Angle, 0, 0,  1);
       
   366 {$ENDIF}
       
   367 if Dir < 0 then
       
   368 {$IFDEF GL2}
       
   369     hglScalef(-1.0, 1.0, 1.0);
       
   370 {$ELSE}
       
   371     glScalef(-1.0, 1.0, 1.0);
       
   372 {$ENDIF}
       
   373 
   399 
   374 DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
   400 DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
   375 
   401 
   376 {$IFDEF GL2}
   402 openglPopMatrix;
   377 hglPopMatrix;
       
   378 {$ELSE}
       
   379 glPopMatrix;
       
   380 {$ENDIF}
       
   381 
   403 
   382 end;
   404 end;
   383 
   405 
   384 procedure DrawTextureRotated(Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
   406 procedure DrawTextureRotated(Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
   385 var VertexBuffer: array [0..3] of TVertex2f;
   407 var VertexBuffer: array [0..3] of TVertex2f;
   388 if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then
   410 if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then
   389     exit;
   411     exit;
   390 if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then
   412 if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then
   391     exit;
   413     exit;
   392 
   414 
   393 {$IFDEF GL2}
   415 openglPushMatrix;
   394 hglPushMatrix;
   416 openglTranslatef(X, Y, 0);
   395 hglTranslatef(X, Y, 0);
       
   396 {$ELSE}
       
   397 glPushMatrix;
       
   398 glTranslatef(X, Y, 0);
       
   399 {$ENDIF}
       
   400 
   417 
   401 if Dir < 0 then
   418 if Dir < 0 then
   402     begin
   419     begin
   403     hw:= - hw;
   420     hw:= - hw;
   404 {$IFDEF GL2}
   421     openglRotatef(Angle, 0, 0, -1);
   405     hglRotatef(Angle, 0, 0, -1);
       
   406 {$ELSE}
       
   407     glRotatef(Angle, 0, 0, -1);
       
   408 {$ENDIF}
       
   409     end
   422     end
   410 else
   423 else
   411 {$IFDEF GL2}
   424     openglRotatef(Angle, 0, 0, 1);
   412     hglRotatef(Angle, 0, 0,  1);
       
   413 {$ELSE}
       
   414     glRotatef(Angle, 0, 0, 1);
       
   415 {$ENDIF}
       
   416 
   425 
   417 glBindTexture(GL_TEXTURE_2D, Texture^.id);
   426 glBindTexture(GL_TEXTURE_2D, Texture^.id);
   418 
   427 
   419 VertexBuffer[0].X:= -hw;
   428 VertexBuffer[0].X:= -hw;
   420 VertexBuffer[0].Y:= -hh;
   429 VertexBuffer[0].Y:= -hh;
   432 UpdateModelviewProjection;
   441 UpdateModelviewProjection;
   433 {$ENDIF}
   442 {$ENDIF}
   434 
   443 
   435 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   444 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   436 
   445 
   437 {$IFDEF GL2}
   446 openglPopMatrix;
   438 hglPopMatrix;
       
   439 {$ELSE}
       
   440 glPopMatrix;
       
   441 {$ENDIF}
       
   442 
   447 
   443 end;
   448 end;
   444 
   449 
   445 procedure DrawSprite(Sprite: TSprite; X, Y, Frame: LongInt);
   450 procedure DrawSprite(Sprite: TSprite; X, Y, Frame: LongInt);
   446 var row, col, numFramesFirstCol: LongInt;
   451 var row, col, numFramesFirstCol: LongInt;
   507 
   512 
   508 procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
   513 procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
   509 var VertexBuffer: array [0..1] of TVertex2f;
   514 var VertexBuffer: array [0..1] of TVertex2f;
   510 begin
   515 begin
   511     glEnable(GL_LINE_SMOOTH);
   516     glEnable(GL_LINE_SMOOTH);
   512 {$IFNDEF GL2}
   517 
   513     glDisable(GL_TEXTURE_2D);
   518     EnableTexture(False);
   514 
   519 
   515     glPushMatrix;
   520     openglPushMatrix;
   516     glTranslatef(WorldDx, WorldDy, 0);
   521     openglTranslatef(WorldDx, WorldDy, 0);
   517     glLineWidth(Width);
   522     glLineWidth(Width);
       
   523 
       
   524     {$IFDEF GL2}
       
   525     UpdateModelviewProjection;
       
   526     {$ENDIF}
   518 
   527 
   519     Tint(r, g, b, a);
   528     Tint(r, g, b, a);
   520     VertexBuffer[0].X:= X0;
   529     VertexBuffer[0].X:= X0;
   521     VertexBuffer[0].Y:= Y0;
   530     VertexBuffer[0].Y:= Y0;
   522     VertexBuffer[1].X:= X1;
   531     VertexBuffer[1].X:= X1;
   524 
   533 
   525     SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
   534     SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
   526     glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
   535     glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
   527     untint;
   536     untint;
   528 
   537 
   529     glPopMatrix;
   538     openglPopMatrix;
   530 
   539 
   531     glEnable(GL_TEXTURE_2D);
       
   532 
       
   533 {$ELSE}
       
   534     EnableTexture(False);
       
   535 
       
   536     hglPushMatrix;
       
   537     hglTranslatef(WorldDx, WorldDy, 0);
       
   538     glLineWidth(Width);
       
   539 
       
   540     UpdateModelviewProjection;
       
   541 
       
   542     Tint(r, g, b, a);
       
   543     VertexBuffer[0].X:= X0;
       
   544     VertexBuffer[0].Y:= Y0;
       
   545     VertexBuffer[1].X:= X1;
       
   546     VertexBuffer[1].Y:= Y1;
       
   547 
       
   548     SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
       
   549     glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
       
   550     Tint($FF, $FF, $FF, $FF);
       
   551 
       
   552     hglPopMatrix;
       
   553     EnableTexture(True);
   540     EnableTexture(True);
   554 
   541 
   555 {$ENDIF}
       
   556     glDisable(GL_LINE_SMOOTH);
   542     glDisable(GL_LINE_SMOOTH);
   557 end;
   543 end;
   558 
   544 
   559 procedure DrawFillRect(r: TSDL_Rect);
   545 procedure DrawFillRect(r: TSDL_Rect);
   560 var VertexBuffer: array [0..3] of TVertex2f;
   546 var VertexBuffer: array [0..3] of TVertex2f;
   564 if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) * cScaleFactor > cScreenWidth) then
   550 if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) * cScaleFactor > cScreenWidth) then
   565     exit;
   551     exit;
   566 if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) * cScaleFactor > cScreenHeight) then
   552 if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) * cScaleFactor > cScreenHeight) then
   567     exit;
   553     exit;
   568 
   554 
   569 {$IFDEF GL2}
       
   570 EnableTexture(False);
   555 EnableTexture(False);
   571 {$ELSE}
       
   572 glDisable(GL_TEXTURE_2D);
       
   573 {$ENDIF}
       
   574 
   556 
   575 Tint($00, $00, $00, $80);
   557 Tint($00, $00, $00, $80);
   576 
   558 
   577 VertexBuffer[0].X:= r.x;
   559 VertexBuffer[0].X:= r.x;
   578 VertexBuffer[0].Y:= r.y;
   560 VertexBuffer[0].Y:= r.y;
   585 
   567 
   586 SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
   568 SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
   587 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   569 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   588 
   570 
   589 untint;
   571 untint;
   590 {$IFDEF GL2}
   572 
   591 EnableTexture(True);
   573 EnableTexture(True);
   592 {$ELSE}
       
   593 glEnable(GL_TEXTURE_2D)
       
   594 {$ENDIF}
       
   595 
   574 
   596 end;
   575 end;
   597 
   576 
   598 procedure DrawCircle(X, Y, Radius, Width: LongInt; r, g, b, a: Byte);
   577 procedure DrawCircle(X, Y, Radius, Width: LongInt; r, g, b, a: Byte);
   599 begin
   578 begin
   610     for i := 0 to 59 do begin
   589     for i := 0 to 59 do begin
   611         CircleVertex[i].X := X + Radius*cos(i*pi/30);
   590         CircleVertex[i].X := X + Radius*cos(i*pi/30);
   612         CircleVertex[i].Y := Y + Radius*sin(i*pi/30);
   591         CircleVertex[i].Y := Y + Radius*sin(i*pi/30);
   613     end;
   592     end;
   614 
   593 
   615 {$IFNDEF GL2}
       
   616 
       
   617     glDisable(GL_TEXTURE_2D);
       
   618     glEnable(GL_LINE_SMOOTH);
       
   619     glPushMatrix;
       
   620     glLineWidth(Width);
       
   621     glVertexPointer(2, GL_FLOAT, 0, @CircleVertex[0]);
       
   622     glDrawArrays(GL_LINE_LOOP, 0, 60);
       
   623     glPopMatrix;
       
   624     glEnable(GL_TEXTURE_2D);
       
   625     glDisable(GL_LINE_SMOOTH);
       
   626 
       
   627 {$ELSE}
       
   628     EnableTexture(False);
   594     EnableTexture(False);
   629     glEnable(GL_LINE_SMOOTH);
   595     glEnable(GL_LINE_SMOOTH);
   630     hglPushMatrix;
   596     openglPushMatrix;
   631     glLineWidth(Width);
   597     glLineWidth(Width);
   632     SetVertexPointer(@CircleVertex[0], 60);
   598     SetVertexPointer(@CircleVertex[0], 60);
   633     glDrawArrays(GL_LINE_LOOP, 0, 60);
   599     glDrawArrays(GL_LINE_LOOP, 0, 60);
   634     hglPopMatrix;
   600     openglPopMatrix;
   635     EnableTexture(True);
   601     EnableTexture(True);
   636     glDisable(GL_LINE_SMOOTH);
   602     glDisable(GL_LINE_SMOOTH);
   637 {$ENDIF}
       
   638 end;
   603 end;
   639 
   604 
   640 
   605 
   641 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
   606 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
   642 const VertexBuffer: array [0..3] of TVertex2f = (
   607 const VertexBuffer: array [0..3] of TVertex2f = (
   665         begin
   630         begin
   666         l:= Step * 32 / HHTexture^.w;
   631         l:= Step * 32 / HHTexture^.w;
   667         r:= (Step + 1) * 32 / HHTexture^.w
   632         r:= (Step + 1) * 32 / HHTexture^.w
   668     end;
   633     end;
   669 
   634 
   670 {$IFDEF GL2}
   635     openglPushMatrix();
   671     hglPushMatrix();
   636     openglTranslatef(X, Y, 0);
   672     hglTranslatef(X, Y, 0);
   637     openglRotatef(Angle, 0, 0, 1);
   673     hglRotatef(Angle, 0, 0, 1);
       
   674 {$ELSE}
       
   675     glPushMatrix();
       
   676     glTranslatef(X, Y, 0);
       
   677     glRotatef(Angle, 0, 0, 1);
       
   678 {$ENDIF}
       
   679 
   638 
   680     glBindTexture(GL_TEXTURE_2D, HHTexture^.id);
   639     glBindTexture(GL_TEXTURE_2D, HHTexture^.id);
   681 
   640 
   682     TextureBuffer[0].X:= l;
   641     TextureBuffer[0].X:= l;
   683     TextureBuffer[0].Y:= t;
   642     TextureBuffer[0].Y:= t;
   695     UpdateModelviewProjection;
   654     UpdateModelviewProjection;
   696 {$ENDIF}
   655 {$ENDIF}
   697 
   656 
   698     glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   657     glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   699 
   658 
   700 {$IFDEF GL2}
   659     openglPopMatrix;
   701     hglPopMatrix;
       
   702 {$ELSE}
       
   703     glPopMatrix;
       
   704 {$ENDIF}
       
   705 end;
   660 end;
   706 
   661 
   707 procedure DrawScreenWidget(widget: POnScreenWidget);
   662 procedure DrawScreenWidget(widget: POnScreenWidget);
   708 {$IFDEF USE_TOUCH_INTERFACE}
   663 {$IFDEF USE_TOUCH_INTERFACE}
   709 var alpha: byte = $FF;
   664 var alpha: byte = $FF;
   749 begin
   704 begin
   750 widget:= widget; // avoid hint
   705 widget:= widget; // avoid hint
   751 {$ENDIF}
   706 {$ENDIF}
   752 end;
   707 end;
   753 
   708 
       
   709 procedure BeginWater;
       
   710 begin
       
   711 {$IFDEF GL2}
       
   712     glUseProgram(shaderWater);
       
   713     uCurrentMVPLocation:=uWaterMVPLocation;
       
   714     UpdateModelviewProjection;
       
   715     glDisableVertexAttribArray(aTexCoord);
       
   716     glEnableVertexAttribArray(aColor);
       
   717 {$ENDIF}
       
   718 
       
   719     openglUseColorOnly(true);
       
   720 end;
       
   721 
       
   722 procedure EndWater;
       
   723 begin
       
   724 {$IFDEF GL2}
       
   725     glUseProgram(shaderMain);
       
   726     uCurrentMVPLocation:=uMainMVPLocation;
       
   727     UpdateModelviewProjection;
       
   728     glDisableVertexAttribArray(aColor);
       
   729     glEnableVertexAttribArray(aTexCoord);
       
   730 {$ENDIF}
       
   731 
       
   732     openglUseColorOnly(false);
       
   733 end;
       
   734 
       
   735 procedure DrawWaterBody(pVertexBuffer: Pointer; length: LongInt);
       
   736 begin
       
   737 {$IFDEF GL2}
       
   738         UpdateModelviewProjection;
       
   739 {$ENDIF}
       
   740 
       
   741         BeginWater;
       
   742         if SuddenDeathDmg then
       
   743             SetColorPointer(@SDWaterColorArray[0], 4)
       
   744         else
       
   745             SetColorPointer(@WaterColorArray[0], 4);
       
   746 
       
   747         SetVertexPointer(pVertexBuffer, 4);
       
   748 
       
   749         glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
       
   750 
       
   751         EndWater;
       
   752 end;
       
   753 
   754 procedure openglTint(r, g, b, a: Byte); inline;
   754 procedure openglTint(r, g, b, a: Byte); inline;
   755 {$IFDEF GL2}
   755 {$IFDEF GL2}
   756 const
   756 const
   757     scale:Real = 1.0/255.0;
   757     scale:Real = 1.0/255.0;
   758 {$ENDIF}
   758 {$ENDIF}