]> icculus.org git repositories - divverent/darkplaces.git/blob - gl_draw.c
win32 fixes and some MSVC warnings fixed
[divverent/darkplaces.git] / gl_draw.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #include "quakedef.h"
22
23 cvar_t scr_conalpha = {CVAR_SAVE, "scr_conalpha", "1"};
24
25 static rtexture_t *char_texture;
26
27 //=============================================================================
28 /* Support Routines */
29
30 #define MAX_CACHED_PICS 256
31 #define CACHEPICHASHSIZE 256
32 static cachepic_t *cachepichash[CACHEPICHASHSIZE];
33 static cachepic_t cachepics[MAX_CACHED_PICS];
34 static int numcachepics;
35
36 static rtexturepool_t *drawtexturepool;
37
38 static qbyte pointerimage[256] =
39 {
40         "333333332......."
41         "26777761........"
42         "2655541........."
43         "265541.........."
44         "2654561........."
45         "26414561........"
46         "251.14561......."
47         "21...14561......"
48         "1.....141......."
49         ".......1........"
50         "................"
51         "................"
52         "................"
53         "................"
54         "................"
55         "................"
56 };
57
58 static rtexture_t *draw_generatemousepointer(void)
59 {
60         int i;
61         qbyte buffer[256][4];
62         for (i = 0;i < 256;i++)
63         {
64                 if (pointerimage[i] == '.')
65                 {
66                         buffer[i][0] = 0;
67                         buffer[i][1] = 0;
68                         buffer[i][2] = 0;
69                         buffer[i][3] = 0;
70                 }
71                 else
72                 {
73                         buffer[i][0] = (pointerimage[i] - '0') * 16;
74                         buffer[i][1] = (pointerimage[i] - '0') * 16;
75                         buffer[i][2] = (pointerimage[i] - '0') * 16;
76                         buffer[i][3] = 255;
77                 }
78         }
79         return R_LoadTexture(drawtexturepool, "mousepointer", 16, 16, &buffer[0][0], TEXTYPE_RGBA, TEXF_ALPHA | TEXF_PRECACHE);
80 }
81
82 // must match NUMCROSSHAIRS in r_crosshairs.c
83 #define NUMCROSSHAIRS 5
84
85 static qbyte *crosshairtexdata[NUMCROSSHAIRS] =
86 {
87         "................"
88         "................"
89         "................"
90         "...33......33..."
91         "...355....553..."
92         "....577..775...."
93         ".....77..77....."
94         "................"
95         "................"
96         ".....77..77....."
97         "....577..775...."
98         "...355....553..."
99         "...33......33..."
100         "................"
101         "................"
102         "................"
103         ,
104         "................"
105         "................"
106         "................"
107         "...3........3..."
108         "....5......5...."
109         ".....7....7....."
110         "......7..7......"
111         "................"
112         "................"
113         "......7..7......"
114         ".....7....7....."
115         "....5......5...."
116         "...3........3..."
117         "................"
118         "................"
119         "................"
120         ,
121         "................"
122         ".......77......."
123         ".......77......."
124         "................"
125         "................"
126         ".......44......."
127         ".......44......."
128         ".77..44..44..77."
129         ".77..44..44..77."
130         ".......44......."
131         ".......44......."
132         "................"
133         ".......77......."
134         ".......77......."
135         "................"
136         "................"
137         ,
138         "................"
139         "................"
140         "................"
141         "................"
142         "................"
143         "................"
144         "................"
145         "................"
146         "........7777777."
147         "........752....."
148         "........72......"
149         "........7......."
150         "........7......."
151         "........7......."
152         "................"
153         "................"
154         ,
155         "................"
156         "................"
157         "................"
158         "................"
159         "................"
160         "........7......."
161         "................"
162         "........4......."
163         ".....7.4.4.7...."
164         "........4......."
165         "................"
166         "........7......."
167         "................"
168         "................"
169         "................"
170         "................"
171 };
172
173 static rtexture_t *draw_generatecrosshair(int num)
174 {
175         int i;
176         char *in;
177         qbyte data[16*16][4];
178         in = crosshairtexdata[num];
179         for (i = 0;i < 16*16;i++)
180         {
181                 if (in[i] == '.')
182                 {
183                         data[i][0] = 255;
184                         data[i][1] = 255;
185                         data[i][2] = 255;
186                         data[i][3] = 0;
187                 }
188                 else
189                 {
190                         data[i][0] = 255;
191                         data[i][1] = 255;
192                         data[i][2] = 255;
193                         data[i][3] = (qbyte) ((int) (in[i] - '0') * 255 / 7);
194                 }
195         }
196         return R_LoadTexture(drawtexturepool, va("crosshair%i", num), 16, 16, &data[0][0], TEXTYPE_RGBA, TEXF_ALPHA | TEXF_PRECACHE);
197 }
198
199 /*
200 ================
201 Draw_CachePic
202 ================
203 */
204 // FIXME: move this to client somehow
205 cachepic_t      *Draw_CachePic (char *path)
206 {
207         int i, crc, hashkey;
208         cachepic_t *pic;
209         qpic_t *p;
210
211         crc = CRC_Block(path, strlen(path));
212         hashkey = ((crc >> 8) ^ crc) % CACHEPICHASHSIZE;
213         for (pic = cachepichash[hashkey];pic;pic = pic->chain)
214                 if (!strcmp (path, pic->name))
215                         return pic;
216
217         if (numcachepics == MAX_CACHED_PICS)
218                 Sys_Error ("numcachepics == MAX_CACHED_PICS");
219         pic = cachepics + (numcachepics++);
220         strcpy (pic->name, path);
221         // link into list
222         pic->chain = cachepichash[hashkey];
223         cachepichash[hashkey] = pic;
224
225         // load the pic from disk
226         pic->tex = loadtextureimage(drawtexturepool, path, 0, 0, false, false, true);
227         if (pic->tex == NULL && (p = W_GetLumpName (path)))
228         {
229                 if (!strcmp(path, "conchars"))
230                 {
231                         qbyte *pix;
232                         // conchars is a raw image and with the wrong transparent color
233                         pix = (qbyte *)p;
234                         for (i = 0;i < 128 * 128;i++)
235                                 if (pix[i] == 0)
236                                         pix[i] = 255;
237                         pic->tex = R_LoadTexture (drawtexturepool, path, 128, 128, pix, TEXTYPE_QPALETTE, TEXF_ALPHA | TEXF_PRECACHE);
238                 }
239                 else
240                         pic->tex = R_LoadTexture (drawtexturepool, path, p->width, p->height, p->data, TEXTYPE_QPALETTE, TEXF_ALPHA | TEXF_PRECACHE);
241         }
242         if (pic->tex == NULL && !strcmp(path, "ui/mousepointer.tga"))
243                 pic->tex = draw_generatemousepointer();
244         if (pic->tex == NULL && !strcmp(path, "gfx/crosshair1.tga"))
245                 pic->tex = draw_generatecrosshair(0);
246         if (pic->tex == NULL && !strcmp(path, "gfx/crosshair2.tga"))
247                 pic->tex = draw_generatecrosshair(1);
248         if (pic->tex == NULL && !strcmp(path, "gfx/crosshair3.tga"))
249                 pic->tex = draw_generatecrosshair(2);
250         if (pic->tex == NULL && !strcmp(path, "gfx/crosshair4.tga"))
251                 pic->tex = draw_generatecrosshair(3);
252         if (pic->tex == NULL && !strcmp(path, "gfx/crosshair5.tga"))
253                 pic->tex = draw_generatecrosshair(4);
254         if (pic->tex == NULL)
255                 Sys_Error ("Draw_CachePic: failed to load %s", path);
256
257         pic->width = R_TextureWidth(pic->tex);
258         pic->height = R_TextureHeight(pic->tex);
259         return pic;
260 }
261
262 cachepic_t *Draw_NewPic(char *picname, int width, int height, int alpha, qbyte *pixels)
263 {
264         int crc, hashkey;
265         cachepic_t *pic;
266
267         crc = CRC_Block(picname, strlen(picname));
268         hashkey = ((crc >> 8) ^ crc) % CACHEPICHASHSIZE;
269         for (pic = cachepichash[hashkey];pic;pic = pic->chain)
270                 if (!strcmp (picname, pic->name))
271                         break;
272
273         if (pic)
274         {
275                 if (pic->tex && R_TextureWidth(pic->tex) == width && R_TextureHeight(pic->tex) == height && (R_TextureHasAlpha(pic->tex) != 0) == (alpha != 0))
276                 {
277                         R_UpdateTexture(pic->tex, pixels);
278                         return pic;
279                 }
280         }
281         else
282         {
283                 if (pic == NULL)
284                 {
285                         if (numcachepics == MAX_CACHED_PICS)
286                                 Sys_Error ("numcachepics == MAX_CACHED_PICS");
287                         pic = cachepics + (numcachepics++);
288                         strcpy (pic->name, picname);
289                         // link into list
290                         pic->chain = cachepichash[hashkey];
291                         cachepichash[hashkey] = pic;
292                 }
293         }
294
295         pic->width = width;
296         pic->height = height;
297         if (pic->tex)
298                 R_FreeTexture(pic->tex);
299         pic->tex = R_LoadTexture (drawtexturepool, picname, width, height, pixels, TEXTYPE_RGBA, alpha ? TEXF_ALPHA : 0);
300         return pic;
301 }
302
303 void Draw_FreePic(char *picname)
304 {
305         int crc;
306         int hashkey;
307         cachepic_t *pic;
308         // this doesn't really free the pic, but does free it's texture
309         crc = CRC_Block(picname, strlen(picname));
310         hashkey = ((crc >> 8) ^ crc) % CACHEPICHASHSIZE;
311         for (pic = cachepichash[hashkey];pic;pic = pic->chain)
312         {
313                 if (!strcmp (picname, pic->name))
314                 {
315                         R_FreeTexture(pic->tex);
316                         pic->width = 0;
317                         pic->height = 0;
318                         return;
319                 }
320         }
321 }
322
323 /*
324 ===============
325 Draw_Init
326 ===============
327 */
328 static void gl_draw_start(void)
329 {
330         drawtexturepool = R_AllocTexturePool();
331
332         numcachepics = 0;
333         memset(cachepichash, 0, sizeof(cachepichash));
334
335         char_texture = Draw_CachePic("conchars")->tex;
336 }
337
338 static void gl_draw_shutdown(void)
339 {
340         R_FreeTexturePool(&drawtexturepool);
341
342         numcachepics = 0;
343         memset(cachepichash, 0, sizeof(cachepichash));
344 }
345
346 static void gl_draw_newmap(void)
347 {
348 }
349
350 void GL_Draw_Init (void)
351 {
352         Cvar_RegisterVariable (&scr_conalpha);
353
354         numcachepics = 0;
355         memset(cachepichash, 0, sizeof(cachepichash));
356
357         R_RegisterModule("GL_Draw", gl_draw_start, gl_draw_shutdown, gl_draw_newmap);
358 }
359
360 extern cvar_t gl_mesh_drawmode;
361 void R_DrawQueue(void)
362 {
363         int pos, num, chartexnum, overbright;
364         float x, y, w, h, s, t, u, v;
365         cachepic_t *pic;
366         drawqueue_t *dq;
367         char *str, *currentpic;
368         int batch, batchcount, additive;
369         unsigned int color;
370         drawqueuemesh_t *mesh;
371
372         if (!r_render.integer)
373                 return;
374
375         qglViewport(vid.realx, vid.realy, vid.realwidth, vid.realheight);
376
377         qglMatrixMode(GL_PROJECTION);
378     qglLoadIdentity();
379         qglOrtho(0, vid.conwidth, vid.conheight, 0, -99999, 99999);
380
381         qglMatrixMode(GL_MODELVIEW);
382     qglLoadIdentity();
383
384         qglDisable(GL_DEPTH_TEST);
385         qglDisable(GL_CULL_FACE);
386         qglEnable(GL_BLEND);
387         qglEnable(GL_TEXTURE_2D);
388         qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
389
390         chartexnum = R_GetTexture(char_texture);
391
392         additive = false;
393         qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
394         currentpic = "";
395         pic = NULL;
396         qglBindTexture(GL_TEXTURE_2D, 0);
397         color = 0;
398         qglColor4ub(0,0,0,0);
399
400         overbright = v_overbrightbits.integer;
401         batch = false;
402         batchcount = 0;
403         for (pos = 0;pos < r_refdef.drawqueuesize;pos += ((drawqueue_t *)(r_refdef.drawqueue + pos))->size)
404         {
405                 dq = (drawqueue_t *)(r_refdef.drawqueue + pos);
406                 if (dq->flags & DRAWFLAG_ADDITIVE)
407                 {
408                         if (!additive)
409                         {
410                                 if (batch)
411                                 {
412                                         batch = false;
413                                         qglEnd();
414                                 }
415                                 additive = true;
416                                 qglBlendFunc(GL_SRC_ALPHA, GL_ONE);
417                         }
418                 }
419                 else
420                 {
421                         if (additive)
422                         {
423                                 if (batch)
424                                 {
425                                         batch = false;
426                                         qglEnd();
427                                 }
428                                 additive = false;
429                                 qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
430                         }
431                 }
432                 if (color != dq->color)
433                 {
434                         color = dq->color;
435                         qglColor4ub((qbyte)(((color >> 24) & 0xFF) >> overbright), (qbyte)(((color >> 16) & 0xFF) >> overbright), (qbyte)(((color >> 8) & 0xFF) >> overbright), (qbyte)(color & 0xFF));
436                 }
437                 if (batch && batchcount > 128)
438                 {
439                         batch = false;
440                         qglEnd();
441                 }
442                 x = dq->x;
443                 y = dq->y;
444                 w = dq->scalex;
445                 h = dq->scaley;
446                 switch(dq->command)
447                 {
448                 case DRAWQUEUE_PIC:
449                         str = (char *)(dq + 1);
450                         if (*str)
451                         {
452                                 if (strcmp(str, currentpic))
453                                 {
454                                         if (batch)
455                                         {
456                                                 batch = false;
457                                                 qglEnd();
458                                         }
459                                         currentpic = str;
460                                         pic = Draw_CachePic(str);
461                                         qglBindTexture(GL_TEXTURE_2D, R_GetTexture(pic->tex));
462                                 }
463                                 if (w == 0)
464                                         w = pic->width;
465                                 if (h == 0)
466                                         h = pic->height;
467                                 if (!batch)
468                                 {
469                                         batch = true;
470                                         qglBegin(GL_TRIANGLES);
471                                         batchcount = 0;
472                                 }
473                                 qglTexCoord2f (0, 0);qglVertex2f (x  , y  );
474                                 qglTexCoord2f (1, 0);qglVertex2f (x+w, y  );
475                                 qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
476                                 qglTexCoord2f (0, 0);qglVertex2f (x  , y  );
477                                 qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
478                                 qglTexCoord2f (0, 1);qglVertex2f (x  , y+h);
479                                 batchcount++;
480                         }
481                         else
482                         {
483                                 if (currentpic[0])
484                                 {
485                                         if (batch)
486                                         {
487                                                 batch = false;
488                                                 qglEnd();
489                                         }
490                                         currentpic = "";
491                                         qglBindTexture(GL_TEXTURE_2D, 0);
492                                 }
493                                 if (!batch)
494                                 {
495                                         batch = true;
496                                         qglBegin(GL_TRIANGLES);
497                                         batchcount = 0;
498                                 }
499                                 qglTexCoord2f (0, 0);qglVertex2f (x  , y  );
500                                 qglTexCoord2f (1, 0);qglVertex2f (x+w, y  );
501                                 qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
502                                 qglTexCoord2f (0, 0);qglVertex2f (x  , y  );
503                                 qglTexCoord2f (1, 1);qglVertex2f (x+w, y+h);
504                                 qglTexCoord2f (0, 1);qglVertex2f (x  , y+h);
505                                 batchcount++;
506                         }
507                         break;
508                 case DRAWQUEUE_STRING:
509                         str = (char *)(dq + 1);
510                         if (strcmp("conchars", currentpic))
511                         {
512                                 if (batch)
513                                 {
514                                         batch = false;
515                                         qglEnd();
516                                 }
517                                 currentpic = "conchars";
518                                 qglBindTexture(GL_TEXTURE_2D, chartexnum);
519                         }
520                         if (!batch)
521                         {
522                                 batch = true;
523                                 qglBegin(GL_TRIANGLES);
524                                 batchcount = 0;
525                         }
526                         while ((num = *str++) && x < vid.conwidth)
527                         {
528                                 if (num != ' ')
529                                 {
530                                         s = (num & 15)*0.0625f + (0.5f / 256.0f);
531                                         t = (num >> 4)*0.0625f + (0.5f / 256.0f);
532                                         u = 0.0625f - (1.0f / 256.0f);
533                                         v = 0.0625f - (1.0f / 256.0f);
534                                         qglTexCoord2f (s  , t  );qglVertex2f (x  , y  );
535                                         qglTexCoord2f (s+u, t  );qglVertex2f (x+w, y  );
536                                         qglTexCoord2f (s+u, t+v);qglVertex2f (x+w, y+h);
537                                         qglTexCoord2f (s  , t  );qglVertex2f (x  , y  );
538                                         qglTexCoord2f (s+u, t+v);qglVertex2f (x+w, y+h);
539                                         qglTexCoord2f (s  , t+v);qglVertex2f (x  , y+h);
540                                         batchcount++;
541                                 }
542                                 x += w;
543                         }
544                         break;
545                 case DRAWQUEUE_MESH:
546                         if (batch)
547                         {
548                                 batch = false;
549                                 qglEnd();
550                         }
551                         mesh = (void *)(dq + 1);
552                         qglBindTexture(GL_TEXTURE_2D, R_GetTexture(mesh->texture));
553                         if (gl_mesh_drawmode.integer > 0)
554                         {
555                                 qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), mesh->vertices);CHECKGLERROR
556                                 qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), mesh->texcoords);CHECKGLERROR
557                                 qglColorPointer(4, GL_UNSIGNED_BYTE, sizeof(qbyte[4]), mesh->colors);CHECKGLERROR
558                                 qglEnableClientState(GL_VERTEX_ARRAY);CHECKGLERROR
559                                 qglEnableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
560                                 qglEnableClientState(GL_COLOR_ARRAY);CHECKGLERROR
561                         }
562                         if (gl_mesh_drawmode.integer == 3 && qglDrawRangeElements == NULL)
563                                 Cvar_SetValueQuick(&gl_mesh_drawmode, 2);
564
565                         if (gl_mesh_drawmode.integer == 3)
566                         {
567                                 // GL 1.2 or GL 1.1 with extension
568                                 qglDrawRangeElements(GL_TRIANGLES, 0, mesh->numvertices, mesh->numindices, GL_UNSIGNED_INT, mesh->indices);
569                                 CHECKGLERROR
570                         }
571                         else if (gl_mesh_drawmode.integer == 2)
572                         {
573                                 // GL 1.1
574                                 qglDrawElements(GL_TRIANGLES, mesh->numindices, GL_UNSIGNED_INT, mesh->indices);
575                                 CHECKGLERROR
576                         }
577                         else if (gl_mesh_drawmode.integer == 1)
578                         {
579                                 int i;
580                                 // GL 1.1
581                                 // feed it manually using glArrayElement
582                                 qglBegin(GL_TRIANGLES);
583                                 for (i = 0;i < mesh->numindices;i++)
584                                         qglArrayElement(mesh->indices[i]);
585                                 qglEnd();
586                                 CHECKGLERROR
587                         }
588                         else
589                         {
590                                 int i, in;
591                                 // GL 1.1 but not using vertex arrays - 3dfx glquake minigl driver
592                                 // feed it manually
593                                 if (gl_mesh_drawmode.integer != 0)
594                                         Cvar_SetValueQuick(&gl_mesh_drawmode, 0);
595                                 qglBegin(GL_TRIANGLES);
596                                 for (i = 0;i < mesh->numindices;i++)
597                                 {
598                                         in = mesh->indices[i];
599                                         qglColor4ub(mesh->colors[in * 4], mesh->colors[in * 4 + 1], mesh->colors[in * 4 + 2], mesh->colors[in * 4 + 3]);
600                                         qglTexCoord2f(mesh->texcoords[in * 2], mesh->texcoords[in * 2 + 1]);
601                                         qglVertex3f(mesh->vertices[in * 3], mesh->vertices[in * 3 + 1], mesh->vertices[in * 3 + 2]);
602                                 }
603                                 qglEnd();
604                                 CHECKGLERROR
605                         }
606                         if (gl_mesh_drawmode.integer > 0)
607                         {
608                                 qglDisableClientState(GL_VERTEX_ARRAY);CHECKGLERROR
609                                 qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
610                                 qglDisableClientState(GL_COLOR_ARRAY);CHECKGLERROR
611                         }
612                         // restore color, since it got trashed by using color array
613                         qglColor4ub((qbyte)(((color >> 24) & 0xFF) >> overbright), (qbyte)(((color >> 16) & 0xFF) >> overbright), (qbyte)(((color >> 8) & 0xFF) >> overbright), (qbyte)(color & 0xFF));
614                         CHECKGLERROR
615                         currentpic = "\0";
616                         break;
617                 }
618         }
619         if (batch)
620                 qglEnd();
621         CHECKGLERROR
622
623         if (!v_hwgamma.integer)
624         {
625                 qglDisable(GL_TEXTURE_2D);
626                 CHECKGLERROR
627                 t = v_contrast.value * (float) (1 << v_overbrightbits.integer);
628                 if (t >= 1.01f)
629                 {
630                         qglBlendFunc (GL_DST_COLOR, GL_ONE);
631                         CHECKGLERROR
632                         qglBegin (GL_TRIANGLES);
633                         while (t >= 1.01f)
634                         {
635                                 num = (int) ((t - 1.0f) * 255.0f);
636                                 if (num > 255)
637                                         num = 255;
638                                 qglColor4ub ((qbyte) num, (qbyte) num, (qbyte) num, 255);
639                                 qglVertex2f (-5000, -5000);
640                                 qglVertex2f (10000, -5000);
641                                 qglVertex2f (-5000, 10000);
642                                 t *= 0.5;
643                         }
644                         qglEnd ();
645                         CHECKGLERROR
646                 }
647                 else if (t <= 0.99f)
648                 {
649                         qglBlendFunc(GL_ZERO, GL_SRC_COLOR);
650                         CHECKGLERROR
651                         qglBegin(GL_TRIANGLES);
652                         num = (int) (t * 255.0f);
653                         qglColor4ub ((qbyte) num, (qbyte) num, (qbyte) num, 255);
654                         qglVertex2f (-5000, -5000);
655                         qglVertex2f (10000, -5000);
656                         qglVertex2f (-5000, 10000);
657                         qglEnd();
658                         CHECKGLERROR
659                 }
660                 if (v_brightness.value >= 0.01f)
661                 {
662                         qglBlendFunc (GL_ONE, GL_ONE);
663                         CHECKGLERROR
664                         num = (int) (v_brightness.value * 255.0f);
665                         qglColor4ub ((qbyte) num, (qbyte) num, (qbyte) num, 255);
666                         CHECKGLERROR
667                         qglBegin (GL_TRIANGLES);
668                         qglVertex2f (-5000, -5000);
669                         qglVertex2f (10000, -5000);
670                         qglVertex2f (-5000, 10000);
671                         qglEnd ();
672                         CHECKGLERROR
673                 }
674                 qglEnable(GL_TEXTURE_2D);
675                 CHECKGLERROR
676         }
677
678         qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
679         CHECKGLERROR
680         qglEnable (GL_CULL_FACE);
681         CHECKGLERROR
682         qglEnable (GL_DEPTH_TEST);
683         CHECKGLERROR
684         qglDisable (GL_BLEND);
685         CHECKGLERROR
686         qglColor4ub (255, 255, 255, 255);
687         CHECKGLERROR
688 }
689