24 |
24 |
25 uses SDLh, uTypes, GLunit, uConsts; |
25 uses SDLh, uTypes, GLunit, uConsts; |
26 |
26 |
27 procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
27 procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
28 procedure DrawSprite (Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
28 procedure DrawSprite (Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
29 procedure DrawSpriteFromRect (Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
29 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); |
30 procedure DrawSpriteClipped (Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
31 procedure DrawSpriteRotated (Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
31 procedure DrawSpriteRotated (Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
32 procedure DrawSpriteRotatedF (Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
32 procedure DrawSpriteRotatedF (Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
33 |
33 |
34 procedure DrawTexture (X, Y: LongInt; Texture: PTexture); inline; |
34 procedure DrawTexture (X, Y: LongInt; Texture: PTexture); inline; |
35 procedure DrawTexture (X, Y: LongInt; Texture: PTexture; Scale: GLfloat); |
35 procedure DrawTexture (X, Y: LongInt; Texture: PTexture; Scale: GLfloat); |
36 procedure DrawTextureFromRect (X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
36 procedure DrawTextureFromRect (X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline; |
37 procedure DrawTextureFromRect (X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
37 procedure DrawTextureFromRect (X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline; |
|
38 procedure DrawTextureFromRectDir(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture; Dir: LongInt); |
38 procedure DrawTextureCentered (X, Top: LongInt; Source: PTexture); |
39 procedure DrawTextureCentered (X, Top: LongInt; Source: PTexture); |
39 procedure DrawTextureF (Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt); |
40 procedure DrawTextureF (Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt); |
40 procedure DrawTextureRotated (Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
41 procedure DrawTextureRotated (Texture: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
41 procedure DrawTextureRotatedF (Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
42 procedure DrawTextureRotatedF (Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
42 |
43 |
61 MOVE_ANIM_TIME = 500; |
62 MOVE_ANIM_TIME = 500; |
62 {$ENDIF} |
63 {$ENDIF} |
63 |
64 |
64 var LastTint: LongWord = 0; |
65 var LastTint: LongWord = 0; |
65 |
66 |
66 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
67 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); inline; |
67 begin |
68 begin |
68 r.y:= r.y + Height * Position; |
69 r.y:= r.y + Height * Position; |
69 r.h:= Height; |
70 r.h:= Height; |
70 DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
71 DrawTextureFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
71 end; |
72 end; |
72 |
73 |
73 procedure DrawTextureFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
74 procedure DrawTextureFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline; |
74 begin |
75 begin |
75 DrawTextureFromRect(X, Y, r^.w, r^.h, r, SourceTexture) |
76 DrawTextureFromRectDir(X, Y, r^.w, r^.h, r, SourceTexture, 1) |
76 end; |
77 end; |
77 |
78 procedure DrawTextureFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); inline; |
78 procedure DrawTextureFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
79 begin |
|
80 DrawTextureFromRectDir(X, Y, W, H, r, SourceTexture, 1) |
|
81 end; |
|
82 |
|
83 procedure DrawTextureFromRectDir(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture; Dir: LongInt); |
79 var rr: TSDL_Rect; |
84 var rr: TSDL_Rect; |
80 _l, _r, _t, _b: real; |
85 _l, _r, _t, _b: real; |
81 VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
86 VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
82 begin |
87 begin |
83 if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then |
88 if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then |
99 _t:= r^.y / SourceTexture^.h * SourceTexture^.ry; |
104 _t:= r^.y / SourceTexture^.h * SourceTexture^.ry; |
100 _b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry; |
105 _b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry; |
101 |
106 |
102 glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
107 glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
103 |
108 |
104 VertexBuffer[0].X:= X; |
109 if Dir < 0 then |
105 VertexBuffer[0].Y:= Y; |
110 begin |
106 VertexBuffer[1].X:= rr.w + X; |
111 VertexBuffer[0].X:= X + rr.w/2; |
107 VertexBuffer[1].Y:= Y; |
112 VertexBuffer[0].Y:= Y; |
108 VertexBuffer[2].X:= rr.w + X; |
113 VertexBuffer[1].X:= X - rr.w/2; |
109 VertexBuffer[2].Y:= rr.h + Y; |
114 VertexBuffer[1].Y:= Y; |
110 VertexBuffer[3].X:= X; |
115 VertexBuffer[2].X:= X - rr.w/2; |
111 VertexBuffer[3].Y:= rr.h + Y; |
116 VertexBuffer[2].Y:= rr.h + Y; |
|
117 VertexBuffer[3].X:= X + rr.w/2; |
|
118 VertexBuffer[3].Y:= rr.h + Y; |
|
119 end |
|
120 else |
|
121 begin |
|
122 VertexBuffer[0].X:= X; |
|
123 VertexBuffer[0].Y:= Y; |
|
124 VertexBuffer[1].X:= rr.w + X; |
|
125 VertexBuffer[1].Y:= Y; |
|
126 VertexBuffer[2].X:= rr.w + X; |
|
127 VertexBuffer[2].Y:= rr.h + Y; |
|
128 VertexBuffer[3].X:= X; |
|
129 VertexBuffer[3].Y:= rr.h + Y; |
|
130 end; |
112 |
131 |
113 TextureBuffer[0].X:= _l; |
132 TextureBuffer[0].X:= _l; |
114 TextureBuffer[0].Y:= _t; |
133 TextureBuffer[0].Y:= _t; |
115 TextureBuffer[1].X:= _r; |
134 TextureBuffer[1].X:= _r; |
116 TextureBuffer[1].Y:= _t; |
135 TextureBuffer[1].Y:= _t; |