1 //**************************************************************************
9 //** OpenGL drawing functions.
11 //**************************************************************************
13 // HEADER FILES ------------------------------------------------------------
16 #define WIN32_LEAN_AND_MEAN
29 // MACROS ------------------------------------------------------------------
31 // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
33 // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
35 // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
37 // EXTERNAL DATA DECLARATIONS ----------------------------------------------
39 // PUBLIC DATA DEFINITIONS -------------------------------------------------
41 // PRIVATE DATA DEFINITIONS ------------------------------------------------
43 static int curfilter = 0; // The current filter (0 = none).
45 // CODE --------------------------------------------------------------------
47 void OGL_DrawRawScreen(int lump) // Raw screens are 320 x 200.
51 //float shift64 = 1.0/(64*screenWidth/320.0);
52 //float onePhysPixel = 320/(float)screenWidth;
54 glMatrixMode(GL_MODELVIEW);
57 glMatrixMode(GL_PROJECTION);
60 glOrtho (0, screenWidth, screenHeight, 0, -1, 1);
62 OGL_SetRawImage(lump,1);
63 tcbottom = lumptexsizes[lump].h / (float)FindNextPower2(lumptexsizes[lump].h);
64 pixelBorder = lumptexsizes[lump].w * screenWidth / 320;
71 glVertex2f(pixelBorder, 0);
72 glTexCoord2f(1,tcbottom);
73 glVertex2f(pixelBorder, screenHeight);
74 glTexCoord2f(0,tcbottom);
75 glVertex2f(0, screenHeight);
78 // And the other part.
79 OGL_SetRawImage(lump,2);
82 glVertex2f(pixelBorder-1, 0);
84 glVertex2f(screenWidth, 0);
85 glTexCoord2f(1, tcbottom);
86 glVertex2f(screenWidth, screenHeight);
87 glTexCoord2f(0, tcbottom);
88 glVertex2f(pixelBorder-1, screenHeight);
91 // Restore the old projection matrix.
94 glMatrixMode(GL_MODELVIEW);
98 // Drawing with the current state.
99 void OGL_DrawPatch_CS(int x, int y, int lumpnum)
102 float tcright, tcbottom;
105 OGL_SetPatch(lumpnum);
107 w = lumptexsizes[lumpnum].w;
108 h = lumptexsizes[lumpnum].h;
109 p2w = FindNextPower2(w);
110 p2h = OGL_ValidTexHeight2(w, h);
111 tcright = (float)w/(float)p2w;
112 tcbottom = (float)h/(float)p2h;
114 x += lumptexsizes[lumpnum].offx;
115 y += lumptexsizes[lumpnum].offy;
122 glTexCoord2f(tcright, 0);
125 glTexCoord2f(tcright, tcbottom);
126 glVertex2i(x+w, y+h);
128 glTexCoord2f(0, tcbottom);
133 // Is there a second part?
134 if(OGL_GetOtherPart(lumpnum))
138 OGL_BindTexture(OGL_GetOtherPart(lumpnum));
139 w = lumptexsizes[lumpnum].w2;
140 p2w = FindNextPower2(w);
141 tcright = w/(float)p2w;
148 glTexCoord2f(tcright, 0);
151 glTexCoord2f(tcright, tcbottom);
152 glVertex2i(x+w, y+h);
154 glTexCoord2f(0, tcbottom);
161 void OGL_DrawPatchLitAlpha(int x, int y, float light, float alpha, int lumpnum)
163 glColor4f(light, light, light, alpha);
164 OGL_DrawPatch_CS(x, y, lumpnum);
167 void OGL_DrawPatch(int x, int y, int lumpnum)
169 if(lumpnum < 0) return;
170 OGL_DrawPatchLitAlpha(x, y, 1, 1, lumpnum);
173 void OGL_DrawFuzzPatch(int x, int y, int lumpnum)
175 if(lumpnum < 0) return;
176 OGL_DrawPatchLitAlpha(x, y, 1, .333f, lumpnum);
179 void OGL_DrawAltFuzzPatch(int x, int y, int lumpnum)
181 if(lumpnum < 0) return;
182 OGL_DrawPatchLitAlpha(x, y, 1, .666f, lumpnum);
185 void OGL_DrawShadowedPatch(int x, int y, int lumpnum)
187 if(lumpnum < 0) return;
188 OGL_DrawPatchLitAlpha(x+2, y+2, 0, .4f, lumpnum);
189 OGL_DrawPatchLitAlpha(x, y, 1, 1, lumpnum);
192 extern void checkGLContext();
193 void OGL_DrawRect(float x, float y, float w, float h, float r, float g, float b, float a)
195 glColor4f(r, g, b, a);
202 glVertex2f(x+w, y+h);
208 void OGL_DrawRectTiled(int x, int y, int w, int h, int tw, int th)
213 glTexCoord2f(w/(float)tw, 0);
215 glTexCoord2f(w/(float)tw, h/(float)th);
216 glVertex2i(x+w, y+h);
217 glTexCoord2f(0, h/(float)th);
222 // The cut rectangle must be inside the other one.
223 void OGL_DrawCutRectTiled(int x, int y, int w, int h, int tw, int th,
224 int cx, int cy, int cw, int ch)
226 float ftw = tw, fth = th;
227 // We'll draw at max four rectangles.
228 int toph = cy-y, bottomh = y+h-(cy+ch), sideh = h-toph-bottomh,
229 lefth = cx-x, righth = x+w-(cx+cw);
234 // The top rectangle.
238 glTexCoord2f(w/ftw, 0);
241 glTexCoord2f(w/ftw, toph/fth);
242 glVertex2i(x+w, y+toph);
244 glTexCoord2f(0, toph/fth);
245 glVertex2i(x, y+toph);
247 if(lefth > 0 && sideh > 0)
249 float yoff = toph/fth;
250 // The left rectangle.
251 glTexCoord2f(0, yoff);
252 glVertex2i(x, y+toph);
254 glTexCoord2f(lefth/ftw, yoff);
255 glVertex2i(x+lefth, y+toph);
257 glTexCoord2f(lefth/ftw, yoff+sideh/fth);
258 glVertex2i(x+lefth, y+toph+sideh);
260 glTexCoord2f(0, yoff+sideh/fth);
261 glVertex2i(x, y+toph+sideh);
263 if(righth > 0 && sideh > 0)
266 float xoff = (lefth+cw)/ftw;
267 float yoff = toph/fth;
268 // The left rectangle.
269 glTexCoord2f(xoff, yoff);
270 glVertex2i(ox, y+toph);
272 glTexCoord2f(xoff+lefth/ftw, yoff);
273 glVertex2i(ox+righth, y+toph);
275 glTexCoord2f(xoff+lefth/ftw, yoff+sideh/fth);
276 glVertex2i(ox+righth, y+toph+sideh);
278 glTexCoord2f(xoff, yoff+sideh/fth);
279 glVertex2i(ox, y+toph+sideh);
283 int oy = y+toph+sideh;
284 float yoff = (toph+sideh)/fth;
285 glTexCoord2f(0, yoff);
288 glTexCoord2f(w/ftw, yoff);
291 glTexCoord2f(w/ftw, yoff+bottomh/fth);
292 glVertex2i(x+w, oy+bottomh);
294 glTexCoord2f(0, yoff+bottomh/fth);
295 glVertex2i(x, oy+bottomh);
300 void OGL_DrawLine(float x1, float y1, float x2, float y2,
301 float r, float g, float b, float a)
303 glColor4f(r, g, b, a);
310 void OGL_SetColor(int palidx)
314 if(palidx == -1) // Invisible?
318 PalIdxToRGB(W_CacheLumpNum(pallump,PU_CACHE), palidx, rgb);
319 glColor3f(rgb[0]/255.0, rgb[1]/255.0, rgb[2]/255.0);
323 void OGL_SetColorAndAlpha(float r, float g, float b, float a)
325 glColor4f(r, g, b, a);
328 // Filters correspond the palettes in the wad.
329 void OGL_SetFilter(int filter)
334 // Returns nonzero if the filter was drawn.
337 if(!curfilter) return 0; // No filter needed.
339 // No texture, please.
340 //glBindTexture(GL_TEXTURE_2D, 0);
341 glDisable( GL_TEXTURE_2D );
343 // We have to choose the right color and alpha.
344 if(curfilter >= STARTREDPALS && curfilter < STARTREDPALS+NUMREDPALS)
346 glColor4f(1, 0, 0, curfilter/8.0); // Full red with filter 8.
347 else if(curfilter >= STARTBONUSPALS && curfilter < STARTBONUSPALS+NUMBONUSPALS)
349 glColor4f(.5, 1, .5, (curfilter-STARTBONUSPALS+1)/12.0);
351 I_Error("OGL_DrawFilter: Real strange filter number: %d.\n", curfilter);
356 glVertex2f(320, 200);
360 glEnable( GL_TEXTURE_2D );