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);
42 SysUtils
, Classes
, Math
,
44 g_game
// gScreenWidth, gScreenHeight
53 procedure SetupMatrix
;
55 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
56 glViewport(0, 0, gScreenWidth
, gScreenHeight
);
57 glMatrixMode(GL_PROJECTION
);
59 glOrtho(0, gScreenWidth
, gScreenHeight
, 0, 0, 1);
60 glMatrixMode(GL_MODELVIEW
);
64 procedure DrawQuad (x
, y
, w
, h
: Integer);
70 glVertex2i(x
+ w
, y
+ h
);
74 procedure DrawTile (tile
: TGLAtlasNode
; x
, y
, w
, h
: Integer; flip
: Boolean; rr
, gg
, bb
, aa
: Byte; blend
: Boolean);
75 var nw
, nh
, ax
, bx
, ay
, by
: GLfloat
; l
, t
, r
, b
: Integer;
79 glColor4ub(rr
, gg
, bb
, aa
);
80 if blend
then glBlendFunc(GL_SRC_ALPHA
, GL_ONE
) else glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
81 glDisable(GL_TEXTURE_2D
);
89 ax
:= IfThen(flip
, tile
.l
, tile
.r
+ 1) / nw
;
90 bx
:= IfThen(flip
, tile
.r
+ 1, tile
.l
) / nh
;
92 by
:= (tile
.b
+ 1) / nh
;
93 l
:= x
; t
:= y
; r
:= x
+ w
; b
:= y
+ h
;
94 glBindTexture(GL_TEXTURE_2D
, tile
.id
);
95 glColor4ub(rr
, gg
, bb
, aa
);
96 if blend
then glBlendFunc(GL_SRC_ALPHA
, GL_ONE
) else glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
97 glEnable(GL_TEXTURE_2D
);
100 glTexCoord2f(ax
, ay
); glVertex2i(r
, t
);
101 glTexCoord2f(bx
, ay
); glVertex2i(l
, t
);
102 glTexCoord2f(bx
, by
); glVertex2i(l
, b
);
103 glTexCoord2f(ax
, by
); glVertex2i(r
, b
);
105 glDisable(GL_TEXTURE_2D
);
106 glBindTexture(GL_TEXTURE_2D
, 0);
110 procedure r_Draw_Texture (img
: TGLTexture
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean);
111 var i
, j
, offx
, offy
: Integer; n
: TGLAtlasNode
;
116 DrawTile(nil, x
, y
, w
, h
, flip
, NTR
, NTB
, NTG
, NTA
, blend
)
120 glScalef(w
/ img
.width
, h
/ img
.height
, 1);
123 for j
:= 0 to img
.lines
- 1 do
125 for i
:= 0 to img
.cols
- 1 do
127 n
:= img
.GetTile(i
, j
);
129 DrawTile(n
, x
+ offx
, y
+ offy
, n
.width
, n
.height
, flip
, r
, g
, b
, a
, blend
);
130 offx
:= offx
+ n
.width
;
133 offy
:= offy
+ n
.height
;
139 procedure r_Draw_TextureRepeat (img
: TGLTexture
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean);
145 r_Draw_Texture(nil, x
, y
, w
, h
, flip
, NTR
, NTG
, NTB
, NTB
, blend
)
147 for j
:= 0 to h
div img
.height
- 1 do
148 for i
:= 0 to w
div img
.width
- 1 do
149 r_Draw_Texture(img
, x
+ i
* img
.width
, y
+ j
* img
.height
, img
.width
, img
.height
, flip
, r
, g
, b
, a
, blend
);
152 procedure r_Draw_TextureRepeatRotate (img
: TGLTexture
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean; rx
, ry
, angle
: Integer);
159 glTranslatef(x
+ rx
, y
+ ry
, 0);
160 glRotatef(angle
, 0, 0, 1);
161 glTranslatef(-(x
+ rx
), -(y
+ ry
), 0);
162 r_Draw_TextureRepeat(img
, x
, y
, w
, h
, flip
, r
, g
, b
, a
, blend
);
166 r_Draw_TextureRepeat(img
, x
, y
, w
, h
, flip
, r
, g
, b
, a
, blend
);
169 procedure r_Draw_MultiTextureRepeat (m
: TGLMultiTexture
; const anim
: TAnimState
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean);
170 var img
: TGLTexture
; cur
, total
, i
: Integer;
172 ASSERT(anim
.IsValid());
174 r_Draw_TextureRepeat(nil, x
, y
, w
, h
, flip
, NTR
, NTG
, NTB
, NTB
, blend
)
179 total
:= m
.count
* 2 - 1;
180 cur
:= anim
.CurrentFrame
mod total
;
181 if cur
< m
.count
then i
:= cur
else i
:= total
- cur
- 1;
184 i
:= anim
.CurrentFrame
mod m
.count
;
185 img
:= m
.GetTexture(i
);
186 r_Draw_TextureRepeat(img
, x
, y
, w
, h
, flip
, r
, g
, b
, a
, blend
);
190 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);
197 glTranslatef(x
+ rx
, y
+ ry
, 0);
198 glRotatef(angle
, 0, 0, 1);
199 glTranslatef(-(x
+ rx
), -(y
+ ry
), 0);
200 r_Draw_MultiTextureRepeat(m
, anim
, x
, y
, w
, h
, flip
, r
, g
, b
, a
, blend
);
204 r_Draw_MultiTextureRepeat(m
, anim
, x
, y
, w
, h
, flip
, r
, g
, b
, a
, blend
);
207 procedure r_Draw_Filter (l
, t
, r
, b
: Integer; rr
, gg
, bb
, aa
: Byte);
212 glBlendFunc(GL_ZERO
, GL_SRC_COLOR
);
213 glDisable(GL_TEXTURE_2D
);
214 glColor4ub(rr
, gg
, bb
, aa
);