hedgewars/uRender.pas
changeset 10015 4feced261c68
parent 9998 736015b847e3
parent 9950 2759212a27de
child 10040 4ac87acbaed9
equal deleted inserted replaced
10014:56d2f2d5aad8 10015:4feced261c68
    15  * along with this program; if not, write to the Free Software
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17  *)
    17  *)
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
       
    20 {$IF GLunit = GL}{$DEFINE GLunit:=GL,GLext}{$ENDIF}
    20 
    21 
    21 unit uRender;
    22 unit uRender;
    22 
    23 
    23 interface
    24 interface
    24 
    25 
    25 uses SDLh, uTypes, GLunit, uConsts;
    26 uses SDLh, uTypes, GLunit, uConsts, uStore{$IFDEF GL2}, uMatrix{$ENDIF};
    26 
    27 
    27 procedure DrawSprite            (Sprite: TSprite; X, Y, Frame: LongInt);
    28 procedure DrawSprite            (Sprite: TSprite; X, Y, Frame: LongInt);
    28 procedure DrawSprite            (Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
    29 procedure DrawSprite            (Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
    29 procedure DrawSpriteFromRect    (Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline;
    30 procedure DrawSpriteFromRect    (Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline;
    30 procedure DrawSpriteClipped     (Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
    31 procedure DrawSpriteClipped     (Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt);
    53 procedure Tint                  (r, g, b, a: Byte); inline;
    54 procedure Tint                  (r, g, b, a: Byte); inline;
    54 procedure Tint                  (c: Longword); inline;
    55 procedure Tint                  (c: Longword); inline;
    55 procedure untint(); inline;
    56 procedure untint(); inline;
    56 procedure setTintAdd            (f: boolean); inline;
    57 procedure setTintAdd            (f: boolean); inline;
    57 
    58 
    58 
       
    59 implementation
    59 implementation
    60 uses uVariables;
    60 uses uVariables;
    61 
    61 
    62 {$IFDEF USE_TOUCH_INTERFACE}
    62 {$IFDEF USE_TOUCH_INTERFACE}
    63 const
    63 const
    76 
    76 
    77 procedure DrawTextureFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
    77 procedure DrawTextureFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
    78 begin
    78 begin
    79 DrawTextureFromRectDir(X, Y, r^.w, r^.h, r, SourceTexture, 1)
    79 DrawTextureFromRectDir(X, Y, r^.w, r^.h, r, SourceTexture, 1)
    80 end;
    80 end;
       
    81 
    81 procedure DrawTextureFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
    82 procedure DrawTextureFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline;
    82 begin
    83 begin
    83 DrawTextureFromRectDir(X, Y, W, H, r, SourceTexture, 1)
    84 DrawTextureFromRectDir(X, Y, W, H, r, SourceTexture, 1)
    84 end;
    85 end;
    85 
    86 
   141 TextureBuffer[3].X:= _l;
   142 TextureBuffer[3].X:= _l;
   142 TextureBuffer[3].Y:= _b;
   143 TextureBuffer[3].Y:= _b;
   143 
   144 
   144 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   145 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   145 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
   146 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
   146 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   147 glDrawArrays(GL_TRIANGLE_FAN, 0, High(VertexBuffer) - Low(VertexBuffer) + 1);
   147 end;
   148 end;
   148 
   149 
   149 procedure DrawTexture(X, Y: LongInt; Texture: PTexture); inline;
   150 procedure DrawTexture(X, Y: LongInt; Texture: PTexture); inline;
   150 begin
   151 begin
   151     DrawTexture(X, Y, Texture, 1.0);
   152     DrawTexture(X, Y, Texture, 1.0);
   152 end;
   153 end;
   153 
   154 
   154 procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
   155 procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat);
   155 begin
   156 begin
   156 
   157 
       
   158 {$IFDEF GL2}
       
   159 hglPushMatrix;
       
   160 hglTranslatef(X, Y, 0);
       
   161 hglScalef(Scale, Scale, 1);
       
   162 {$ELSE}
   157 glPushMatrix;
   163 glPushMatrix;
   158 glTranslatef(X, Y, 0);
   164 glTranslatef(X, Y, 0);
   159 glScalef(Scale, Scale, 1);
   165 glScalef(Scale, Scale, 1);
       
   166 {$ENDIF}
   160 
   167 
   161 glBindTexture(GL_TEXTURE_2D, Texture^.id);
   168 glBindTexture(GL_TEXTURE_2D, Texture^.id);
   162 
   169 
   163 glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb);
   170 SetVertexPointer(@Texture^.vb, Length(Texture^.vb));
   164 glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb);
   171 SetTexCoordPointer(@Texture^.tb, Length(Texture^.vb));
       
   172 
       
   173 {$IFDEF GL2}
       
   174 UpdateModelviewProjection;
   165 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
   175 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
   166 
   176 hglPopMatrix;
   167 glPopMatrix
   177 {$ELSE}
       
   178 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb));
       
   179 glPopMatrix;
       
   180 {$ENDIF}
       
   181 
   168 end;
   182 end;
   169 
   183 
   170 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
   184 procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt);
   171 begin
   185 begin
   172     DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
   186     DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0)
   181 if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then
   195 if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then
   182     exit;
   196     exit;
   183 if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then
   197 if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then
   184     exit;
   198     exit;
   185 
   199 
       
   200 {$IFDEF GL2}
       
   201 hglPushMatrix;
       
   202 hglTranslatef(X, Y, 0);
       
   203 {$ELSE}
   186 glPushMatrix;
   204 glPushMatrix;
   187 glTranslatef(X, Y, 0);
   205 glTranslatef(X, Y, 0);
       
   206 {$ENDIF}
       
   207 
   188 if Dir = 0 then Dir:= 1;
   208 if Dir = 0 then Dir:= 1;
   189 
   209 
       
   210 {$IFDEF GL2}
       
   211 hglRotatef(Angle, 0, 0, Dir);
       
   212 hglTranslatef(Dir*OffsetX, OffsetY, 0);
       
   213 hglScalef(Scale, Scale, 1);
       
   214 {$ELSE}
   190 glRotatef(Angle, 0, 0, Dir);
   215 glRotatef(Angle, 0, 0, Dir);
   191 
       
   192 glTranslatef(Dir*OffsetX, OffsetY, 0);
   216 glTranslatef(Dir*OffsetX, OffsetY, 0);
   193 glScalef(Scale, Scale, 1);
   217 glScalef(Scale, Scale, 1);
       
   218 {$ENDIF}
   194 
   219 
   195 // Any reason for this call? And why only in t direction, not s?
   220 // Any reason for this call? And why only in t direction, not s?
   196 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   221 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   197 
   222 
   198 hw:= w div (2 div Dir);
   223 hw:= w div (2 div Dir);
   223 TextureBuffer[2].X:= fr;
   248 TextureBuffer[2].X:= fr;
   224 TextureBuffer[2].Y:= fb;
   249 TextureBuffer[2].Y:= fb;
   225 TextureBuffer[3].X:= fl;
   250 TextureBuffer[3].X:= fl;
   226 TextureBuffer[3].Y:= fb;
   251 TextureBuffer[3].Y:= fb;
   227 
   252 
   228 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   253 SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
   229 glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
   254 SetTexCoordPointer(@TextureBuffer[0], Length(VertexBuffer));
       
   255 
       
   256 {$IFDEF GL2}
       
   257 UpdateModelviewProjection;
       
   258 {$ENDIF}
       
   259 
   230 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   260 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   231 
   261 
   232 glPopMatrix
   262 {$IFDEF GL2}
       
   263 hglPopMatrix;
       
   264 {$ELSE}
       
   265 glPopMatrix;
       
   266 {$ENDIF}
       
   267 
   233 end;
   268 end;
   234 
   269 
   235 procedure DrawSpriteRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
   270 procedure DrawSpriteRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
   236 begin
   271 begin
   237     DrawTextureRotated(SpritesData[Sprite].Texture,
   272     DrawTextureRotated(SpritesData[Sprite].Texture,
   240         X, Y, Dir, Angle)
   275         X, Y, Dir, Angle)
   241 end;
   276 end;
   242 
   277 
   243 procedure DrawSpriteRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
   278 procedure DrawSpriteRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real);
   244 begin
   279 begin
       
   280 
       
   281 {$IFDEF GL2}
       
   282 hglPushMatrix;
       
   283 hglTranslatef(X, Y, 0);
       
   284 {$ELSE}
   245 glPushMatrix;
   285 glPushMatrix;
   246 glTranslatef(X, Y, 0);
   286 glTranslatef(X, Y, 0);
       
   287 {$ENDIF}
   247 
   288 
   248 if Dir < 0 then
   289 if Dir < 0 then
       
   290 {$IFDEF GL2}
       
   291     hglRotatef(Angle, 0, 0, -1)
       
   292 {$ELSE}
   249     glRotatef(Angle, 0, 0, -1)
   293     glRotatef(Angle, 0, 0, -1)
       
   294 {$ENDIF}
   250 else
   295 else
       
   296 {$IFDEF GL2}
       
   297     hglRotatef(Angle, 0, 0,  1);
       
   298 {$ELSE}
   251     glRotatef(Angle, 0, 0,  1);
   299     glRotatef(Angle, 0, 0,  1);
       
   300 {$ENDIF}
   252 if Dir < 0 then
   301 if Dir < 0 then
       
   302 {$IFDEF GL2}
       
   303     hglScalef(-1.0, 1.0, 1.0);
       
   304 {$ELSE}
   253     glScalef(-1.0, 1.0, 1.0);
   305     glScalef(-1.0, 1.0, 1.0);
       
   306 {$ENDIF}
   254 
   307 
   255 DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
   308 DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
   256 
   309 
   257 glPopMatrix
   310 {$IFDEF GL2}
       
   311 hglPopMatrix;
       
   312 {$ELSE}
       
   313 glPopMatrix;
       
   314 {$ENDIF}
       
   315 
   258 end;
   316 end;
   259 
   317 
   260 procedure DrawTextureRotated(Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
   318 procedure DrawTextureRotated(Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
   261 var VertexBuffer: array [0..3] of TVertex2f;
   319 var VertexBuffer: array [0..3] of TVertex2f;
   262 begin
   320 begin
   264 if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then
   322 if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then
   265     exit;
   323     exit;
   266 if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then
   324 if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then
   267     exit;
   325     exit;
   268 
   326 
       
   327 {$IFDEF GL2}
       
   328 hglPushMatrix;
       
   329 hglTranslatef(X, Y, 0);
       
   330 {$ELSE}
   269 glPushMatrix;
   331 glPushMatrix;
   270 glTranslatef(X, Y, 0);
   332 glTranslatef(X, Y, 0);
       
   333 {$ENDIF}
   271 
   334 
   272 if Dir < 0 then
   335 if Dir < 0 then
   273     begin
   336     begin
   274     hw:= - hw;
   337     hw:= - hw;
       
   338 {$IFDEF GL2}
       
   339     hglRotatef(Angle, 0, 0, -1);
       
   340 {$ELSE}
   275     glRotatef(Angle, 0, 0, -1);
   341     glRotatef(Angle, 0, 0, -1);
       
   342 {$ENDIF}
   276     end
   343     end
   277 else
   344 else
   278     glRotatef(Angle, 0, 0,  1);
   345 {$IFDEF GL2}
   279 
   346     hglRotatef(Angle, 0, 0,  1);
       
   347 {$ELSE}
       
   348     glRotatef(Angle, 0, 0, 1);
       
   349 {$ENDIF}
   280 
   350 
   281 glBindTexture(GL_TEXTURE_2D, Texture^.id);
   351 glBindTexture(GL_TEXTURE_2D, Texture^.id);
   282 
   352 
   283 VertexBuffer[0].X:= -hw;
   353 VertexBuffer[0].X:= -hw;
   284 VertexBuffer[0].Y:= -hh;
   354 VertexBuffer[0].Y:= -hh;
   287 VertexBuffer[2].X:= hw;
   357 VertexBuffer[2].X:= hw;
   288 VertexBuffer[2].Y:= hh;
   358 VertexBuffer[2].Y:= hh;
   289 VertexBuffer[3].X:= -hw;
   359 VertexBuffer[3].X:= -hw;
   290 VertexBuffer[3].Y:= hh;
   360 VertexBuffer[3].Y:= hh;
   291 
   361 
   292 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   362 SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
   293 glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb);
   363 SetTexCoordPointer(@Texture^.tb, Length(VertexBuffer));
       
   364 
       
   365 {$IFDEF GL2}
       
   366 UpdateModelviewProjection;
       
   367 {$ENDIF}
       
   368 
   294 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   369 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   295 
   370 
   296 glPopMatrix
   371 {$IFDEF GL2}
       
   372 hglPopMatrix;
       
   373 {$ELSE}
       
   374 glPopMatrix;
       
   375 {$ENDIF}
       
   376 
   297 end;
   377 end;
   298 
   378 
   299 procedure DrawSprite(Sprite: TSprite; X, Y, Frame: LongInt);
   379 procedure DrawSprite(Sprite: TSprite; X, Y, Frame: LongInt);
   300 var row, col, numFramesFirstCol: LongInt;
   380 var row, col, numFramesFirstCol: LongInt;
   301 begin
   381 begin
   333 if (Y + SpritesData[Sprite].Height > BottomY) then
   413 if (Y + SpritesData[Sprite].Height > BottomY) then
   334     r.h:= BottomY - Y + 1;
   414     r.h:= BottomY - Y + 1;
   335 if (X + SpritesData[Sprite].Width > RightX) then
   415 if (X + SpritesData[Sprite].Width > RightX) then
   336     r.w:= RightX - X + 1;
   416     r.w:= RightX - X + 1;
   337 
   417 
   338 if (r.h < r.y) or (r.w < r.x) then 
   418 if (r.h < r.y) or (r.w < r.x) then
   339     exit;
   419     exit;
   340 
   420 
   341 dec(r.h, r.y);
   421 dec(r.h, r.y);
   342 dec(r.w, r.x);
   422 dec(r.w, r.x);
   343 
   423 
   360 end;
   440 end;
   361 
   441 
   362 procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
   442 procedure DrawLine(X0, Y0, X1, Y1, Width: Single; r, g, b, a: Byte);
   363 var VertexBuffer: array [0..1] of TVertex2f;
   443 var VertexBuffer: array [0..1] of TVertex2f;
   364 begin
   444 begin
       
   445     glEnable(GL_LINE_SMOOTH);
       
   446 {$IFNDEF GL2}
   365     glDisable(GL_TEXTURE_2D);
   447     glDisable(GL_TEXTURE_2D);
   366     glEnable(GL_LINE_SMOOTH);
       
   367 
   448 
   368     glPushMatrix;
   449     glPushMatrix;
   369     glTranslatef(WorldDx, WorldDy, 0);
   450     glTranslatef(WorldDx, WorldDy, 0);
   370     glLineWidth(Width);
   451     glLineWidth(Width);
   371 
   452 
   373     VertexBuffer[0].X:= X0;
   454     VertexBuffer[0].X:= X0;
   374     VertexBuffer[0].Y:= Y0;
   455     VertexBuffer[0].Y:= Y0;
   375     VertexBuffer[1].X:= X1;
   456     VertexBuffer[1].X:= X1;
   376     VertexBuffer[1].Y:= Y1;
   457     VertexBuffer[1].Y:= Y1;
   377 
   458 
   378     glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   459     SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
   379     glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
   460     glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
   380     untint;
   461     untint;
   381     
   462 
   382     glPopMatrix;
   463     glPopMatrix;
   383     
   464 
   384     glEnable(GL_TEXTURE_2D);
   465     glEnable(GL_TEXTURE_2D);
       
   466 
       
   467 {$ELSE}
       
   468     EnableTexture(False);
       
   469 
       
   470     hglPushMatrix;
       
   471     hglTranslatef(WorldDx, WorldDy, 0);
       
   472     glLineWidth(Width);
       
   473 
       
   474     UpdateModelviewProjection;
       
   475 
       
   476     Tint(r, g, b, a);
       
   477     VertexBuffer[0].X:= X0;
       
   478     VertexBuffer[0].Y:= Y0;
       
   479     VertexBuffer[1].X:= X1;
       
   480     VertexBuffer[1].Y:= Y1;
       
   481 
       
   482     SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
       
   483     glDrawArrays(GL_LINES, 0, Length(VertexBuffer));
       
   484     Tint($FF, $FF, $FF, $FF);
       
   485 
       
   486     hglPopMatrix;
       
   487     EnableTexture(True);
       
   488 
       
   489 {$ENDIF}
   385     glDisable(GL_LINE_SMOOTH);
   490     glDisable(GL_LINE_SMOOTH);
   386 end;
   491 end;
   387 
   492 
   388 procedure DrawFillRect(r: TSDL_Rect);
   493 procedure DrawFillRect(r: TSDL_Rect);
   389 var VertexBuffer: array [0..3] of TVertex2f;
   494 var VertexBuffer: array [0..3] of TVertex2f;
   390 begin
   495 begin
   391 // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
   496 // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
       
   497 
   392 if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) * cScaleFactor > cScreenWidth) then
   498 if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) * cScaleFactor > cScreenWidth) then
   393     exit;
   499     exit;
   394 if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) * cScaleFactor > cScreenHeight) then
   500 if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) * cScaleFactor > cScreenHeight) then
   395     exit;
   501     exit;
   396 
   502 
       
   503 {$IFDEF GL2}
       
   504 EnableTexture(False);
       
   505 {$ELSE}
   397 glDisable(GL_TEXTURE_2D);
   506 glDisable(GL_TEXTURE_2D);
       
   507 {$ENDIF}
   398 
   508 
   399 Tint($00, $00, $00, $80);
   509 Tint($00, $00, $00, $80);
   400 
   510 
   401 VertexBuffer[0].X:= r.x;
   511 VertexBuffer[0].X:= r.x;
   402 VertexBuffer[0].Y:= r.y;
   512 VertexBuffer[0].Y:= r.y;
   405 VertexBuffer[2].X:= r.x + r.w;
   515 VertexBuffer[2].X:= r.x + r.w;
   406 VertexBuffer[2].Y:= r.y + r.h;
   516 VertexBuffer[2].Y:= r.y + r.h;
   407 VertexBuffer[3].X:= r.x;
   517 VertexBuffer[3].X:= r.x;
   408 VertexBuffer[3].Y:= r.y + r.h;
   518 VertexBuffer[3].Y:= r.y + r.h;
   409 
   519 
   410 glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   520 SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
   411 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   521 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   412 
   522 
   413 untint;
   523 untint;
       
   524 {$IFDEF GL2}
       
   525 EnableTexture(True);
       
   526 {$ELSE}
   414 glEnable(GL_TEXTURE_2D)
   527 glEnable(GL_TEXTURE_2D)
   415 end;
   528 {$ENDIF}
   416 
   529 
   417 procedure DrawCircle(X, Y, Radius, Width: LongInt; r, g, b, a: Byte); 
   530 end;
       
   531 
       
   532 procedure DrawCircle(X, Y, Radius, Width: LongInt; r, g, b, a: Byte);
   418 begin
   533 begin
   419     Tint(r, g, b, a);
   534     Tint(r, g, b, a);
   420     DrawCircle(X, Y, Radius, Width); 
   535     DrawCircle(X, Y, Radius, Width);
   421     untint;
   536     untint;
   422 end;
   537 end;
   423 
   538 
   424 procedure DrawCircle(X, Y, Radius, Width: LongInt); 
   539 procedure DrawCircle(X, Y, Radius, Width: LongInt);
   425 var
   540 var
   426     i: LongInt;
   541     i: LongInt;
   427     CircleVertex: array [0..59] of TVertex2f;
   542     CircleVertex: array [0..59] of TVertex2f;
   428 begin
   543 begin
   429     for i := 0 to 59 do begin
   544     for i := 0 to 59 do begin
   430         CircleVertex[i].X := X + Radius*cos(i*pi/30);
   545         CircleVertex[i].X := X + Radius*cos(i*pi/30);
   431         CircleVertex[i].Y := Y + Radius*sin(i*pi/30);
   546         CircleVertex[i].Y := Y + Radius*sin(i*pi/30);
   432     end;
   547     end;
       
   548 
       
   549 {$IFNDEF GL2}
       
   550 
   433     glDisable(GL_TEXTURE_2D);
   551     glDisable(GL_TEXTURE_2D);
   434     glEnable(GL_LINE_SMOOTH);
   552     glEnable(GL_LINE_SMOOTH);
   435     glPushMatrix;
   553     glPushMatrix;
   436     glLineWidth(Width);
   554     glLineWidth(Width);
   437     glVertexPointer(2, GL_FLOAT, 0, @CircleVertex[0]);
   555     glVertexPointer(2, GL_FLOAT, 0, @CircleVertex[0]);
   438     glDrawArrays(GL_LINE_LOOP, 0, 60);
   556     glDrawArrays(GL_LINE_LOOP, 0, 60);
   439     glPopMatrix;
   557     glPopMatrix;
   440     glEnable(GL_TEXTURE_2D);
   558     glEnable(GL_TEXTURE_2D);
   441     glDisable(GL_LINE_SMOOTH);
   559     glDisable(GL_LINE_SMOOTH);
       
   560 
       
   561 {$ELSE}
       
   562     EnableTexture(False);
       
   563     glEnable(GL_LINE_SMOOTH);
       
   564     hglPushMatrix;
       
   565     glLineWidth(Width);
       
   566     SetVertexPointer(@CircleVertex[0], 60);
       
   567     glDrawArrays(GL_LINE_LOOP, 0, 60);
       
   568     hglPopMatrix;
       
   569     EnableTexture(True);
       
   570     glDisable(GL_LINE_SMOOTH);
       
   571 {$ENDIF}
   442 end;
   572 end;
   443 
   573 
   444 
   574 
   445 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
   575 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
   446 const VertexBuffer: array [0..3] of TVertex2f = (
   576 const VertexBuffer: array [0..3] of TVertex2f = (
   469         begin
   599         begin
   470         l:= Step * 32 / HHTexture^.w;
   600         l:= Step * 32 / HHTexture^.w;
   471         r:= (Step + 1) * 32 / HHTexture^.w
   601         r:= (Step + 1) * 32 / HHTexture^.w
   472     end;
   602     end;
   473 
   603 
   474 
   604 {$IFDEF GL2}
       
   605     hglPushMatrix();
       
   606     hglTranslatef(X, Y, 0);
       
   607     hglRotatef(Angle, 0, 0, 1);
       
   608 {$ELSE}
   475     glPushMatrix();
   609     glPushMatrix();
   476     glTranslatef(X, Y, 0);
   610     glTranslatef(X, Y, 0);
   477     glRotatef(Angle, 0, 0, 1);
   611     glRotatef(Angle, 0, 0, 1);
       
   612 {$ENDIF}
   478 
   613 
   479     glBindTexture(GL_TEXTURE_2D, HHTexture^.id);
   614     glBindTexture(GL_TEXTURE_2D, HHTexture^.id);
   480 
   615 
   481     TextureBuffer[0].X:= l;
   616     TextureBuffer[0].X:= l;
   482     TextureBuffer[0].Y:= t;
   617     TextureBuffer[0].Y:= t;
   485     TextureBuffer[2].X:= r;
   620     TextureBuffer[2].X:= r;
   486     TextureBuffer[2].Y:= b;
   621     TextureBuffer[2].Y:= b;
   487     TextureBuffer[3].X:= l;
   622     TextureBuffer[3].X:= l;
   488     TextureBuffer[3].Y:= b;
   623     TextureBuffer[3].Y:= b;
   489 
   624 
   490     glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
   625     SetVertexPointer(@VertexBuffer[0], Length(VertexBuffer));
   491     glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
   626     SetTexCoordPointer(@TextureBuffer[0], Length(VertexBuffer));
       
   627 
       
   628 {$IFDEF GL2}
       
   629     UpdateModelviewProjection;
       
   630 {$ENDIF}
       
   631 
   492     glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   632     glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
   493 
   633 
   494     glPopMatrix
   634 {$IFDEF GL2}
       
   635     hglPopMatrix;
       
   636 {$ELSE}
       
   637     glPopMatrix;
       
   638 {$ENDIF}
   495 end;
   639 end;
   496 
   640 
   497 procedure DrawScreenWidget(widget: POnScreenWidget);
   641 procedure DrawScreenWidget(widget: POnScreenWidget);
   498 {$IFDEF USE_TOUCH_INTERFACE}
   642 {$IFDEF USE_TOUCH_INTERFACE}
   499 var alpha: byte = $FF;
   643 var alpha: byte = $FF;
   503     if (fadeAnimStart <> 0) then
   647     if (fadeAnimStart <> 0) then
   504         begin
   648         begin
   505         if RealTicks > (fadeAnimStart + FADE_ANIM_TIME) then
   649         if RealTicks > (fadeAnimStart + FADE_ANIM_TIME) then
   506             fadeAnimStart:= 0
   650             fadeAnimStart:= 0
   507         else
   651         else
   508             if show then 
   652             if show then
   509                 alpha:= Byte(trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF))
   653                 alpha:= Byte(trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF))
   510             else 
   654             else
   511                 alpha:= Byte($FF - trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF));
   655                 alpha:= Byte($FF - trunc((RealTicks - fadeAnimStart)/FADE_ANIM_TIME * $FF));
   512         end;
   656         end;
   513 
   657 
   514     with moveAnim do
   658     with moveAnim do
   515         if animate then
   659         if animate then
   540 widget:= widget; // avoid hint
   684 widget:= widget; // avoid hint
   541 {$ENDIF}
   685 {$ENDIF}
   542 end;
   686 end;
   543 
   687 
   544 procedure Tint(r, g, b, a: Byte); inline;
   688 procedure Tint(r, g, b, a: Byte); inline;
   545 var nc, tw: Longword;
   689 var
       
   690     nc, tw: Longword;
       
   691     {$IFDEF GL2}
       
   692     scale:Real = 1.0/255.0;
       
   693     {$ENDIF}
   546 begin
   694 begin
   547     nc:= (r shl 24) or (g shl 16) or (b shl 8) or a;
   695     nc:= (r shl 24) or (g shl 16) or (b shl 8) or a;
   548 
   696 
   549     if nc = lastTint then
   697     if nc = lastTint then
   550         exit;
   698         exit;
   557         r:= tw;
   705         r:= tw;
   558         g:= tw;
   706         g:= tw;
   559         b:= tw
   707         b:= tw
   560         end;
   708         end;
   561 
   709 
       
   710     {$IFDEF GL2}
       
   711     glUniform4f(uMainTintLocation, r*scale, g*scale, b*scale, a*scale);
       
   712     //glColor4ub(r, g, b, a);
       
   713     {$ELSE}
   562     glColor4ub(r, g, b, a);
   714     glColor4ub(r, g, b, a);
       
   715     {$ENDIF}
   563     lastTint:= nc;
   716     lastTint:= nc;
   564 end;
   717 end;
   565 
   718 
   566 procedure Tint(c: Longword); inline;
   719 procedure Tint(c: Longword); inline;
   567 begin
   720 begin