1 //**************************************************************************
9 //** OpenGL drawing functions.
11 //**************************************************************************
13 // HEADER FILES ------------------------------------------------------------
16 #define WIN32_LEAN_AND_MEAN
30 // MACROS ------------------------------------------------------------------
32 // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
34 // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
36 // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
38 // EXTERNAL DATA DECLARATIONS ----------------------------------------------
40 // PUBLIC DATA DEFINITIONS -------------------------------------------------
42 // PRIVATE DATA DEFINITIONS ------------------------------------------------
44 static int curfilter = 0; // The current filter (0 = none).
46 // CODE --------------------------------------------------------------------
48 void OGL_DrawRawScreen(int lump) // Raw screens are 320 x 200.
52 //float shift64 = 1.0/(64*screenWidth/320.0);
53 //float onePhysPixel = 320/(float)screenWidth;
55 glMatrixMode(GL_MODELVIEW);
58 glMatrixMode(GL_PROJECTION);
61 gluOrtho2D(0, screenWidth, screenHeight, 0);
63 OGL_SetRawImage(lump,1);
64 tcbottom = lumptexsizes[lump].h / (float)FindNextPower2(lumptexsizes[lump].h);
65 pixelBorder = lumptexsizes[lump].w * screenWidth / 320;
72 glVertex2f(pixelBorder, 0);
73 glTexCoord2f(1,tcbottom);
74 glVertex2f(pixelBorder, screenHeight);
75 glTexCoord2f(0,tcbottom);
76 glVertex2f(0, screenHeight);
79 // And the other part.
80 OGL_SetRawImage(lump,2);
83 glVertex2f(pixelBorder-1, 0);
85 glVertex2f(screenWidth, 0);
86 glTexCoord2f(1, tcbottom);
87 glVertex2f(screenWidth, screenHeight);
88 glTexCoord2f(0, tcbottom);
89 glVertex2f(pixelBorder-1, screenHeight);
92 // Restore the old projection matrix.
95 glMatrixMode(GL_MODELVIEW);
99 // Drawing with the current state.
100 void OGL_DrawPatch_CS(int x, int y, int lumpnum)
103 float tcright, tcbottom;
106 OGL_SetPatch(lumpnum);
108 w = lumptexsizes[lumpnum].w;
109 h = lumptexsizes[lumpnum].h;
110 p2w = FindNextPower2(w);
111 p2h = OGL_ValidTexHeight2(w, h);
112 tcright = (float)w/(float)p2w;
113 tcbottom = (float)h/(float)p2h;
115 x += lumptexsizes[lumpnum].offx;
116 y += lumptexsizes[lumpnum].offy;
123 glTexCoord2f(tcright, 0);
126 glTexCoord2f(tcright, tcbottom);
127 glVertex2i(x+w, y+h);
129 glTexCoord2f(0, tcbottom);
134 // Is there a second part?
135 if(OGL_GetOtherPart(lumpnum))
139 OGL_BindTexture(OGL_GetOtherPart(lumpnum));
140 w = lumptexsizes[lumpnum].w2;
141 p2w = FindNextPower2(w);
142 tcright = w/(float)p2w;
149 glTexCoord2f(tcright, 0);
152 glTexCoord2f(tcright, tcbottom);
153 glVertex2i(x+w, y+h);
155 glTexCoord2f(0, tcbottom);
162 void OGL_DrawPatchLitAlpha(int x, int y, float light, float alpha, int lumpnum)
164 glColor4f(light, light, light, alpha);
165 OGL_DrawPatch_CS(x, y, lumpnum);
168 void OGL_DrawPatch(int x, int y, int lumpnum)
170 if(lumpnum < 0) return;
171 OGL_DrawPatchLitAlpha(x, y, 1, 1, lumpnum);
174 void OGL_DrawFuzzPatch(int x, int y, int lumpnum)
176 if(lumpnum < 0) return;
177 OGL_DrawPatchLitAlpha(x, y, 1, .333f, lumpnum);
180 void OGL_DrawAltFuzzPatch(int x, int y, int lumpnum)
182 if(lumpnum < 0) return;
183 OGL_DrawPatchLitAlpha(x, y, 1, .666f, lumpnum);
186 void OGL_DrawShadowedPatch(int x, int y, int lumpnum)
188 if(lumpnum < 0) return;
189 OGL_DrawPatchLitAlpha(x+2, y+2, 0, .4f, lumpnum);
190 OGL_DrawPatchLitAlpha(x, y, 1, 1, lumpnum);
193 extern void checkGLContext();
194 void OGL_DrawRect(float x, float y, float w, float h, float r, float g, float b, float a)
196 glColor4f(r, g, b, a);
203 glVertex2f(x+w, y+h);
209 void OGL_DrawRectTiled(int x, int y, int w, int h, int tw, int th)
214 glTexCoord2f(w/(float)tw, 0);
216 glTexCoord2f(w/(float)tw, h/(float)th);
217 glVertex2i(x+w, y+h);
218 glTexCoord2f(0, h/(float)th);
223 // The cut rectangle must be inside the other one.
224 void OGL_DrawCutRectTiled(int x, int y, int w, int h, int tw, int th,
225 int cx, int cy, int cw, int ch)
227 float ftw = tw, fth = th;
228 // We'll draw at max four rectangles.
229 int toph = cy-y, bottomh = y+h-(cy+ch), sideh = h-toph-bottomh,
230 lefth = cx-x, righth = x+w-(cx+cw);
235 // The top rectangle.
239 glTexCoord2f(w/ftw, 0);
242 glTexCoord2f(w/ftw, toph/fth);
243 glVertex2i(x+w, y+toph);
245 glTexCoord2f(0, toph/fth);
246 glVertex2i(x, y+toph);
248 if(lefth > 0 && sideh > 0)
250 float yoff = toph/fth;
251 // The left rectangle.
252 glTexCoord2f(0, yoff);
253 glVertex2i(x, y+toph);
255 glTexCoord2f(lefth/ftw, yoff);
256 glVertex2i(x+lefth, y+toph);
258 glTexCoord2f(lefth/ftw, yoff+sideh/fth);
259 glVertex2i(x+lefth, y+toph+sideh);
261 glTexCoord2f(0, yoff+sideh/fth);
262 glVertex2i(x, y+toph+sideh);
264 if(righth > 0 && sideh > 0)
267 float xoff = (lefth+cw)/ftw;
268 float yoff = toph/fth;
269 // The left rectangle.
270 glTexCoord2f(xoff, yoff);
271 glVertex2i(ox, y+toph);
273 glTexCoord2f(xoff+lefth/ftw, yoff);
274 glVertex2i(ox+righth, y+toph);
276 glTexCoord2f(xoff+lefth/ftw, yoff+sideh/fth);
277 glVertex2i(ox+righth, y+toph+sideh);
279 glTexCoord2f(xoff, yoff+sideh/fth);
280 glVertex2i(ox, y+toph+sideh);
284 int oy = y+toph+sideh;
285 float yoff = (toph+sideh)/fth;
286 glTexCoord2f(0, yoff);
289 glTexCoord2f(w/ftw, yoff);
292 glTexCoord2f(w/ftw, yoff+bottomh/fth);
293 glVertex2i(x+w, oy+bottomh);
295 glTexCoord2f(0, yoff+bottomh/fth);
296 glVertex2i(x, oy+bottomh);
301 void OGL_DrawLine(float x1, float y1, float x2, float y2,
302 float r, float g, float b, float a)
304 glColor4f(r, g, b, a);
311 void OGL_SetColor(int palidx)
315 if(palidx == -1) // Invisible?
319 PalIdxToRGB(W_CacheLumpNum(pallump,PU_CACHE), palidx, rgb);
320 glColor3f(rgb[0]/255.0, rgb[1]/255.0, rgb[2]/255.0);
324 void OGL_SetColorAndAlpha(float r, float g, float b, float a)
326 glColor4f(r, g, b, a);
329 // Filters correspond the palettes in the wad.
330 void OGL_SetFilter(int filter)
335 // Returns nonzero if the filter was drawn.
338 if(!curfilter) return 0; // No filter needed.
340 // No texture, please.
341 //glBindTexture(GL_TEXTURE_2D, 0);
342 glDisable( GL_TEXTURE_2D );
344 // We have to choose the right color and alpha.
345 if(curfilter >= STARTREDPALS && curfilter < STARTREDPALS+NUMREDPALS)
347 glColor4f(1, 0, 0, curfilter/8.0); // Full red with filter 8.
348 else if(curfilter >= STARTBONUSPALS && curfilter < STARTBONUSPALS+NUMBONUSPALS)
350 glColor4f(.5, 1, .5, (curfilter-STARTBONUSPALS+1)/12.0);
351 else if(curfilter >= STARTPOISONPALS && curfilter < STARTPOISONPALS+NUMPOISONPALS)
353 glColor4f(0, 1, 0, (curfilter-STARTPOISONPALS+1)/16.0);
354 else if(curfilter >= STARTSCOURGEPAL)
356 glColor4f(1, .5, 0, (STARTSCOURGEPAL+3-curfilter)/6.0);
357 else if(curfilter >= STARTHOLYPAL)
359 glColor4f(1, 1, 1, (STARTHOLYPAL+3-curfilter)/6.0);
360 else if(curfilter == STARTICEPAL)
362 glColor4f(.5f, .5f, 1, .4f);
364 I_Error("OGL_DrawFilter: Real strange filter number: %d.\n", curfilter);
369 glVertex2f(320, 200);
373 glEnable( GL_TEXTURE_2D );