1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <math.h>
5 
6 #include "gl_syms.h"
7 
8 #include "gl_struct.h"
9 #include "gl_mem.h"
10 #include "doomdef.h"
11 #include "r_local.h"
12 #include "p_spec.h"
13 
14 extern GLboolean g_b3Dfx;
15 extern H_boolean shareware;
16 
17 extern int iNbGLTextures;
18 extern GLuint *texobjs;
19 extern byte *p_bPalette;
20 extern int	iNbGLSprites;
21 extern int iMaxSizeBeforeReduction;
22 
23 extern int FontABaseLump,FontBBaseLump;
24 extern GLuint *FontAobjs,*FontBobjs;
25 
26 extern int numpatches;
27 extern GLboolean g_bPaletteTexture;
28 /* PROC glColorTableEXT; */
29 
30 GLTexture *p_stGLFontA;
31 int	iNbGLFontA;
32 GLTexArray *p_stGLFontAArray;
33 GLMapSprite *p_stMapFontA;
34 short *FontAtopoffset,*FontAoffset;
35 
36 GLTexArray *p_stGLFontBArray;
37 short *FontBtopoffset,*FontBoffset;
38 
39 int numFontAlumps,numFontBlumps;
40 
41 #define NB_PATCHS	130
42 GLTexArray *p_stGLPatchArray;
43 short *Patchtopoffset,*Patchoffset;
44 int iPatchLump[NB_PATCHS];
45 char a_szPatchName[NB_PATCHS][10]=
46 {
47   /* Menus */
48   "PAUSED",
49   "M_SLCTR1",
50   "M_SLCTR2",
51   "M_HTIC",
52   "M_SKL00",
53   "M_SKL01",
54   "M_SKL02",
55   "M_SKL03",
56   "M_SKL04",
57   "M_SKL05",
58   "M_SKL06",
59   "M_SKL07",
60   "M_SKL08",
61   "M_SKL09",
62   "M_SKL10",
63   "M_SKL11",
64   "M_SKL12",
65   "M_SKL13",
66   "M_SKL14",
67   "M_SKL15",
68   "M_SKL16",
69   "M_SKL17",
70   "M_FSLOT",
71   "M_SLDLT",
72   "M_SLDMD1",
73   "M_SLDMD2",
74   "M_SLDRT",
75   "M_SLDKB",
76   /* Intermissions */
77   "IN_X",
78   "IN_YAH",
79   "FACEA0",
80   "FACEB0",
81   /* STATUS_BAR */
82   "LTFACE",
83   "RTFACE",
84   "INVBAR",
85   "LIFEBAR",
86   "LIFEGEM2",
87   "LTFCTOP",
88   "RTFCTOP",
89   "SELECTBOX",
90   "INVGEML1",
91   "INVGEML2",
92   "INVGEMR1",
93   "INVGEMR2",
94   "BLACKSQ",
95   "ARMCLEAR",
96   "IN0",
97   "IN1",
98   "IN2",
99   "IN3",
100   "IN4",
101   "IN5",
102   "IN6",
103   "IN7",
104   "IN8",
105   "IN9",
106   "NEGNUM",
107   "SMALLIN0",
108   "SMALLIN1",
109   "SMALLIN2",
110   "SMALLIN3",
111   "SMALLIN4",
112   "SMALLIN5",
113   "SMALLIN6",
114   "SMALLIN7",
115   "SMALLIN8",
116   "SMALLIN9",
117   "LAME",
118   /* BARBACK w=320 h=42 */
119   /* CHAIN w=296 h=8 */
120   /* CHAINBACK w=320 h=10 */
121   "BARBACK",
122   "CHAIN",
123   "CHAINBACK",
124   "SPFLY0",
125   "SPFLY1",
126   "SPFLY2",
127   "SPFLY3",
128   "SPFLY4",
129   "SPFLY5",
130   "SPFLY6",
131   "SPFLY7",
132   "SPFLY8",
133   "SPFLY9",
134   "SPFLY10",
135   "SPFLY11",
136   "SPFLY12",
137   "SPFLY13",
138   "SPFLY14",
139   "SPFLY15",
140   "SPINBK0",
141   "SPINBK1",
142   "SPINBK2",
143   "SPINBK3",
144   "SPINBK4",
145   "SPINBK5",
146   "SPINBK6",
147   "SPINBK7",
148   "SPINBK8",
149   "SPINBK9",
150   "SPINBK10",
151   "SPINBK11",
152   "SPINBK12",
153   "SPINBK13",
154   "SPINBK14",
155   "SPINBK15",
156   "USEARTIA",
157   "USEARTIB",
158   "USEARTIC",
159   "USEARTID",
160   "USEARTIE",
161   "ARTIBOX",
162   "ARTIINVU",
163   "ARTIINVS",
164   "ARTIPTN2",
165   "ARTISPHL",
166   "ARTIPWBK",
167   "ARTITRCH",
168   "ARTIFBMB",
169   "ARTIEGGC",
170   "ARTISOAR",
171   "ARTIATLP",
172   "INAMGLD",
173   "INAMBOW",
174   "INAMBST",
175   "INAMRAM",
176   "INAMPNX",
177   "INAMLOB",
178   "YKEYICON",
179   "GKEYICON",
180   "BKEYICON",
181   "GOD1",
182   "GOD2"
183 };
184 
185 #define NB_SCREENS 8
186 char a_szScreenNames[NB_SCREENS][8]=
187 {
188   /* V_DrawRawScreen */
189   "TITLE",
190   "ORDER",
191   "HELP1",
192   "HELP2",
193   "CREDIT",
194   /* V_DrawPatch */
195   "MAPE1",
196   "MAPE2",
197   "MAPE3"
198 };
199 
200 #define MNU_X(x)		(int)((float)(x)*screenwidth/320.0f)
201 #define MNU_Y(y)		(int)((float)(y)*screenheight/200.0f)
202 
203 extern float fScaleSprite;
204 
fn_vRegisterPatchs()205 void fn_vRegisterPatchs() {
206   patch_t *patch;
207   int i;
208   int iPrevMax;
209   float fPrevScale;
210 
211   fPrevScale=fScaleSprite;
212   iPrevMax=iMaxSizeBeforeReduction;
213   iMaxSizeBeforeReduction=65536;
214 
215   p_stGLPatchArray=(GLTexArray *)Malloc(NB_PATCHS*sizeof(GLTexArray));
216 
217   for (i=0;i<NB_PATCHS;i++)
218     p_stGLPatchArray[i].iTexID=-1;
219 
220   Patchtopoffset=(short *)Malloc(NB_PATCHS*sizeof(short));
221   Patchoffset=(short *)Malloc(NB_PATCHS*sizeof(short));
222   for (i=0;i<NB_PATCHS;i++) {
223     if (shareware&&
224 	(!strcmp(a_szPatchName[i],"ARTISPHL")||!strcmp(a_szPatchName[i],"ARTIATLP")||
225 	 !strcmp(a_szPatchName[i],"INAMRAM")||!strcmp(a_szPatchName[i],"INAMPNX")||
226 	 !strcmp(a_szPatchName[i],"INAMLOB")))	/* shareware */
227       continue;
228     iPatchLump[i]=W_GetNumForName(a_szPatchName[i]);
229     patch = W_CacheLumpNum(iPatchLump[i], PU_CACHE);
230     Patchtopoffset[i]=SHORT(patch->topoffset);
231     Patchoffset[i]=SHORT(patch->leftoffset);
232     if (g_b3Dfx) {
233       if ((!strcmp(a_szPatchName[i],"BARBACK"))||(!strcmp(a_szPatchName[i],"CHAINBACK")))
234 	{
235 	  iMaxSizeBeforeReduction=2;
236 	  fScaleSprite=0.8f;
237 	}
238       else
239 	if (!strcmp(a_szPatchName[i],"CHAIN"))
240 	  {
241 	    iMaxSizeBeforeReduction=2;
242 	    fScaleSprite=256.0f/296.0f;
243 	  }
244 	else
245 	  iMaxSizeBeforeReduction=65536;
246     }
247     fn_vRegisterSpriteCompressed(&p_stGLFontA,&p_stMapFontA,&p_stGLPatchArray,i,patch);
248   }
249   iNbGLFontA=iNbGLSprites;
250   /* fn_vSaveRAW("bar.raw",p_stGLFontA[3].p_bRGBBuffer,256,128); */
251 
252   iMaxSizeBeforeReduction=iPrevMax;
253   fScaleSprite=fPrevScale;
254 }
255 
GL_GetNumForName(char * szName)256 int GL_GetNumForName(char *szName) {
257   int i;
258 
259   for (i=0;i<NB_PATCHS;i++)
260     if (!strcasecmp(szName,a_szPatchName[i]))
261       return i;
262   return -1;
263 }
264 
GL_DrawCompressedPatch(int x,int y,int iWidth,int iHeight,int iLump)265 void GL_DrawCompressedPatch(int x, int y, int iWidth, int iHeight,int iLump) {
266   /* For 3Dfx (Max texture size is 256x256) */
267   float fU1,fU2,fV1,fV2;
268   int iTexIndex,iSubTex,i;
269 
270   if (iLump==-1)
271     return;	/* Patch not registered */
272   i=iLump;
273   {
274     x=MNU_X(x);
275     y=MNU_Y(y);
276 
277     y -= MNU_Y(Patchtopoffset[i]);
278     x -= MNU_X(Patchoffset[i]);
279 
280     iTexIndex=p_stGLPatchArray[i].iGLTexIndex;
281     iSubTex=p_stGLPatchArray[i].iUVIndex;
282     fU1=(float)p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iU/(float)p_stGLFontA[iTexIndex].iWidth;
283     fU2=(float)(p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iU+p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iWidth)/(float)p_stGLFontA[iTexIndex].iWidth;
284     fV1=(float)p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iV/(float)p_stGLFontA[iTexIndex].iHeight;
285     fV2=(float)(p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iV+p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iHeight)/(float)p_stGLFontA[iTexIndex].iHeight;
286     iWidth=MNU_X(iWidth);
287     iHeight=MNU_Y(iHeight);
288 
289 
290     (*glBindTexture_s) (GL_TEXTURE_2D, FontAobjs[iTexIndex]);
291 
292     (*glBegin_s) (GL_QUADS);
293     (*glTexCoord2f_s) (fU1, fV1); (*glVertex2f_s) ( x, screenheight-1-y );
294     (*glTexCoord2f_s) (fU1, fV2); (*glVertex2f_s) ( x, screenheight-1-y-iHeight );
295     (*glTexCoord2f_s) (fU2, fV2); (*glVertex2f_s) ( x+iWidth, screenheight-1-y-iHeight );
296     (*glTexCoord2f_s) (fU2, fV1); (*glVertex2f_s) ( x+iWidth, screenheight-1-y );
297     (*glEnd_s) ();
298   }
299 }
300 
GL_DrawPatch(int x,int y,int iLump)301 void GL_DrawPatch(int x, int y, int iLump) {
302   float fU1,fU2,fV1,fV2;
303   int iTexIndex,iSubTex,iWidth,iHeight,i;
304 
305   if (iLump==-1)
306     return;	/* Patch not registered */
307   i=iLump;
308   {
309     x=MNU_X(x);
310     y=MNU_Y(y);
311 
312     y -= MNU_Y(Patchtopoffset[i]);
313     x -= MNU_X(Patchoffset[i]);
314 
315     iTexIndex=p_stGLPatchArray[i].iGLTexIndex;
316     iSubTex=p_stGLPatchArray[i].iUVIndex;
317     fU1=(float)p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iU/(float)p_stGLFontA[iTexIndex].iWidth;
318     fU2=(float)(p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iU+p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iWidth)/(float)p_stGLFontA[iTexIndex].iWidth;
319     fV1=(float)p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iV/(float)p_stGLFontA[iTexIndex].iHeight;
320     fV2=(float)(p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iV+p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iHeight)/(float)p_stGLFontA[iTexIndex].iHeight;
321     iWidth=MNU_X(p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iWidth);
322     iHeight=MNU_Y(p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iHeight);
323 
324     (*glBindTexture_s) (GL_TEXTURE_2D, FontAobjs[iTexIndex]);
325 
326     (*glBegin_s) (GL_QUADS);
327     (*glTexCoord2f_s)(fU1, fV1); (*glVertex2f_s)( x, screenheight-1-y );
328     (*glTexCoord2f_s)(fU1, fV2); (*glVertex2f_s)( x, screenheight-1-y-iHeight );
329     (*glTexCoord2f_s)(fU2, fV2); (*glVertex2f_s)( x+iWidth, screenheight-1-y-iHeight );
330     (*glTexCoord2f_s)(fU2, fV1); (*glVertex2f_s)( x+iWidth, screenheight-1-y );
331     (*glEnd_s) ();
332   }
333 }
334 
GL_DrawShadowedPatch(int x,int y,int iLump)335 void GL_DrawShadowedPatch(int x, int y, int iLump) {
336   (*glColor3f_s) (0.5f,0.5f,0.5f);
337   GL_DrawShadowedPatch(x,y,iLump);
338   (*glColor3f_s) (1.0f,1.0f,1.0f);
339 }
340 
341 GLboolean g_bInitFonts=false;
fn_vGLInitFonts()342 GLvoid fn_vGLInitFonts() {
343   patch_t *patch;
344   int i;
345 
346   g_bInitFonts=true;
347   SPRITE_WIDTH=128;
348   SPRITE_HEIGHT=128;
349   numFontAlumps=W_GetNumForName("FONTA_E")-W_GetNumForName("FONTA_S");
350   numFontBlumps=W_GetNumForName("FONTB_E")-W_GetNumForName("FONTB_S");
351 
352   p_stGLFontA=(GLTexture *)Malloc(sizeof(GLTexture));
353   p_stMapFontA=(GLMapSprite *)Malloc(sizeof(GLMapSprite));
354   p_stGLFontAArray=(GLTexArray *)Malloc(numFontAlumps*sizeof(GLTexArray));
355   for (i=0;i<numFontAlumps;i++)
356     p_stGLFontAArray[i].iTexID=-1;
357   p_bPalette=W_CacheLumpName("PLAYPAL", PU_STATIC);
358 
359   p_stGLFontBArray=(GLTexArray *)Malloc(numFontBlumps*sizeof(GLTexArray));
360   for (i=0;i<numFontBlumps;i++)
361     p_stGLFontBArray[i].iTexID=-1;
362 
363   FontAtopoffset=(short *)Malloc(numFontAlumps*sizeof(short));
364   FontAoffset=(short *)Malloc(numFontAlumps*sizeof(short));
365   iNbGLSprites=0;
366   for (i=0;i<numFontAlumps;i++)
367     {
368        /*printf("fontachar %d (%d) ",i, FontABaseLump+i);*/
369       patch = W_CacheLumpNum(FontABaseLump+i, PU_CACHE);
370       /*printf("  %dx%d:\n",(unsigned int)(SHORT(patch->width)),(unsigned int)(SHORT(patch->width)));*/
371       /* sanity check */
372       if(SHORT(patch->width)>20) {
373 	 printf("[SDLGLdrv/fonts] fonta %d eek!\n",i);
374 	 continue;
375       }
376       FontAtopoffset[i]=SHORT(patch->topoffset);
377       FontAoffset[i]=SHORT(patch->leftoffset);
378       fn_vRegisterSpriteCompressed(&p_stGLFontA,&p_stMapFontA,&p_stGLFontAArray,i,patch);
379     }
380 
381   FontBtopoffset=(short *)Malloc(numFontBlumps*sizeof(short));
382   FontBoffset=(short *)Malloc(numFontBlumps*sizeof(short));
383 
384   for (i=0;i<numFontBlumps-1;i++)	/* Why -1 ??? */
385     {
386        /*printf("fontbchar %d (%d) ",i, FontBBaseLump+i);*/
387       patch = W_CacheLumpNum(FontBBaseLump+i, PU_CACHE);
388       /*printf("  %dx%d:\n",(unsigned int)(SHORT(patch->width)),(unsigned int)(SHORT(patch->width)));*/
389       /* sanity check */
390       if(SHORT(patch->width)>20) {
391 	 printf("[SDLGLdrv/fonts] fontb %d eek!\n",i);
392 	 continue;
393       }
394       FontBtopoffset[i]=SHORT(patch->topoffset);
395       FontBoffset[i]=SHORT(patch->leftoffset);
396       fn_vRegisterSpriteCompressed(&p_stGLFontA,&p_stMapFontA,&p_stGLFontBArray,i,patch);
397     }
398   iNbGLFontA=iNbGLSprites;
399 
400   /* Register other patchs... */
401   fn_vRegisterPatchs();
402 
403   iNbGLSprites=0;
404 
405   SPRITE_WIDTH=SPRITE_HEIGHT=128;
406   g_bInitFonts=false;
407 }
408 
GL_DrawLetterA(int x,int y,int lump)409 int GL_DrawLetterA(int x,int y,int lump) {
410   float fU1,fU2,fV1,fV2;
411   int iTexIndex,iSubTex,iWidth,iHeight;
412 
413   y -= MNU_Y(FontAtopoffset[lump]);
414   x -= MNU_X(FontAoffset[lump]);
415 
416   iTexIndex=p_stGLFontAArray[lump].iGLTexIndex;
417   iSubTex=p_stGLFontAArray[lump].iUVIndex;
418   fU1=(float)p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iU/(float)p_stGLFontA[iTexIndex].iWidth;
419   fU2=(float)(p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iU+p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iWidth)/(float)p_stGLFontA[iTexIndex].iWidth;
420   fV1=(float)p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iV/(float)p_stGLFontA[iTexIndex].iHeight;
421   fV2=(float)(p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iV+p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iHeight)/(float)p_stGLFontA[iTexIndex].iHeight;
422   iWidth=MNU_X(p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iWidth);
423   iHeight=MNU_Y(p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iHeight);
424 
425   (*glBindTexture_s) (GL_TEXTURE_2D, FontAobjs[iTexIndex]);
426 
427   (*glBegin_s) (GL_QUADS);
428   (*glTexCoord2f_s) (fU1, fV1); (*glVertex2f_s) ( x, screenheight-1-y );
429   (*glTexCoord2f_s) (fU1, fV2); (*glVertex2f_s) ( x, screenheight-1-y-iHeight );
430   (*glTexCoord2f_s) (fU2, fV2); (*glVertex2f_s) ( x+iWidth, screenheight-1-y-iHeight );
431   (*glTexCoord2f_s) (fU2, fV1); (*glVertex2f_s) ( x+iWidth, screenheight-1-y );
432   (*glEnd_s) ();
433 
434   return p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iWidth;
435 }
436 
GL_DrTextA(char * text,int x,int y)437 void GL_DrTextA(char *text, int x, int y) {
438   char c;
439   int width;
440 
441   while((c = *text++) != 0) {
442     if(c < 33)
443       {
444 	x += 5;
445       }
446     else
447       {
448 	width=GL_DrawLetterA(MNU_X(x), MNU_Y(y), c-33);
449 	x += width-1;
450       }
451   }
452 }
453 
GL_DrawLetterB(int x,int y,int lump)454 int GL_DrawLetterB(int x,int y,int lump) {
455   float fU1,fU2,fV1,fV2;
456   int iTexIndex,iSubTex,iWidth,iHeight;
457 
458   y -= MNU_Y(FontBtopoffset[lump]);
459   x -= MNU_X(FontBoffset[lump]);
460 
461   iTexIndex=p_stGLFontBArray[lump].iGLTexIndex;
462   iSubTex=p_stGLFontBArray[lump].iUVIndex;
463 
464   fU1=(float)p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iU/(float)p_stGLFontA[iTexIndex].iWidth;
465   fU2=(float)(p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iU+p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iWidth)/(float)p_stGLFontA[iTexIndex].iWidth;
466   fV1=(float)p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iV/(float)p_stGLFontA[iTexIndex].iHeight;
467   fV2=(float)(p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iV+p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iHeight)/(float)p_stGLFontA[iTexIndex].iHeight;
468   iWidth=MNU_X(p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iWidth);
469   iHeight=MNU_Y(p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iHeight);
470 
471   (*glBindTexture_s) (GL_TEXTURE_2D, FontAobjs[iTexIndex]);
472 
473   (*glBegin_s) (GL_QUADS);
474   (*glTexCoord2f_s) (fU1, fV1); (*glVertex2f_s) ( x, screenheight-1-y );
475   (*glTexCoord2f_s) (fU1, fV2); (*glVertex2f_s) ( x, screenheight-1-y-iHeight );
476   (*glTexCoord2f_s) (fU2, fV2); (*glVertex2f_s) ( x+iWidth, screenheight-1-y-iHeight );
477   (*glTexCoord2f_s) (fU2, fV1); (*glVertex2f_s) ( x+iWidth, screenheight-1-y );
478   (*glEnd_s) ();
479 
480   return p_stGLFontA[iTexIndex].a_stSubTex[iSubTex].iWidth;
481 }
482 
GL_DrawShadowedLetterB(int x,int y,int lump)483 int GL_DrawShadowedLetterB(int x,int y,int lump) {
484   int width;
485 
486   (*glColor3f_s) (0.5f,0.5f,0.5f);
487   width=GL_DrawLetterB(MNU_X(x),MNU_Y(y),lump);
488   (*glColor3f_s) (1.0f,1.0f,1.0f);
489 
490   return width;
491 }
492 
GL_DrTextB(char * text,int x,int y)493 void GL_DrTextB(char *text, int x, int y) {
494   char c;
495   int width;
496 
497   while((c = *text++) != 0) {
498     if(c < 33)
499       {
500 	x += 8;
501       }
502     else
503       {
504 	width=GL_DrawLetterB(MNU_X(x), MNU_Y(y), c-33);
505 	x += width-1;
506       }
507   }
508 }
509 
510 /* For the MAP */
GL_DrawLine(int X0,int Y0,int X1,int Y1,byte BaseColor)511 GLvoid GL_DrawLine(int X0, int Y0, int X1, int Y1, byte BaseColor) {
512   (*glDisable_s) (GL_TEXTURE_2D);
513   (*glColor3f_s) ((float)p_bPalette[3*BaseColor]/255.0f,(float)p_bPalette[3*BaseColor+1]/255.0f,(float)p_bPalette[3*BaseColor+2]/255.0f);
514   (*glBegin_s) (GL_LINES);
515   (*glVertex2f_s) ( X0, screenheight-1-Y0 );
516   (*glVertex2f_s) ( X1, screenheight-1-Y1 );
517   (*glEnd_s) ();
518   (*glEnable_s) (GL_TEXTURE_2D);
519 }
520 
GL_DumpScreen()521 GLvoid GL_DumpScreen() {
522   (*glColor3f_s) (1.0f,1.0f,1.0f);
523   (*glClear_s) (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
524   (*glRasterPos2i_s) (0,0);
525 #ifdef PALETTED_TEXTURE
526   if (g_bPaletteTexture)
527     {
528       (*glColorTableEXT_s) (GL_TEXTURE_2D,GL_RGB8,256,GL_RGB,GL_UNSIGNED_BYTE,p_bPalette);
529       (*glDrawPixels_s) (screenwidth,screenheight,GL_COLOR_INDEX8_EXT,GL_UNSIGNED_BYTE,screen);
530     }
531   else
532 #endif
533   (*glDrawPixels_s) (screenwidth,screenheight,GL_RGB,GL_UNSIGNED_BYTE,screen);
534   (*glEnable_s) (GL_TEXTURE_2D);
535   (*glColor3f_s) (1.0f,1.0f,1.0f);
536 }
537 
538 unsigned char *p_bRGBTitle1[NB_SCREENS],*p_bRGBTitle2[NB_SCREENS];
539 int iGlObjTITLE;
540 
GL_RegisterPatchScreen(int i)541 GLvoid GL_RegisterPatchScreen(int i) {
542   int y=0;
543   int count;
544   int col;
545   column_t *column;
546   byte *source;
547   int w;
548   patch_t *patch;
549 
550   patch=(patch_t *)W_CacheLumpName(a_szScreenNames[i],PU_CACHE);
551   w = SHORT(patch->width);
552 #ifdef PALETTED_TEXTURE
553   if (g_bPaletteTexture) {
554     p_bRGBTitle1[i]=(unsigned char *)Malloc(256*256);
555     for (col=0;col<256;col++) {
556       column = (column_t *)((byte *)patch+LONG(patch->columnofs[col]));
557       y=0;
558       while (column->topdelta != 0xff ) {
559 	source = (byte *)column + 3;
560 	count = column->length;
561 
562 	while (count--) {
563 	  p_bRGBTitle1[i][col+y*256]=*source;
564 	  source++;
565 	  y++;
566 	}
567 	column = (column_t *)(  (byte *)column + column->length+ 4 );
568       }
569     }
570     p_bRGBTitle2[i]=(unsigned char *)Malloc(64*256);
571     for (col=256;col<320;col++) {
572       column = (column_t *)((byte *)patch+LONG(patch->columnofs[col]));
573       y=0;
574       while (column->topdelta != 0xff ) {
575 	source = (byte *)column + 3;
576 	count = column->length;
577 
578 	while (count--) {
579 	  p_bRGBTitle2[i][col-256+y*64]=*source;
580 	  source++;
581 	  y++;
582 	}
583 	column = (column_t *)(  (byte *)column + column->length+ 4 );
584       }
585     }
586   }
587   else
588 #endif
589     {
590       p_bRGBTitle1[i]=(unsigned char *)Malloc(256*256*3);
591       for (col=0;col<256;col++) {
592 	column = (column_t *)((byte *)patch+LONG(patch->columnofs[col]));
593 	y=0;
594 	while (column->topdelta != 0xff ) {
595 	  source = (byte *)column + 3;
596 	  count = column->length;
597 
598 	  while (count--) {
599 	    p_bRGBTitle1[i][3*(col+y*256)]=p_bPalette[3**source];
600 	    p_bRGBTitle1[i][3*(col+y*256)+1]=p_bPalette[3**source+1];
601 	    p_bRGBTitle1[i][3*(col+y*256)+2]=p_bPalette[3**source+2];
602 	    source++;
603 	    y++;
604 	  }
605 	  column = (column_t *)(  (byte *)column + column->length+ 4 );
606 	}
607       }
608       p_bRGBTitle2[i]=(unsigned char *)Malloc(64*256*3);
609       for (col=256;col<320;col++) {
610 	column = (column_t *)((byte *)patch+LONG(patch->columnofs[col]));
611 	y=0;
612 	while (column->topdelta != 0xff ) {
613 	  source = (byte *)column + 3;
614 	  count = column->length;
615 
616 	  while (count--) {
617 	    p_bRGBTitle2[i][3*(col-256+y*64)]=p_bPalette[3**source];
618 	    p_bRGBTitle2[i][3*(col-256+y*64)+1]=p_bPalette[3**source+1];
619 	    p_bRGBTitle2[i][3*(col-256+y*64)+2]=p_bPalette[3**source+2];
620 	    source++;
621 	    y++;
622 	  }
623 	  column = (column_t *)(  (byte *)column + column->length+ 4 );
624 	}
625       }
626     }
627 
628   (*glBindTexture_s) (GL_TEXTURE_2D, iGlObjTITLE+2*i);
629   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
630   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
631   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
632   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
633   (*glTexEnvf_s) (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
634 
635 #ifdef PALETTED_TEXTURE
636   if (g_bPaletteTexture)
637     {
638       (*glColorTableEXT_s) (GL_TEXTURE_2D,GL_RGB8,256,GL_RGB,GL_UNSIGNED_BYTE,p_bPalette);
639       (*glTexImage2D_s) (GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, 256, 256, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, p_bRGBTitle1[i]);
640     }
641   else
642 #endif
643   (*glTexImage2D_s) (GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, p_bRGBTitle1[i]);
644 
645   (*glBindTexture_s) (GL_TEXTURE_2D, iGlObjTITLE+2*i+1);
646   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
647   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
648   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
649   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
650   (*glTexEnvf_s) (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
651 
652 #ifdef PALETTED_TEXTURE
653   if (g_bPaletteTexture)
654     {
655       (*glColorTableEXT_s) (GL_TEXTURE_2D,GL_RGB8,256,GL_RGB,GL_UNSIGNED_BYTE,p_bPalette);
656       (*glTexImage2D_s) (GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, 64, 256, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, p_bRGBTitle2[i]);
657     }
658   else
659 #endif
660   (*glTexImage2D_s) (GL_TEXTURE_2D, 0, 3, 64, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, p_bRGBTitle2[i]);
661 }
662 
GLDrawScreen(int i)663 GLvoid GLDrawScreen(int i) {
664   if (i==1)
665     i=4;
666   (*glEnable_s) (GL_TEXTURE_2D);
667   (*glColor3f_s) (1.0f,1.0f,1.0f);
668   (*glClear_s) (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
669 
670   (*glBindTexture_s) (GL_TEXTURE_2D,iGlObjTITLE+2*i);
671   (*glBegin_s) (GL_QUADS);
672   (*glTexCoord2f_s) (0,0);		(*glVertex2f_s) (0,(float)screenheight);
673   (*glTexCoord2f_s) (1,0);		(*glVertex2f_s) (0.8f*screenwidth,(float)screenheight);
674   (*glTexCoord2f_s) (1,0.78125f);		(*glVertex2f_s) (0.8f*screenwidth,0);
675   (*glTexCoord2f_s) (0,0.78125f);		(*glVertex2f_s) (0,0);
676   (*glEnd_s) ();
677   (*glBindTexture_s) (GL_TEXTURE_2D,iGlObjTITLE+2*i+1);
678   (*glBegin_s) (GL_QUADS);
679   (*glTexCoord2f_s) (0,0);		(*glVertex2f_s) (0.8f*screenwidth,(float)screenheight);
680   (*glTexCoord2f_s) (1,0);		(*glVertex2f_s) ((float)screenwidth,(float)screenheight);
681   (*glTexCoord2f_s) (1,0.78125f);		(*glVertex2f_s) ((float)screenwidth,0);
682   (*glTexCoord2f_s) (0,0.78125f);		(*glVertex2f_s) (0.8f*screenwidth,0);
683   (*glEnd_s) ();
684 }
685 
GLDrawScreenFromName(char * name)686 GLvoid GLDrawScreenFromName(char *name) {
687   int i;
688   for (i=0;i<NB_SCREENS;i++)
689     if (!strcmp(name,a_szScreenNames[i]))
690       break;
691   if (i==NB_SCREENS)
692     return;
693 
694   GLDrawScreen(i);
695 }
696 
GLRegisterScreen(int i)697 GLvoid GLRegisterScreen(int i) {	/* 2 textures for one 320x200 screen because of the 3Dfx limitations (256x256) */
698   byte *patch;
699   int x,y;
700 
701   patch=(byte *)W_CacheLumpName(a_szScreenNames[i],PU_CACHE);
702 #ifdef PALETTED_TEXTURE
703   if (g_bPaletteTexture) {
704     p_bRGBTitle1[i]=(unsigned char *)Malloc(256*256);
705     for (x=0;x<256;x++) {
706       for (y=0;y<200;y++) {
707 	p_bRGBTitle1[i][x+y*256]=patch[x+y*320];
708       }
709     }
710     p_bRGBTitle2[i]=(unsigned char *)Malloc(64*256);
711     for (x=256;x<320;x++) {
712       for (y=0;y<200;y++) {
713 	p_bRGBTitle2[i][x-256+y*64]=patch[x+y*320];
714       }
715     }
716   }
717   else
718 #endif
719     {
720       p_bRGBTitle1[i]=(unsigned char *)Malloc(256*256*3);
721       for (x=0;x<256;x++) {
722 	for (y=0;y<200;y++) {
723 	  p_bRGBTitle1[i][3*(x+y*256)]=p_bPalette[3*patch[x+y*320]];
724 	  p_bRGBTitle1[i][3*(x+y*256)+1]=p_bPalette[3*patch[x+y*320]+1];
725 	  p_bRGBTitle1[i][3*(x+y*256)+2]=p_bPalette[3*patch[x+y*320]+2];
726 	}
727       }
728       p_bRGBTitle2[i]=(unsigned char *)Malloc(64*256*3);
729       for (x=256;x<320;x++) {
730 	for (y=0;y<200;y++) {
731 	  p_bRGBTitle2[i][3*(x-256+y*64)]=p_bPalette[3*patch[x+y*320]];
732 	  p_bRGBTitle2[i][3*(x-256+y*64)+1]=p_bPalette[3*patch[x+y*320]+1];
733 	  p_bRGBTitle2[i][3*(x-256+y*64)+2]=p_bPalette[3*patch[x+y*320]+2];
734 	}
735       }
736     }
737 
738   iGlObjTITLE =10000;
739   (*glBindTexture_s) (GL_TEXTURE_2D, iGlObjTITLE+2*i);
740   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
741   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
742   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
743   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
744   (*glTexEnvf_s) (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
745 
746 #ifdef PALETTED_TEXTURE
747   if (g_bPaletteTexture)
748     {
749       (*glColorTableEXT_s) (GL_TEXTURE_2D,GL_RGB8,256,GL_RGB,GL_UNSIGNED_BYTE,p_bPalette);
750       (*glTexImage2D_s) (GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, 256, 256, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, p_bRGBTitle1[i]);
751     }
752   else
753 #endif
754   (*glTexImage2D_s) (GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, p_bRGBTitle1[i]);
755 
756   (*glBindTexture_s) (GL_TEXTURE_2D, iGlObjTITLE+2*i+1);
757   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
758   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
759   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
760   (*glTexParameterf_s) (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
761   (*glTexEnvf_s) (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
762 
763 #ifdef PALETTED_TEXTURE
764   if (g_bPaletteTexture)
765     {
766       (*glColorTableEXT_s) (GL_TEXTURE_2D,GL_RGB8,256,GL_RGB,GL_UNSIGNED_BYTE,p_bPalette);
767       (*glTexImage2D_s) (GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, 64, 256, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, p_bRGBTitle2[i]);
768     }
769   else
770 #endif
771   (*glTexImage2D_s) (GL_TEXTURE_2D, 0, 3, 64, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, p_bRGBTitle2[i]);
772 }
773 
GLRegisterScreens()774 GLvoid GLRegisterScreens() {
775   GLRegisterScreen(0);
776   if (shareware)
777     GLRegisterScreen(1);
778   GLRegisterScreen(2);
779   GLRegisterScreen(3);
780   GLRegisterScreen(4);
781 
782   GL_RegisterPatchScreen(5);
783   if (!shareware)
784     {	GL_RegisterPatchScreen(6);
785     GL_RegisterPatchScreen(7);
786     }
787 }
788 
GL_DrawStatBack(char * name)789 void GL_DrawStatBack(char *name) {
790   int x;
791   int y;
792   int i;
793 
794   byte *src;
795   byte *dest;
796 
797   src = W_CacheLumpName (name, PU_CACHE);
798   dest = screen;
799 
800   for (y=0 ; y<screenheight ; y++) {
801     for (x=0 ; x<screenwidth/64 ; x++) {
802 #ifdef PALETTED_TEXTURE
803       if (g_bPaletteTexture) {
804 	memcpy (dest, src+((y&63)<<6), 64);
805 	dest += 64;
806       }
807       else
808 #endif
809 	for (i=0;i<64;i++) {
810 	  dest[3*(64*x+i+screenwidth*y)]=p_bPalette[3*src[i+((y&63)<<6)]];
811 	  dest[3*(64*x+i+screenwidth*y)+1]=p_bPalette[3*src[i+((y&63)<<6)]+1];
812 	  dest[3*(64*x+i+screenwidth*y)+2]=p_bPalette[3*src[i+((y&63)<<6)]+2];
813 	}
814     }
815     if (screenwidth&63) {
816 #ifdef PALETTED_TEXTURE
817       if (g_bPaletteTexture) {
818 	memcpy (dest, src+((y&63)<<6), screenwidth&63);
819 	dest += (screenwidth&63);
820       }
821       else
822 #endif
823 	for (i=0; i<(screenwidth&63); i++) {
824 	  dest[3*(64*x+i+screenwidth*y)]=p_bPalette[3*src[i+((y&63)<<6)]];
825 	  dest[3*(64*x+i+screenwidth*y)+1]=p_bPalette[3*src[i+((y&63)<<6)]+1];
826 	  dest[3*(64*x+i+screenwidth*y)+2]=p_bPalette[3*src[i+((y&63)<<6)]+2];
827 	}
828     }
829   }
830   GL_DumpScreen();
831 }
832