DEADSOFTWARE

render: use only r_render to access render
[d2df-sdl.git] / src / game / opengl / r_gfx.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
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.
6 *
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.
11 *
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/>.
14 *)
15 {$INCLUDE ../../shared/a_modes.inc}
16 unit r_gfx;
18 interface
20 {
21 const
22 R_GFX_FLAME_WIDTH = 32;
23 R_GFX_FLAME_HEIGHT = 32;
24 R_GFX_SMOKE_WIDTH = 32;
25 R_GFX_SMOKE_HEIGHT = 32;
26 }
28 procedure r_GFX_Load;
29 procedure r_GFX_Free;
30 procedure r_GFX_Draw;
31 procedure r_GFX_Update;
33 procedure r_GFX_OnceAnim (AnimType, X, Y: Integer);
35 implementation
37 uses
38 {$INCLUDE ../nogl/noGLuses.inc}
39 SysUtils, Classes, Math,
40 utils,
41 g_base, r_graphics, g_options, r_animations,
42 g_game, g_textures,
43 g_gfx
44 ;
46 type
47 TOnceAnim = record
48 AnimType: Byte;
49 x, y: Integer;
50 oldX, oldY: Integer;
51 Animation: TAnimationState;
52 end;
54 var
55 OnceAnims: array of TOnceAnim = nil;
56 gfxFrames: array [0..R_GFX_LAST] of DWORD;
58 procedure r_GFX_Load;
59 begin
60 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
61 g_Frames_Get(gfxFrames[R_GFX_TELEPORT], 'FRAMES_TELEPORT');
62 g_Frames_Get(gfxFrames[R_GFX_FLAME], 'FRAMES_FLAME');
63 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_ROCKET], 'FRAMES_EXPLODE_ROCKET');
64 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_BFG], 'FRAMES_EXPLODE_BFG');
65 g_Frames_Get(gfxFrames[R_GFX_BFG_HIT], 'FRAMES_BFGHIT');
66 g_Frames_Get(gfxFrames[R_GFX_FIRE], 'FRAMES_FIRE');
67 g_Frames_Get(gfxFrames[R_GFX_ITEM_RESPAWN], 'FRAMES_ITEM_RESPAWN');
68 g_Frames_Get(gfxFrames[R_GFX_SMOKE], 'FRAMES_SMOKE');
69 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_SKELFIRE], 'FRAMES_EXPLODE_SKELFIRE');
70 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_PLASMA], 'FRAMES_EXPLODE_PLASMA');
71 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_BSPFIRE], 'FRAMES_EXPLODE_BSPFIRE');
72 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_IMPFIRE], 'FRAMES_EXPLODE_IMPFIRE');
73 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_CACOFIRE], 'FRAMES_EXPLODE_CACOFIRE');
74 g_Frames_Get(gfxFrames[R_GFX_EXPLODE_BARONFIRE], 'FRAMES_EXPLODE_BARONFIRE');
75 end;
77 procedure r_GFX_Free;
78 var a: Integer;
79 begin
80 g_Frames_DeleteByName('FRAMES_TELEPORT');
81 if OnceAnims <> nil then
82 begin
83 for a := 0 to High(OnceAnims) do
84 OnceAnims[a].Animation.Free();
85 OnceAnims := nil;
86 end;
87 end;
89 function FindOnceAnim (): DWORD;
90 var i: Integer;
91 begin
92 if OnceAnims <> nil then
93 for i := 0 to High(OnceAnims) do
94 if OnceAnims[i].Animation = nil then
95 begin
96 Result := i;
97 Exit;
98 end;
99 if OnceAnims = nil then
100 begin
101 SetLength(OnceAnims, 16);
102 Result := 0;
103 end
104 else
105 begin
106 Result := High(OnceAnims) + 1;
107 SetLength(OnceAnims, Length(OnceAnims) + 16);
108 end;
109 end;
111 procedure r_GFX_OnceAnim (AnimType, x, y: Integer);
112 var find_id: DWORD; a: TAnimationState;
113 begin
114 if not gpart_dbg_enabled then exit;
115 find_id := FindOnceAnim();
116 case AnimType of
117 R_GFX_NONE: a := nil;
118 R_GFX_TELEPORT: a := TAnimationState.Create(false, 6, 10); // !!! speed can be 3
119 R_GFX_TELEPORT_FAST:
120 begin
121 AnimType := R_GFX_TELEPORT;
122 a := TAnimationState.Create(false, 3, 10);
123 end;
124 R_GFX_FLAME: a := TAnimationState.Create(false, 3, 11);
125 R_GFX_FLAME_RAND:
126 begin
127 AnimType := R_GFX_FLAME;
128 a := TAnimationState.Create(false, 2 + Random(2), 10);
129 end;
130 R_GFX_EXPLODE_ROCKET: a := TAnimationState.Create(false, 6, 6);
131 R_GFX_EXPLODE_BFG: a := TAnimationState.Create(false, 6, 6);
132 R_GFX_BFG_HIT: a := TAnimationState.Create(false, 4, 4);
133 R_GFX_FIRE: a := TAnimationState.Create(false, 4, 8); // !!! speed can be random
134 R_GFX_ITEM_RESPAWN: a := TAnimationState.Create(false, 4, 5);
135 R_GFX_SMOKE: a := TAnimationState.Create(false, 3, 10);
136 R_GFX_SMOKE_TRANS:
137 begin
138 AnimType := R_GFX_SMOKE;
139 a := TAnimationState.Create(false, 3, 10);
140 a.alpha := 150;
141 end;
142 R_GFX_EXPLODE_SKELFIRE: a := TAnimationState.Create(false, 8, 3);
143 R_GFX_EXPLODE_PLASMA: a := TAnimationState.Create(false, 3, 4);
144 R_GFX_EXPLODE_BSPFIRE: a := TAnimationState.Create(false, 3, 5);
145 R_GFX_EXPLODE_IMPFIRE: a := TAnimationState.Create(false, 6, 3);
146 R_GFX_EXPLODE_CACOFIRE: a := TAnimationState.Create(false, 6, 3);
147 R_GFX_EXPLODE_BARONFIRE: a := TAnimationState.Create(false, 6, 3);
148 else
149 a := nil;
150 assert(false)
151 end;
152 OnceAnims[find_id].AnimType := AnimType;
153 OnceAnims[find_id].Animation := a;
154 // OnceAnims[find_id].Animation.Blending := Anim.Blending;
155 // OnceAnims[find_id].Animation.alpha := Anim.alpha;
156 OnceAnims[find_id].x := x;
157 OnceAnims[find_id].y := y;
158 end;
160 procedure r_GFX_Update;
161 var a: Integer;
162 begin
163 if OnceAnims <> nil then
164 begin
165 for a := 0 to High(OnceAnims) do
166 begin
167 if OnceAnims[a].Animation <> nil then
168 begin
169 OnceAnims[a].oldx := OnceAnims[a].x;
170 OnceAnims[a].oldy := OnceAnims[a].y;
171 case OnceAnims[a].AnimType of
172 R_GFX_FLAME, R_GFX_SMOKE: (*ONCEANIM_SMOKE:*)
173 begin
174 if Random(3) = 0 then
175 OnceAnims[a].x := OnceAnims[a].x-1+Random(3);
176 if Random(2) = 0 then
177 OnceAnims[a].y := OnceAnims[a].y-Random(2);
178 end;
179 end;
180 if OnceAnims[a].Animation.Played then
181 begin
182 OnceAnims[a].Animation.Free();
183 OnceAnims[a].Animation := nil;
184 end
185 else
186 OnceAnims[a].Animation.Update();
187 end;
188 end;
189 end;
190 end;
192 procedure r_GFX_Draw;
193 var
194 a, len, fx, fy: Integer;
195 begin
196 if not gpart_dbg_enabled then exit;
198 if (Particles <> nil) then
199 begin
200 glDisable(GL_TEXTURE_2D);
201 if (g_dbg_scale < 0.6) then glPointSize(1)
202 else if (g_dbg_scale > 1.3) then glPointSize(g_dbg_scale+1)
203 else glPointSize(2);
204 glDisable(GL_POINT_SMOOTH);
206 glEnable(GL_BLEND);
207 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
209 glBegin(GL_POINTS);
211 len := High(Particles);
212 for a := 0 to len do
213 begin
214 with Particles[a] do
215 begin
216 if not alive then continue;
217 if (x >= sX) and (y >= sY) and (x <= sX+sWidth) and (sY <= sY+sHeight) then
218 begin
219 fx := nlerp(oldx, x, gLerpFactor);
220 fy := nlerp(oldy, y, gLerpFactor);
221 glColor4ub(red, green, blue, alpha);
222 glVertex2f(fx+0.37, fy+0.37);
223 end;
224 end;
225 end;
227 glEnd();
229 glDisable(GL_BLEND);
230 end;
232 if (OnceAnims <> nil) then
233 begin
234 len := High(OnceAnims);
235 for a := 0 to len do
236 begin
237 if (OnceAnims[a].Animation <> nil) then
238 begin
239 with OnceAnims[a] do
240 begin
241 fx := nlerp(oldx, x, gLerpFactor);
242 fy := nlerp(oldy, y, gLerpFactor);
243 r_AnimationState_Draw(gfxFrames[AnimType], Animation, x, y, TMirrorType.None);
244 end;
245 end;
246 end;
247 end;
248 end;
250 end.