491 var rr: TSDL_Rect; |
491 var rr: TSDL_Rect; |
492 _l, _r, _t, _b: real; |
492 _l, _r, _t, _b: real; |
493 VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
493 VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
494 begin |
494 begin |
495 if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit; |
495 if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit; |
|
496 |
|
497 // don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
498 if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then |
|
499 exit; |
|
500 if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) > cScreenHeight / cScaleFactor) then |
|
501 exit; |
|
502 |
496 rr.x:= X; |
503 rr.x:= X; |
497 rr.y:= Y; |
504 rr.y:= Y; |
498 rr.w:= W; |
505 rr.w:= W; |
499 rr.h:= H; |
506 rr.h:= H; |
500 |
507 |
529 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
536 glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
530 end; |
537 end; |
531 |
538 |
532 procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat); |
539 procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat); |
533 begin |
540 begin |
|
541 |
534 glPushMatrix; |
542 glPushMatrix; |
535 glTranslatef(X, Y, 0); |
543 glTranslatef(X, Y, 0); |
536 glScalef(Scale, Scale, 1); |
544 glScalef(Scale, Scale, 1); |
537 |
545 |
538 glBindTexture(GL_TEXTURE_2D, Texture^.id); |
546 glBindTexture(GL_TEXTURE_2D, Texture^.id); |
552 procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
560 procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
553 var ft, fb, fl, fr: GLfloat; |
561 var ft, fb, fl, fr: GLfloat; |
554 hw, nx, ny: LongInt; |
562 hw, nx, ny: LongInt; |
555 VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
563 VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
556 begin |
564 begin |
|
565 // don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
566 if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) > cScreenWidth / cScaleFactor) then |
|
567 exit; |
|
568 if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) > cScreenHeight / cScaleFactor) then |
|
569 exit; |
|
570 |
557 glPushMatrix; |
571 glPushMatrix; |
558 glTranslatef(X, Y, 0); |
572 glTranslatef(X, Y, 0); |
559 |
573 |
560 if Dir < 0 then |
574 if Dir < 0 then |
561 glRotatef(Angle, 0, 0, -1) |
575 glRotatef(Angle, 0, 0, -1) |
633 end; |
647 end; |
634 |
648 |
635 procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
649 procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
636 var VertexBuffer: array [0..3] of TVertex2f; |
650 var VertexBuffer: array [0..3] of TVertex2f; |
637 begin |
651 begin |
|
652 // don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
653 if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then |
|
654 exit; |
|
655 if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then |
|
656 exit; |
|
657 |
638 glPushMatrix; |
658 glPushMatrix; |
639 glTranslatef(X, Y, 0); |
659 glTranslatef(X, Y, 0); |
640 |
660 |
641 if Dir < 0 then |
661 if Dir < 0 then |
642 begin |
662 begin |
726 (x: 16; y: 16), |
746 (x: 16; y: 16), |
727 (x: -16; y: 16)); |
747 (x: -16; y: 16)); |
728 var l, r, t, b: real; |
748 var l, r, t, b: real; |
729 TextureBuffer: array [0..3] of TVertex2f; |
749 TextureBuffer: array [0..3] of TVertex2f; |
730 begin |
750 begin |
|
751 // don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
752 if (abs(X) > 32) and ((abs(X) - 16)> cScreenWidth / cScaleFactor) then |
|
753 exit; |
|
754 if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) > cScreenHeight / cScaleFactor) then |
|
755 exit; |
731 |
756 |
732 t:= Pos * 32 / HHTexture^.h; |
757 t:= Pos * 32 / HHTexture^.h; |
733 b:= (Pos + 1) * 32 / HHTexture^.h; |
758 b:= (Pos + 1) * 32 / HHTexture^.h; |
734 |
759 |
735 if Dir = -1 then |
760 if Dir = -1 then |
766 end; |
791 end; |
767 |
792 |
768 procedure DrawFillRect(r: TSDL_Rect); |
793 procedure DrawFillRect(r: TSDL_Rect); |
769 var VertexBuffer: array [0..3] of TVertex2f; |
794 var VertexBuffer: array [0..3] of TVertex2f; |
770 begin |
795 begin |
|
796 // don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
797 if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) > cScreenWidth / cScaleFactor) then |
|
798 exit; |
|
799 if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) > cScreenHeight / cScaleFactor) then |
|
800 exit; |
|
801 |
771 glDisable(GL_TEXTURE_2D); |
802 glDisable(GL_TEXTURE_2D); |
772 |
803 |
773 Tint($00, $00, $00, $80); |
804 Tint($00, $00, $00, $80); |
774 |
805 |
775 VertexBuffer[0].X:= r.x; |
806 VertexBuffer[0].X:= r.x; |