1 //**************************************************************************
2 //**
3 //** ## ## ## ## ## #### #### ### ###
4 //** ## ## ## ## ## ## ## ## ## ## #### ####
5 //** ## ## ## ## ## ## ## ## ## ## ## ## ## ##
6 //** ## ## ######## ## ## ## ## ## ## ## ### ##
7 //** ### ## ## ### ## ## ## ## ## ##
8 //** # ## ## # #### #### ## ##
9 //**
10 //** $Id: d3d_draw.cpp 3402 2008-03-29 18:48:10Z dj_jl $
11 //**
12 //** Copyright (C) 1999-2006 Jānis Legzdiņš
13 //**
14 //** This program is free software; you can redistribute it and/or
15 //** modify it under the terms of the GNU General Public License
16 //** as published by the Free Software Foundation; either version 2
17 //** of the License, or (at your option) any later version.
18 //**
19 //** This program is distributed in the hope that it will be useful,
20 //** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 //** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 //** GNU General Public License for more details.
23 //**
24 //**************************************************************************
25 //**
26 //** Functions to draw patches (by post) directly to screen.
27 //**
28 //**************************************************************************
29
30 // HEADER FILES ------------------------------------------------------------
31
32 #include "d3d_local.h"
33
34 // MACROS ------------------------------------------------------------------
35
36 // TYPES -------------------------------------------------------------------
37
38 // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
39
40 // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
41
42 // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
43
44 // EXTERNAL DATA DECLARATIONS ----------------------------------------------
45
46 // PUBLIC DATA DEFINITIONS -------------------------------------------------
47
48 // PRIVATE DATA DEFINITIONS ------------------------------------------------
49
50 // CODE --------------------------------------------------------------------
51
52 //==========================================================================
53 //
54 // VDirect3DDrawer::DrawPic
55 //
56 //==========================================================================
57
DrawPic(float x1,float y1,float x2,float y2,float s1,float t1,float s2,float t2,VTexture * Tex,VTextureTranslation * Trans,float Alpha)58 void VDirect3DDrawer::DrawPic(float x1, float y1, float x2, float y2,
59 float s1, float t1, float s2, float t2, VTexture* Tex,
60 VTextureTranslation* Trans, float Alpha)
61 {
62 guard(VDirect3DDrawer::DrawPic);
63 MyD3DVertex dv[4];
64 int l = ((int)(Alpha * 255) << 24) | 0xffffff;
65
66 SetPic(Tex, Trans, CM_Default);
67
68 dv[0] = MyD3DVertex(x1, y1, l, s1 * tex_iw, t1 * tex_ih);
69 dv[1] = MyD3DVertex(x2, y1, l, s2 * tex_iw, t1 * tex_ih);
70 dv[2] = MyD3DVertex(x2, y2, l, s2 * tex_iw, t2 * tex_ih);
71 dv[3] = MyD3DVertex(x1, y2, l, s1 * tex_iw, t2 * tex_ih);
72
73 if (Alpha < 1.0)
74 {
75 RenderDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
76 RenderDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
77 }
78
79 RenderDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, dv, sizeof(MyD3DVertex));
80
81 if (Alpha < 1.0)
82 {
83 RenderDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
84 RenderDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
85 }
86 unguard;
87 }
88
89 //==========================================================================
90 //
91 // VDirect3DDrawer::DrawPicShadow
92 //
93 //==========================================================================
94
DrawPicShadow(float x1,float y1,float x2,float y2,float s1,float t1,float s2,float t2,VTexture * Tex,float shade)95 void VDirect3DDrawer::DrawPicShadow(float x1, float y1, float x2, float y2,
96 float s1, float t1, float s2, float t2, VTexture* Tex, float shade)
97 {
98 guard(VDirect3DDrawer::DrawPicShadow);
99 MyD3DVertex dv[4];
100 int l = (int)(shade * 255) << 24;
101
102 SetPic(Tex, NULL, CM_Default);
103
104 dv[0] = MyD3DVertex(x1, y1, l, s1 * tex_iw, t1 * tex_ih);
105 dv[1] = MyD3DVertex(x2, y1, l, s2 * tex_iw, t1 * tex_ih);
106 dv[2] = MyD3DVertex(x2, y2, l, s2 * tex_iw, t2 * tex_ih);
107 dv[3] = MyD3DVertex(x1, y2, l, s1 * tex_iw, t2 * tex_ih);
108
109 RenderDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
110 RenderDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
111
112 RenderDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, dv, sizeof(MyD3DVertex));
113
114 RenderDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
115 RenderDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
116 unguard;
117 }
118
119 //==========================================================================
120 //
121 // VDirect3DDrawer::FillRectWithFlat
122 //
123 // Fills rectangle with flat.
124 //
125 //==========================================================================
126
FillRectWithFlat(float x1,float y1,float x2,float y2,float s1,float t1,float s2,float t2,VTexture * Tex)127 void VDirect3DDrawer::FillRectWithFlat(float x1, float y1, float x2, float y2,
128 float s1, float t1, float s2, float t2, VTexture* Tex)
129 {
130 guard(VDirect3DDrawer::FillRectWithFlat);
131 MyD3DVertex dv[4];
132 int l = 0xffffffff;
133
134 SetTexture(Tex, CM_Default);
135
136 dv[0] = MyD3DVertex(x1, y1, l, s1 * tex_iw, t1 * tex_ih);
137 dv[1] = MyD3DVertex(x2, y1, l, s2 * tex_iw, t1 * tex_ih);
138 dv[2] = MyD3DVertex(x2, y2, l, s2 * tex_iw, t2 * tex_ih);
139 dv[3] = MyD3DVertex(x1, y2, l, s1 * tex_iw, t2 * tex_ih);
140
141 RenderDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, dv, sizeof(MyD3DVertex));
142 unguard;
143 }
144
145 //==========================================================================
146 //
147 // VDirect3DDrawer::FillRect
148 //
149 //==========================================================================
150
FillRect(float x1,float y1,float x2,float y2,vuint32 colour)151 void VDirect3DDrawer::FillRect(float x1, float y1, float x2, float y2,
152 vuint32 colour)
153 {
154 guard(VDirect3DDrawer::FillRect);
155 MyD3DVertex dv[4];
156
157 dv[0] = MyD3DVertex(x1, y1, colour, 0, 0);
158 dv[1] = MyD3DVertex(x2, y1, colour, 0, 0);
159 dv[2] = MyD3DVertex(x2, y2, colour, 0, 0);
160 dv[3] = MyD3DVertex(x1, y2, colour, 0, 0);
161
162 RenderDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);
163 RenderDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
164 RenderDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, dv, sizeof(MyD3DVertex));
165 RenderDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
166 RenderDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
167 unguard;
168 }
169
170 //==========================================================================
171 //
172 // VDirect3DDrawer::ShadeRect
173 //
174 // Fade all the screen buffer, so that the menu is more readable,
175 // especially now that we use the small hufont in the menus...
176 //
177 //==========================================================================
178
ShadeRect(int x,int y,int w,int h,float darkening)179 void VDirect3DDrawer::ShadeRect(int x, int y, int w, int h, float darkening)
180 {
181 guard(VDirect3DDrawer::ShadeRect);
182 MyD3DVertex dv[4];
183 int l = (int)(darkening * 255) << 24;
184
185 RenderDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);
186 RenderDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
187 RenderDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
188
189 dv[0] = MyD3DVertex(x, y, l, 0, 0);
190 dv[1] = MyD3DVertex(x + w, y, l, 0, 0);
191 dv[2] = MyD3DVertex(x + w, y + h, l, 0, 0);
192 dv[3] = MyD3DVertex(x, y + h, l, 0, 0);
193
194 RenderDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, dv, sizeof(MyD3DVertex));
195
196 RenderDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
197 RenderDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
198 RenderDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
199 unguard;
200 }
201
202 //==========================================================================
203 //
204 // VDirect3DDrawer::DrawConsoleBackground
205 //
206 //==========================================================================
207
DrawConsoleBackground(int h)208 void VDirect3DDrawer::DrawConsoleBackground(int h)
209 {
210 guard(VDirect3DDrawer::DrawConsoleBackground);
211 MyD3DVertex dv[4];
212 int l = 0xc000007f;
213
214 RenderDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);
215 RenderDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
216 RenderDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
217
218 dv[0] = MyD3DVertex(0, 0, l, 0, 0);
219 dv[1] = MyD3DVertex(ScreenWidth, 0, l, 0, 0);
220 dv[2] = MyD3DVertex(ScreenWidth, h, l, 0, 0);
221 dv[3] = MyD3DVertex(0, h, l, 0, 0);
222
223 RenderDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, dv, sizeof(MyD3DVertex));
224
225 RenderDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
226 RenderDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
227 RenderDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
228 unguard;
229 }
230
231 //==========================================================================
232 //
233 // VDirect3DDrawer::DrawSpriteLump
234 //
235 //==========================================================================
236
DrawSpriteLump(float x1,float y1,float x2,float y2,VTexture * Tex,VTextureTranslation * Translation,bool flip)237 void VDirect3DDrawer::DrawSpriteLump(float x1, float y1, float x2, float y2,
238 VTexture* Tex, VTextureTranslation* Translation, bool flip)
239 {
240 guard(VDirect3DDrawer::DrawSpriteLump);
241 SetSpriteLump(Tex, Translation, CM_Default);
242
243 float s1, s2;
244 if (flip)
245 {
246 s1 = Tex->GetWidth() * tex_iw;
247 s2 = 0;
248 }
249 else
250 {
251 s1 = 0;
252 s2 = Tex->GetWidth() * tex_iw;
253 }
254 float texh = Tex->GetHeight() * tex_ih;
255
256 MyD3DVertex dv[4];
257
258 dv[0] = MyD3DVertex(x1, y1, 0xffffffff, s1, 0);
259 dv[1] = MyD3DVertex(x2, y1, 0xffffffff, s2, 0);
260 dv[2] = MyD3DVertex(x2, y2, 0xffffffff, s2, texh);
261 dv[3] = MyD3DVertex(x1, y2, 0xffffffff, s1, texh);
262
263 RenderDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, dv, sizeof(MyD3DVertex));
264 unguard;
265 }
266
267 //==========================================================================
268 //
269 // VDirect3DDrawer::StartAutomap
270 //
271 //==========================================================================
272
StartAutomap()273 void VDirect3DDrawer::StartAutomap()
274 {
275 guard(VDirect3DDrawer::StartAutomap);
276 RenderDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);
277 RenderDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
278 RenderDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
279 unguard;
280 }
281
282 //==========================================================================
283 //
284 // VDirect3DDrawer::DrawLine
285 //
286 //==========================================================================
287
DrawLine(int x1,int y1,vuint32 c1,int x2,int y2,vuint32 c2)288 void VDirect3DDrawer::DrawLine(int x1, int y1, vuint32 c1, int x2, int y2,
289 vuint32 c2)
290 {
291 guard(VDirect3DDrawer::DrawLine);
292 MyD3DVertex out[2];
293 out[0] = MyD3DVertex(x1, y1, c1, 0, 0);
294 out[1] = MyD3DVertex(x2, y2, c2, 0, 0);
295 RenderDevice->DrawPrimitiveUP(D3DPT_LINELIST, 1, out, sizeof(MyD3DVertex));
296 unguard;
297 }
298
299 //==========================================================================
300 //
301 // VDirect3DDrawer::EndAutomap
302 //
303 //==========================================================================
304
EndAutomap()305 void VDirect3DDrawer::EndAutomap()
306 {
307 guard(VDirect3DDrawer::EndAutomap);
308 RenderDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
309 RenderDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
310 RenderDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
311 unguard;
312 }
313