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);
26 procedure r_Draw_TextureRepeat (img
: TGLTexture
; x
, y
, w
, h
: Integer; flip
: Boolean);
28 procedure r_Draw_MultiTextureRepeat (m
: TGLMultiTexture
; const a
: TAnimState
; x
, y
, w
, h
: Integer; flip
: Boolean);
30 procedure r_Draw_Filter (l
, t
, r
, b
: Integer; rr
, gg
, bb
, aa
: Byte);
40 SysUtils
, Classes
, Math
,
42 g_game
// gScreenWidth, gScreenHeight
45 procedure SetupMatrix
;
47 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
48 glViewport(0, 0, gScreenWidth
, gScreenHeight
);
49 glMatrixMode(GL_PROJECTION
);
51 glOrtho(0, gScreenWidth
, gScreenHeight
, 0, 0, 1);
52 glMatrixMode(GL_MODELVIEW
);
56 procedure DrawQuad (x
, y
, w
, h
: Integer);
62 glVertex2i(x
+ w
, y
+ h
);
66 procedure DrawTile (tile
: TGLAtlasNode
; x
, y
, w
, h
: Integer; flip
: Boolean);
67 var nw
, nh
, ax
, bx
, ay
, by
: GLfloat
; l
, t
, r
, b
: Integer;
71 glColor3ub(255, 0, 0);
73 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
74 glDisable(GL_TEXTURE_2D
);
81 ax
:= IfThen(flip
, tile
.l
, tile
.r
+ 1) / nw
;
82 bx
:= IfThen(flip
, tile
.r
+ 1, tile
.l
) / nh
;
84 by
:= (tile
.b
+ 1) / nh
;
85 l
:= x
; t
:= y
; r
:= x
+ w
; b
:= y
+ h
;
86 glColor3ub(255, 255, 255);
87 glBindTexture(GL_TEXTURE_2D
, tile
.id
);
88 glEnable(GL_TEXTURE_2D
);
90 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
92 glTexCoord2f(ax
, ay
); glVertex2i(r
, t
);
93 glTexCoord2f(bx
, ay
); glVertex2i(l
, t
);
94 glTexCoord2f(bx
, by
); glVertex2i(l
, b
);
95 glTexCoord2f(ax
, by
); glVertex2i(r
, b
);
97 glDisable(GL_TEXTURE_2D
);
98 glBindTexture(GL_TEXTURE_2D
, 0);
103 procedure r_Draw_Texture (img: TGLTexture; x, y, w, h: Integer; flip: Boolean);
104 var i, j, offx, offy, nw, nh: Integer; n: TGLAtlasNode;
109 DrawTile(nil, x, y, w, h, flip)
114 nw := w div img.cols;
115 nh := h div img.lines;
116 for j := 0 to img.lines - 1 do
118 for i := 0 to img.cols - 1 do
120 n := img.GetTile(i, j);
122 DrawTile(n, x + offx, y + offy, nw, nh, flip);
132 procedure r_Draw_Texture (img
: TGLTexture
; x
, y
, w
, h
: Integer; flip
: Boolean);
133 var i
, j
, offx
, offy
: Integer; n
: TGLAtlasNode
;
138 DrawTile(nil, x
, y
, w
, h
, flip
)
142 glScalef(w
/ img
.width
, h
/ img
.height
, 1);
145 for j
:= 0 to img
.lines
- 1 do
147 for i
:= 0 to img
.cols
- 1 do
149 n
:= img
.GetTile(i
, j
);
151 DrawTile(n
, x
+ offx
, y
+ offy
, n
.width
, n
.height
, flip
);
152 offx
:= offx
+ n
.width
;
155 offy
:= offy
+ n
.height
;
161 procedure r_Draw_TextureRepeat (img
: TGLTexture
; x
, y
, w
, h
: Integer; flip
: Boolean);
167 r_Draw_Texture(nil, x
, y
, w
, h
, flip
)
169 for j
:= 0 to h
div img
.height
- 1 do
170 for i
:= 0 to w
div img
.width
- 1 do
171 r_Draw_Texture(img
, x
+ i
* img
.width
, y
+ j
* img
.height
, img
.width
, img
.height
, flip
);
174 procedure r_Draw_MultiTextureRepeat (m
: TGLMultiTexture
; const a
: TAnimState
; x
, y
, w
, h
: Integer; flip
: Boolean);
175 var img
: TGLTexture
; cur
, total
, i
: Integer;
179 r_Draw_TextureRepeat(nil, x
, y
, w
, h
, flip
)
184 total
:= m
.count
* 2 - 1;
185 cur
:= a
.CurrentFrame
mod total
;
186 if cur
< m
.count
then i
:= cur
else i
:= total
- cur
- 1;
189 i
:= a
.CurrentFrame
mod m
.count
;
190 img
:= m
.GetTexture(i
);
191 r_Draw_TextureRepeat(img
, x
, y
, w
, h
, flip
)
195 procedure r_Draw_Filter (l
, t
, r
, b
: Integer; rr
, gg
, bb
, aa
: Byte);
200 glBlendFunc(GL_ZERO
, GL_SRC_COLOR
);
201 glDisable(GL_TEXTURE_2D
);
202 glColor4ub(rr
, gg
, bb
, aa
);