328 DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0) |
328 DrawTextureRotatedF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0) |
329 end; |
329 end; |
330 |
330 |
331 procedure DrawTextureRotatedF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
331 procedure DrawTextureRotatedF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
332 var ft, fb, fl, fr: GLfloat; |
332 var ft, fb, fl, fr: GLfloat; |
333 hw, nx, ny: LongInt; |
333 hw, hh, nx, ny: LongInt; |
334 VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
334 VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
335 begin |
335 begin |
336 // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
336 // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
337 if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then |
337 if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) * cScaleFactor > cScreenWidth) then |
338 exit; |
338 exit; |
339 if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then |
339 if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) * cScaleFactor > cScreenHeight) then |
340 exit; |
340 exit; |
341 |
341 |
342 openglPushMatrix; |
342 openglPushMatrix; |
|
343 |
343 openglTranslatef(X, Y, 0); |
344 openglTranslatef(X, Y, 0); |
344 |
345 |
345 if Dir = 0 then Dir:= 1; |
346 if Dir = 0 then Dir:= 1; |
346 |
347 |
347 openglRotatef(Angle, 0, 0, Dir); |
348 if Angle <> 0 then |
348 |
349 openglRotatef(Angle, 0, 0, Dir); |
349 openglTranslatef(Dir*OffsetX, OffsetY, 0); |
350 |
350 openglScalef(Scale, Scale, 1); |
351 if (OffsetX <> 0) or (OffsetY <> 0) then |
|
352 openglTranslatef(Dir*OffsetX, OffsetY, 0); |
|
353 |
|
354 if Scale <> 1.0 then |
|
355 openglScalef(Scale, Scale, 1); |
351 |
356 |
352 // Any reason for this call? And why only in t direction, not s? |
357 // Any reason for this call? And why only in t direction, not s? |
353 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
358 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
354 |
359 |
355 hw:= w div (2 div Dir); |
360 if Dir > 0 then |
356 |
361 hw:= w div 2 |
357 nx:= round(Texture^.w / w); // number of horizontal frames |
362 else |
358 ny:= round(Texture^.h / h); // number of vertical frames |
363 hw:= -w div 2; |
|
364 |
|
365 hh:= h div 2; |
|
366 |
|
367 nx:= Texture^.w div w; // number of horizontal frames |
|
368 ny:= Texture^.h div h; // number of vertical frames |
359 |
369 |
360 ft:= (Frame mod ny) * Texture^.ry / ny; |
370 ft:= (Frame mod ny) * Texture^.ry / ny; |
361 fb:= ((Frame mod ny) + 1) * Texture^.ry / ny; |
371 fb:= ((Frame mod ny) + 1) * Texture^.ry / ny; |
362 fl:= (Frame div ny) * Texture^.rx / nx; |
372 fl:= (Frame div ny) * Texture^.rx / nx; |
363 fr:= ((Frame div ny) + 1) * Texture^.rx / nx; |
373 fr:= ((Frame div ny) + 1) * Texture^.rx / nx; |
364 |
374 |
365 glBindTexture(GL_TEXTURE_2D, Texture^.id); |
375 glBindTexture(GL_TEXTURE_2D, Texture^.id); |
366 |
376 |
367 VertexBuffer[0].X:= -hw; |
377 VertexBuffer[0].X:= -hw; |
368 VertexBuffer[0].Y:= w / -2; |
378 VertexBuffer[0].Y:= -hh; |
369 VertexBuffer[1].X:= hw; |
379 VertexBuffer[1].X:= hw; |
370 VertexBuffer[1].Y:= w / -2; |
380 VertexBuffer[1].Y:= -hh; |
371 VertexBuffer[2].X:= hw; |
381 VertexBuffer[2].X:= hw; |
372 VertexBuffer[2].Y:= w / 2; |
382 VertexBuffer[2].Y:= hh; |
373 VertexBuffer[3].X:= -hw; |
383 VertexBuffer[3].X:= -hw; |
374 VertexBuffer[3].Y:= w / 2; |
384 VertexBuffer[3].Y:= hh; |
375 |
385 |
376 TextureBuffer[0].X:= fl; |
386 TextureBuffer[0].X:= fl; |
377 TextureBuffer[0].Y:= ft; |
387 TextureBuffer[0].Y:= ft; |
378 TextureBuffer[1].X:= fr; |
388 TextureBuffer[1].X:= fr; |
379 TextureBuffer[1].Y:= ft; |
389 TextureBuffer[1].Y:= ft; |