1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../../../shared/a_modes.inc}
25 procedure r_Draw_Texture (img
: TGLTexture
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean);
26 procedure r_Draw_TextureRepeat (img
: TGLTexture
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean);
27 procedure r_Draw_TextureRepeatRotate (img
: TGLTexture
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean; rx
, ry
, angle
: Integer);
29 procedure r_Draw_MultiTextureRepeat (m
: TGLMultiTexture
; const anim
: TAnimState
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean);
30 procedure r_Draw_MultiTextureRepeatRotate (m
: TGLMultiTexture
; const anim
: TAnimState
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean; rx
, ry
, angle
: Integer);
32 procedure r_Draw_Filter (l
, t
, r
, b
: Integer; rr
, gg
, bb
, aa
: Byte);
33 procedure r_Draw_FillRect (l
, t
, r
, b
: Integer; rr
, gg
, bb
, aa
: Byte);
34 procedure r_Draw_InvertRect (l
, t
, r
, b
: Integer; rr
, gg
, bb
, aa
: Byte);
44 SysUtils
, Classes
, Math
,
46 g_game
// gScreenWidth, gScreenHeight
55 procedure SetupMatrix
;
57 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
58 glViewport(0, 0, gScreenWidth
, gScreenHeight
);
59 glMatrixMode(GL_PROJECTION
);
61 glOrtho(0, gScreenWidth
, gScreenHeight
, 0, 0, 1);
62 glMatrixMode(GL_MODELVIEW
);
66 procedure DrawQuad (x
, y
, w
, h
: Integer);
72 glVertex2i(x
+ w
, y
+ h
);
76 procedure DrawTile (tile
: TGLAtlasNode
; x
, y
, w
, h
: Integer; flip
: Boolean; rr
, gg
, bb
, aa
: Byte; blend
: Boolean);
77 var nw
, nh
, ax
, bx
, ay
, by
: GLfloat
; l
, t
, r
, b
: Integer;
81 glColor4ub(rr
, gg
, bb
, aa
);
82 if blend
then glBlendFunc(GL_SRC_ALPHA
, GL_ONE
) else glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
83 glDisable(GL_TEXTURE_2D
);
91 ax
:= IfThen(flip
, tile
.l
, tile
.r
+ 1) / nw
;
92 bx
:= IfThen(flip
, tile
.r
+ 1, tile
.l
) / nh
;
94 by
:= (tile
.b
+ 1) / nh
;
95 l
:= x
; t
:= y
; r
:= x
+ w
; b
:= y
+ h
;
96 glBindTexture(GL_TEXTURE_2D
, tile
.id
);
97 glColor4ub(rr
, gg
, bb
, aa
);
98 if blend
then glBlendFunc(GL_SRC_ALPHA
, GL_ONE
) else glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
99 glEnable(GL_TEXTURE_2D
);
102 glTexCoord2f(ax
, ay
); glVertex2i(r
, t
);
103 glTexCoord2f(bx
, ay
); glVertex2i(l
, t
);
104 glTexCoord2f(bx
, by
); glVertex2i(l
, b
);
105 glTexCoord2f(ax
, by
); glVertex2i(r
, b
);
107 glDisable(GL_TEXTURE_2D
);
108 glBindTexture(GL_TEXTURE_2D
, 0);
112 procedure r_Draw_Texture (img
: TGLTexture
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean);
113 var i
, j
, offx
, offy
: Integer; n
: TGLAtlasNode
;
118 DrawTile(nil, x
, y
, w
, h
, flip
, NTR
, NTB
, NTG
, NTA
, blend
)
123 for j
:= 0 to img
.lines
- 1 do
125 for i
:= 0 to img
.cols
- 1 do
127 n
:= img
.GetTile(i
, j
);
130 glTranslatef(x
+ offx
, y
+ offy
, 0);
131 glScalef(w
/ img
.width
, h
/ img
.height
, 1);
132 DrawTile(n
, 0, 0, n
.width
, n
.height
, flip
, r
, g
, b
, a
, blend
);
134 offx
:= offx
+ n
.width
;
137 offy
:= offy
+ n
.height
;
142 procedure r_Draw_TextureRepeat (img
: TGLTexture
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean);
148 r_Draw_Texture(nil, x
, y
, w
, h
, flip
, NTR
, NTG
, NTB
, NTB
, blend
)
150 for j
:= 0 to h
div img
.height
- 1 do
151 for i
:= 0 to w
div img
.width
- 1 do
152 r_Draw_Texture(img
, x
+ i
* img
.width
, y
+ j
* img
.height
, img
.width
, img
.height
, flip
, r
, g
, b
, a
, blend
);
155 procedure r_Draw_TextureRepeatRotate (img
: TGLTexture
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean; rx
, ry
, angle
: Integer);
162 glTranslatef(x
+ rx
, y
+ ry
, 0);
163 glRotatef(angle
, 0, 0, 1);
164 glTranslatef(-(x
+ rx
), -(y
+ ry
), 0);
165 r_Draw_TextureRepeat(img
, x
, y
, w
, h
, flip
, r
, g
, b
, a
, blend
);
169 r_Draw_TextureRepeat(img
, x
, y
, w
, h
, flip
, r
, g
, b
, a
, blend
);
172 procedure r_Draw_MultiTextureRepeat (m
: TGLMultiTexture
; const anim
: TAnimState
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean);
173 var img
: TGLTexture
; cur
, total
, i
: Integer;
175 ASSERT(anim
.IsValid());
177 r_Draw_TextureRepeat(nil, x
, y
, w
, h
, flip
, NTR
, NTG
, NTB
, NTB
, blend
)
182 total
:= m
.count
* 2 - 1;
183 cur
:= anim
.CurrentFrame
mod total
;
184 if cur
< m
.count
then i
:= cur
else i
:= total
- cur
- 1;
187 i
:= anim
.CurrentFrame
mod m
.count
;
188 img
:= m
.GetTexture(i
);
189 r_Draw_TextureRepeat(img
, x
, y
, w
, h
, flip
, r
, g
, b
, a
, blend
);
193 procedure r_Draw_MultiTextureRepeatRotate (m
: TGLMultiTexture
; const anim
: TAnimState
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean; rx
, ry
, angle
: Integer);
200 glTranslatef(x
+ rx
, y
+ ry
, 0);
201 glRotatef(angle
, 0, 0, 1);
202 glTranslatef(-(x
+ rx
), -(y
+ ry
), 0);
203 r_Draw_MultiTextureRepeat(m
, anim
, x
, y
, w
, h
, flip
, r
, g
, b
, a
, blend
);
207 r_Draw_MultiTextureRepeat(m
, anim
, x
, y
, w
, h
, flip
, r
, g
, b
, a
, blend
);
210 procedure r_Draw_Filter (l
, t
, r
, b
: Integer; rr
, gg
, bb
, aa
: Byte);
215 glBlendFunc(GL_ZERO
, GL_SRC_COLOR
);
216 glDisable(GL_TEXTURE_2D
);
217 glColor4ub(rr
, gg
, bb
, aa
);
226 procedure r_Draw_FillRect (l
, t
, r
, b
: Integer; rr
, gg
, bb
, aa
: Byte);
231 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
232 glDisable(GL_TEXTURE_2D
);
233 glColor4ub(rr
, gg
, bb
, aa
);
242 procedure r_Draw_InvertRect (l
, t
, r
, b
: Integer; rr
, gg
, bb
, aa
: Byte);
247 glBlendFunc(GL_ONE_MINUS_DST_COLOR
, GL_ZERO
);
248 glDisable(GL_TEXTURE_2D
);
249 glColor4ub(rr
, gg
, bb
, aa
);