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);
28 procedure r_Draw_MultiTextureRepeat (m
: TGLMultiTexture
; const anim
: TAnimState
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean);
29 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);
31 procedure r_Draw_Filter (l
, t
, r
, b
: Integer; rr
, gg
, bb
, aa
: Byte);
41 SysUtils
, Classes
, Math
,
43 g_game
// gScreenWidth, gScreenHeight
52 procedure SetupMatrix
;
54 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
55 glViewport(0, 0, gScreenWidth
, gScreenHeight
);
56 glMatrixMode(GL_PROJECTION
);
58 glOrtho(0, gScreenWidth
, gScreenHeight
, 0, 0, 1);
59 glMatrixMode(GL_MODELVIEW
);
63 procedure DrawQuad (x
, y
, w
, h
: Integer);
69 glVertex2i(x
+ w
, y
+ h
);
73 procedure DrawTile (tile
: TGLAtlasNode
; x
, y
, w
, h
: Integer; flip
: Boolean; rr
, gg
, bb
, aa
: Byte; blend
: Boolean);
74 var nw
, nh
, ax
, bx
, ay
, by
: GLfloat
; l
, t
, r
, b
: Integer;
78 glColor4ub(rr
, gg
, bb
, aa
);
79 if blend
then glBlendFunc(GL_SRC_ALPHA
, GL_ONE
) else glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
80 glDisable(GL_TEXTURE_2D
);
88 ax
:= IfThen(flip
, tile
.l
, tile
.r
+ 1) / nw
;
89 bx
:= IfThen(flip
, tile
.r
+ 1, tile
.l
) / nh
;
91 by
:= (tile
.b
+ 1) / nh
;
92 l
:= x
; t
:= y
; r
:= x
+ w
; b
:= y
+ h
;
93 glBindTexture(GL_TEXTURE_2D
, tile
.id
);
94 glColor4ub(rr
, gg
, bb
, aa
);
95 if blend
then glBlendFunc(GL_SRC_ALPHA
, GL_ONE
) else glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
96 glEnable(GL_TEXTURE_2D
);
99 glTexCoord2f(ax
, ay
); glVertex2i(r
, t
);
100 glTexCoord2f(bx
, ay
); glVertex2i(l
, t
);
101 glTexCoord2f(bx
, by
); glVertex2i(l
, b
);
102 glTexCoord2f(ax
, by
); glVertex2i(r
, b
);
104 glDisable(GL_TEXTURE_2D
);
105 glBindTexture(GL_TEXTURE_2D
, 0);
109 procedure r_Draw_Texture (img
: TGLTexture
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean);
110 var i
, j
, offx
, offy
: Integer; n
: TGLAtlasNode
;
115 DrawTile(nil, x
, y
, w
, h
, flip
, NTR
, NTB
, NTG
, NTA
, blend
)
119 glScalef(w
/ img
.width
, h
/ img
.height
, 1);
122 for j
:= 0 to img
.lines
- 1 do
124 for i
:= 0 to img
.cols
- 1 do
126 n
:= img
.GetTile(i
, j
);
128 DrawTile(n
, x
+ offx
, y
+ offy
, n
.width
, n
.height
, flip
, r
, g
, b
, a
, blend
);
129 offx
:= offx
+ n
.width
;
132 offy
:= offy
+ n
.height
;
138 procedure r_Draw_TextureRepeat (img
: TGLTexture
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean);
144 r_Draw_Texture(nil, x
, y
, w
, h
, flip
, NTR
, NTG
, NTB
, NTB
, blend
)
146 for j
:= 0 to h
div img
.height
- 1 do
147 for i
:= 0 to w
div img
.width
- 1 do
148 r_Draw_Texture(img
, x
+ i
* img
.width
, y
+ j
* img
.height
, img
.width
, img
.height
, flip
, r
, g
, b
, a
, blend
);
151 procedure r_Draw_MultiTextureRepeat (m
: TGLMultiTexture
; const anim
: TAnimState
; x
, y
, w
, h
: Integer; flip
: Boolean; r
, g
, b
, a
: Byte; blend
: Boolean);
152 var img
: TGLTexture
; cur
, total
, i
: Integer;
154 ASSERT(anim
.IsValid());
156 r_Draw_TextureRepeat(nil, x
, y
, w
, h
, flip
, NTR
, NTG
, NTB
, NTB
, blend
)
161 total
:= m
.count
* 2 - 1;
162 cur
:= anim
.CurrentFrame
mod total
;
163 if cur
< m
.count
then i
:= cur
else i
:= total
- cur
- 1;
166 i
:= anim
.CurrentFrame
mod m
.count
;
167 img
:= m
.GetTexture(i
);
168 r_Draw_TextureRepeat(img
, x
, y
, w
, h
, flip
, r
, g
, b
, a
, blend
);
172 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);
180 glTranslatef(x
+ rx
, y
+ ry
, 0);
181 glRotatef(angle
, 0, 0, 1);
182 glTranslatef(-(x
+ rx
), -(y
+ ry
), 0);
183 r_Draw_MultiTextureRepeat(m
, anim
, x
, y
, w
, h
, flip
, r
, g
, b
, a
, blend
);
187 r_Draw_MultiTextureRepeat(m
, anim
, x
, y
, w
, h
, flip
, r
, g
, b
, a
, blend
);
190 procedure r_Draw_Filter (l
, t
, r
, b
: Integer; rr
, gg
, bb
, aa
: Byte);
195 glBlendFunc(GL_ZERO
, GL_SRC_COLOR
);
196 glDisable(GL_TEXTURE_2D
);
197 glColor4ub(rr
, gg
, bb
, aa
);