]> icculus.org git repositories - btb/d2x.git/blob - video/ogl_gr.c
Partial application of linux/alpha patch. Courtesy of Falk Hueffner <falk.hueffner...
[btb/d2x.git] / video / ogl_gr.c
1 /*
2  * $Source: /cvs/cvsroot/d2x/video/ogl_gr.c,v $
3  * $Revision: 1.6 $
4  * $Author: bradleyb $
5  * $Date: 2001-10-18 23:59:23 $
6  *
7  * // OGL video functions. - Added 9/15/99 Matthew Mueller
8  *
9  * $Log: not supported by cvs2svn $
10  * Revision 1.5  2001/10/12 00:18:40  bradleyb
11  * Switched from Cygwin to mingw32 on MS boxes.  Vastly improved compilability.
12  *
13  * Revision 1.4  2001/01/29 13:47:52  bradleyb
14  * Fixed build, some minor cleanups.
15  *
16  */
17
18 #ifdef HAVE_CONFIG_H
19 #include <conf.h>
20 #endif
21
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #ifdef __WINDOWS__
26 #include <windows.h>
27 #endif
28
29 //#include <GL/gl.h>
30 #include <unistd.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <fcntl.h>
34 #include <errno.h>
35
36 #include "game.h"
37 #include "text.h"
38 #include "gr.h"
39 #include "gamefont.h"
40 #include "grdef.h"
41 #include "palette.h"
42 #include "u_mem.h"
43 #include "error.h"
44
45 #include "inferno.h"
46 #include "screens.h"
47
48 #include "strutil.h"
49 #include "mono.h"
50 #include "args.h"
51 #include "key.h"
52
53 #include "gamefont.h"
54
55 #define DECLARE_VARS
56 #include "ogl_init.h"
57 #include <GL/glu.h>
58
59 int ogl_voodoohack=0;
60
61 int gr_installed = 0;
62
63
64 void gr_palette_clear(); // Function prototype for gr_init;
65 int gl_initialized=0;
66 int gl_reticle=1;
67
68 int ogl_fullscreen=0;
69 int gr_check_fullscreen(void){
70         return ogl_fullscreen;
71 }
72 void gr_do_fullscreen(int f){
73         if (ogl_voodoohack)
74                 ogl_fullscreen=1;//force fullscreen mode on voodoos.
75         else
76                 ogl_fullscreen=f;
77         if (gl_initialized){
78                 ogl_do_fullscreen_internal();
79         }
80 }
81 int gr_toggle_fullscreen(void){
82         gr_do_fullscreen(!ogl_fullscreen);
83         //      grd_curscreen->sc_mode=0;//hack to get it to reset screen mode
84         return ogl_fullscreen;
85 }
86
87
88 void ogl_init_state(void){
89         /* select clearing (background) color   */
90         glClearColor(0.0, 0.0, 0.0, 0.0);
91         glShadeModel(GL_SMOOTH);
92
93         /* initialize viewing values */
94         glMatrixMode(GL_PROJECTION);
95         glLoadIdentity();
96         glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
97         glScalef(1.0, -1.0, 1.0);
98         glTranslatef(0.0, -1.0, 0.0);
99         gr_palette_step_up(0,0,0);//in case its left over from in game
100 }
101
102 int last_screen_mode=-1;
103 void ogl_set_screen_mode(void){
104         if (last_screen_mode==Screen_mode)
105                 return;
106         OGL_VIEWPORT(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h);
107 //      OGL_VIEWPORT(grd_curcanv->cv_bitmap.bm_x,grd_curcanv->cv_bitmap.bm_y,grd_curcanv->cv_bitmap.bm_w,grd_curcanv->cv_bitmap.bm_h);
108         if (Screen_mode==SCREEN_GAME){
109                 glDrawBuffer(GL_BACK);
110         }else{
111                 glClearColor(0.0, 0.0, 0.0, 0.0);
112                 glDrawBuffer(GL_FRONT);
113                 glClear(GL_COLOR_BUFFER_BIT);
114                 glMatrixMode(GL_PROJECTION);
115                 glLoadIdentity();//clear matrix
116                 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
117                 glMatrixMode(GL_MODELVIEW);
118                 glLoadIdentity();//clear matrix
119                 glEnable(GL_BLEND);
120                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
121         }
122         last_screen_mode=Screen_mode;
123 }
124 void gr_update()
125 {
126         if (gl_initialized){
127
128                 if(Screen_mode != SCREEN_GAME){
129                         glFlush();
130                 }
131         }
132 }
133
134 const char *gl_vendor,*gl_renderer,*gl_version,*gl_extensions;
135 void ogl_get_verinfo(void){
136         int t;
137         gl_vendor=glGetString(GL_VENDOR);
138         gl_renderer=glGetString(GL_RENDERER);
139         gl_version=glGetString(GL_VERSION);
140         gl_extensions=glGetString(GL_EXTENSIONS);
141         
142         printf("gl vendor:%s renderer:%s version:%s extensions:%s\n",gl_vendor,gl_renderer,gl_version,gl_extensions);
143
144         ogl_intensity4_ok=1;ogl_luminance4_alpha4_ok=1;ogl_rgba2_ok=1;
145         
146         //add driver specific hacks here.  whee.
147         if (stricmp(gl_renderer,"Mesa NVIDIA RIVA 1.0\n")==0 && stricmp(gl_version,"1.2 Mesa 3.0")==0){
148                 ogl_intensity4_ok=0;//ignores alpha, always black background instead of transparent.
149                 ogl_readpixels_ok=0;//either just returns all black, or kills the X server entirely
150         }
151
152         //allow overriding of stuff.
153         if ((t=FindArg("-gl_intensity4_ok"))){
154                 ogl_intensity4_ok=atoi(Args[t+1]);
155         }
156         if ((t=FindArg("-gl_luminance4_alpha4_ok"))){
157                 ogl_luminance4_alpha4_ok=atoi(Args[t+1]);
158         }
159         if ((t=FindArg("-gl_rgba2_ok"))){
160                 ogl_rgba2_ok=atoi(Args[t+1]);
161         }
162         if ((t=FindArg("-gl_readpixels_ok"))){
163                 ogl_readpixels_ok=atoi(Args[t+1]);
164         }
165
166         printf("gl_intensity4:%i gl_luminance4_alpha4:%i gl_rgba2:%i gl_readpixels:%i\n",ogl_intensity4_ok,ogl_luminance4_alpha4_ok,ogl_rgba2_ok,ogl_readpixels_ok);
167 }
168
169 int gr_set_mode(u_int32_t mode)
170 {
171         unsigned int w,h;
172
173 #ifdef NOGRAPH
174 return 0;
175 #endif
176 //      mode=0;
177         if (mode<=0)
178                 return 0;
179
180         w=SM_W(mode);
181         h=SM_H(mode);
182
183         //if (screen != NULL) gr_palette_clear();
184
185 //      ogl_init_state();
186         
187         memset( grd_curscreen, 0, sizeof(grs_screen));
188         grd_curscreen->sc_mode = mode;
189         grd_curscreen->sc_w = w;
190         grd_curscreen->sc_h = h;
191         grd_curscreen->sc_aspect = fixdiv(grd_curscreen->sc_w*3,grd_curscreen->sc_h*4);
192         grd_curscreen->sc_canvas.cv_bitmap.bm_x = 0;
193         grd_curscreen->sc_canvas.cv_bitmap.bm_y = 0;
194         grd_curscreen->sc_canvas.cv_bitmap.bm_w = w;
195         grd_curscreen->sc_canvas.cv_bitmap.bm_h = h;
196         //grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = screen->pitch;
197         grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = w;
198         grd_curscreen->sc_canvas.cv_bitmap.bm_type = BM_OGL;
199         //grd_curscreen->sc_canvas.cv_bitmap.bm_data = (unsigned char *)screen->pixels;
200         grd_curscreen->sc_canvas.cv_bitmap.bm_data = realloc(grd_curscreen->sc_canvas.cv_bitmap.bm_data,w*h);
201         gr_set_current_canvas(NULL);
202         //gr_enable_default_palette_loading();
203         
204         ogl_init_window(w,h);//platform specific code
205
206         ogl_get_verinfo();
207
208         OGL_VIEWPORT(0,0,w,h);
209
210         ogl_set_screen_mode();
211
212         //gamefont_choose_game_font(w,h);
213         
214         return 0;
215 }
216
217 #define GLstrcmptestr(a,b) if (stricmp(a,#b)==0 || stricmp(a,"GL_" #b)==0)return GL_ ## b;
218 int ogl_atotexfilti(char *a,int min){
219         GLstrcmptestr(a,NEAREST);
220         GLstrcmptestr(a,LINEAR);
221         if (min){//mipmaps are valid only for the min filter
222                 GLstrcmptestr(a,NEAREST_MIPMAP_NEAREST);
223                 GLstrcmptestr(a,NEAREST_MIPMAP_LINEAR);
224                 GLstrcmptestr(a,LINEAR_MIPMAP_NEAREST);
225                 GLstrcmptestr(a,LINEAR_MIPMAP_LINEAR);
226         }
227         Error("unknown/invalid texture filter %s\n",a);
228 //      return GL_NEAREST;
229 }
230 int ogl_testneedmipmaps(int i){
231         switch (i){
232                 case GL_NEAREST:
233                 case GL_LINEAR:
234                         return 0;
235                 case GL_NEAREST_MIPMAP_NEAREST:
236                 case GL_NEAREST_MIPMAP_LINEAR:
237                 case GL_LINEAR_MIPMAP_NEAREST:
238                 case GL_LINEAR_MIPMAP_LINEAR:
239                         return 1;
240         }
241         Error("unknown texture filter %x\n",i);
242 //      return -1;
243 }
244 #ifdef OGL_RUNTIME_LOAD
245 #if defined(__WINDOWS__) || defined(__MINGW32__)
246 char *OglLibPath="opengl32.dll";
247 #else
248 char *OglLibPath="libGL.so";
249 #endif
250
251 int ogl_rt_loaded=0;
252 int ogl_init_load_library(void)
253 {
254         int retcode=0;
255         if (!ogl_rt_loaded){
256                 int t;
257                 if ((t=FindArg("-gl_library")))
258                         OglLibPath=Args[t+1];
259
260                 retcode = OpenGL_LoadLibrary(true);
261                 if(retcode)
262                 {
263                         mprintf((0,"Opengl loaded ok\n"));
264         
265                         if(!glEnd)
266                         {
267                                 Error("Opengl: Functions not imported\n");
268                         }
269                 }else{
270                         Error("Opengl: error loading %s\n",OglLibPath);
271                 }
272                 ogl_rt_loaded=1;
273         }
274         return retcode;
275 }
276 #endif
277
278 int gr_init()
279 {
280  int mode = SM(640,480);
281  int retcode,t,glt=0;
282         // Only do this function once!
283         if (gr_installed==1)
284                 return -1;
285
286
287 #ifdef OGL_RUNTIME_LOAD
288         ogl_init_load_library();
289 #endif
290
291 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
292         if (FindArg("-gl_voodoo")){
293                 ogl_voodoohack=1;
294                 gr_toggle_fullscreen();
295         }
296         if (FindArg("-fullscreen"))
297                 gr_toggle_fullscreen();
298 #endif
299         if ((glt=FindArg("-gl_alttexmerge")))
300                 ogl_alttexmerge=1;
301         if ((t=FindArg("-gl_stdtexmerge")))
302                 if (t>=glt)//allow overriding of earlier args
303                         ogl_alttexmerge=0;
304                         
305         if ((glt=FindArg("-gl_16bittextures")))
306                 ogl_rgba_format=GL_RGB5_A1;
307
308         if ((glt=FindArg("-gl_mipmap"))){
309                 GL_texmagfilt=GL_LINEAR;
310                 GL_texminfilt=GL_LINEAR_MIPMAP_NEAREST;
311         }
312         if ((t=FindArg("-gl_simple"))){
313                 if (t>=glt){//allow overriding of earlier args
314                         glt=t;
315                         GL_texmagfilt=GL_NEAREST;
316                         GL_texminfilt=GL_NEAREST;
317                 }
318         }
319         if ((t=FindArg("-gl_texmagfilt")) || (t=FindArg("-gl_texmagfilter"))){
320                 if (t>=glt)//allow overriding of earlier args
321                         GL_texmagfilt=ogl_atotexfilti(Args[t+1],0);
322         }
323         if ((t=FindArg("-gl_texminfilt")) || (t=FindArg("-gl_texminfilter"))){
324                 if (t>=glt)//allow overriding of earlier args
325                         GL_texminfilt=ogl_atotexfilti(Args[t+1],1);
326         }
327         GL_needmipmaps=ogl_testneedmipmaps(GL_texminfilt);
328         mprintf((0,"gr_init: texmagfilt:%x texminfilt:%x needmipmaps=%i\n",GL_texmagfilt,GL_texminfilt,GL_needmipmaps));
329         
330         if ((t=FindArg("-gl_vidmem"))){
331                 ogl_mem_target=atoi(Args[t+1])*1024*1024;
332         }
333         if ((t=FindArg("-gl_reticle"))){
334                 gl_reticle=atoi(Args[t+1]);
335         }
336         //printf("ogl_mem_target=%i\n",ogl_mem_target);
337         
338         ogl_init();//platform specific initialization
339
340         ogl_init_texture_list_internal();
341                 
342         MALLOC( grd_curscreen,grs_screen,1 );
343         memset( grd_curscreen, 0, sizeof(grs_screen));
344         grd_curscreen->sc_canvas.cv_bitmap.bm_data = NULL;
345
346         // Set the mode.
347         if ((retcode=gr_set_mode(mode)))
348         {
349                 return retcode;
350         }
351         grd_curscreen->sc_canvas.cv_color = 0;
352         grd_curscreen->sc_canvas.cv_drawmode = 0;
353         grd_curscreen->sc_canvas.cv_font = NULL;
354         grd_curscreen->sc_canvas.cv_font_fg_color = 0;
355         grd_curscreen->sc_canvas.cv_font_bg_color = 0;
356         gr_set_current_canvas( &grd_curscreen->sc_canvas );
357
358         gr_installed = 1;
359         
360         atexit(gr_close);
361
362         return 0;
363 }
364
365 void gr_close()
366 {
367 //      mprintf((0,"ogl init: %s %s %s - %s\n",glGetString(GL_VENDOR),glGetString(GL_RENDERER),glGetString(GL_VERSION),glGetString,(GL_EXTENSIONS)));
368
369         ogl_close();//platform specific code
370         if (grd_curscreen){
371                 if (grd_curscreen->sc_canvas.cv_bitmap.bm_data)
372                         d_free(grd_curscreen->sc_canvas.cv_bitmap.bm_data);
373                 d_free(grd_curscreen);
374         }
375 #ifdef OGL_RUNTIME_LOAD
376         if (ogl_rt_loaded)
377                 OpenGL_LoadLibrary(false);
378 #endif
379 }
380 extern int r_upixelc;
381 void ogl_upixelc(int x, int y, int c){
382         r_upixelc++;
383 //      printf("gr_upixelc(%i,%i,%i)%i\n",x,y,c,Function_mode==FMODE_GAME);
384 //      if(Function_mode != FMODE_GAME){
385 //              grd_curcanv->cv_bitmap.bm_data[y*grd_curscreen->sc_canvas.cv_bitmap.bm_w+x]=c;
386 //      }else{
387                 OGL_DISABLE(TEXTURE_2D);
388                 glPointSize(1.0);
389                 glBegin(GL_POINTS);
390 //              glBegin(GL_LINES);
391 //      ogl_pal=gr_current_pal;
392                 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
393 //      ogl_pal=gr_palette;
394                 glVertex2f((x+grd_curcanv->cv_bitmap.bm_x)/(float)last_width,1.0-(y+grd_curcanv->cv_bitmap.bm_y)/(float)last_height);
395 //              glVertex2f(x/((float)last_width+1),1.0-y/((float)last_height+1));
396                 glEnd();
397 //      }
398 }
399 void ogl_urect(int left,int top,int right,int bot){
400         GLfloat xo,yo,xf,yf;
401         int c=COLOR;
402         
403         xo=(left+grd_curcanv->cv_bitmap.bm_x)/(float)last_width;
404         xf=(right+grd_curcanv->cv_bitmap.bm_x)/(float)last_width;
405         yo=1.0-(top+grd_curcanv->cv_bitmap.bm_y)/(float)last_height;
406         yf=1.0-(bot+grd_curcanv->cv_bitmap.bm_y)/(float)last_height;
407         
408         OGL_DISABLE(TEXTURE_2D);
409         glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
410         glBegin(GL_QUADS);
411         glVertex2f(xo,yo);
412         glVertex2f(xo,yf);
413         glVertex2f(xf,yf);
414         glVertex2f(xf,yo);
415         glEnd();
416 }
417 void ogl_ulinec(int left,int top,int right,int bot,int c){
418         GLfloat xo,yo,xf,yf;
419         
420         xo=(left+grd_curcanv->cv_bitmap.bm_x)/(float)last_width;
421         xf=(right+grd_curcanv->cv_bitmap.bm_x)/(float)last_width;
422         yo=1.0-(top+grd_curcanv->cv_bitmap.bm_y)/(float)last_height;
423         yf=1.0-(bot+grd_curcanv->cv_bitmap.bm_y)/(float)last_height;
424         
425         OGL_DISABLE(TEXTURE_2D);
426         glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
427         glBegin(GL_LINES);
428         glVertex2f(xo,yo);
429         glVertex2f(xf,yf);
430         glEnd();
431 }
432         
433
434 GLfloat last_r=0, last_g=0, last_b=0;
435 int do_pal_step=0;
436 void ogl_do_palfx(void){
437 //      GLfloat r,g,b,a;
438         OGL_DISABLE(TEXTURE_2D);
439         if (gr_palette_faded_out){
440 /*              glEnable(GL_BLEND);
441                 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
442                 glColor3f(0,0,0);
443 //              r=g=b=0.0;a=1.0;
444         }else{
445                 if (do_pal_step){
446                         //glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
447                         glEnable(GL_BLEND);
448                         glBlendFunc(GL_ONE,GL_ONE);
449                         glColor3f(last_r,last_g,last_b);
450 //                      r=f2fl(last_r);g=f2fl(last_g);b=f2fl(last_b);a=0.5;
451                 }else
452                         return;
453         }
454         
455         
456         glBegin(GL_QUADS);
457         glVertex2f(0,0);
458         glVertex2f(0,1);
459         glVertex2f(1,1);
460         glVertex2f(1,0);
461         glEnd();
462         
463         glEnable(GL_BLEND);     
464         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
465 }
466
467 void gr_palette_clear()
468 {
469         gr_palette_faded_out=1;
470 }
471
472
473 void gr_palette_step_up( int r, int g, int b )
474 {
475         if (gr_palette_faded_out) return;
476
477 //      if ( (r==last_r) && (g==last_g) && (b==last_b) ) return;
478
479 /*      last_r = r/63.0;
480         last_g = g/63.0;
481         last_b = b/63.0;
482         do_pal_step=(r || g || b);*/
483         
484         last_r = (r+gr_palette_gamma)/63.0;
485         last_g = (g+gr_palette_gamma)/63.0;
486         last_b = (b+gr_palette_gamma)/63.0;
487
488         do_pal_step=(r || g || b || gr_palette_gamma);
489         
490 }
491
492 //added on 980913 by adb to fix palette problems
493 // need a min without side effects...
494 #undef min
495 static inline int min(int x, int y) { return x < y ? x : y; }
496 //end changes by adb
497
498 void gr_palette_load( ubyte *pal )      
499 {
500  int i;//, j;
501
502  for (i=0; i<768; i++ ) {
503      gr_current_pal[i] = pal[i];
504      if (gr_current_pal[i] > 63) gr_current_pal[i] = 63;
505  }
506  //palette = screen->format->palette;
507
508  gr_palette_faded_out=0;
509
510  init_computed_colors();
511 }
512
513
514
515 int gr_palette_fade_out(ubyte *pal, int nsteps, int allow_keys)
516 {
517         gr_palette_faded_out=1;
518         return 0;
519 }
520
521
522
523 int gr_palette_fade_in(ubyte *pal, int nsteps, int allow_keys)
524 {
525         gr_palette_faded_out=0;
526         return 0;
527 }
528
529
530
531 void gr_palette_read(ubyte * pal)
532 {
533         int i;
534         for (i=0; i<768; i++ ) {
535                 pal[i]=gr_current_pal[i];
536                 if (pal[i] > 63) pal[i] = 63;
537         }
538 }
539
540 //writes out an uncompressed RGB .tga file
541 //if we got really spiffy, we could optionally link in libpng or something, and use that.
542 void write_bmp(char *savename,int w,int h,unsigned char *buf){
543         int f;
544 #if defined(__WINDOWS__) || defined (__MINGW32__)
545         f=open(savename,O_CREAT|O_EXCL|O_WRONLY,S_IRUSR|S_IWUSR);
546 #else
547         f=open(savename,O_CREAT|O_EXCL|O_WRONLY,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
548 #endif
549         if (f>=0){
550                 GLubyte    targaMagic[12] = { 0, //no identification field
551                          0,//no colormap
552                          2,//RGB image (well, BGR, actually)
553                          0, 0, 0, 0, 0, 0, 0, 0, 0 };//no colormap or image origin stuff.
554                 GLubyte blah;
555                 int r;
556                 GLubyte *s;
557                 int x,y;
558                 
559                 //write .TGA header.
560                 write (f,targaMagic,sizeof(targaMagic));
561                 blah=w%256;write (f,&blah,1);//w, low
562                 blah=w/256;write (f,&blah,1);//w, high
563                 blah=h%256;write (f,&blah,1);//h, low
564                 blah=h/256;write (f,&blah,1);//h, high
565                 blah=24;write (f,&blah,1);//24 bpp
566                 blah=0;write (f,&blah,1);//no attribute bits, origin is lowerleft, no interleave
567                 
568                 s=buf;
569                 for (y=0;y<h;y++){//TGAs use BGR ordering of data.
570                         for (x=0;x<w;x++){
571                                 blah=s[0];
572                                 s[0]=s[2];
573                                 s[2]=blah;
574                                 s+=3;                           
575                         }
576                 }
577                 x=0;y=w*h*3;
578                 while (x<y){
579                         r=write(f,buf+x,y);
580                         if (r<=0){
581                                 mprintf((0,"screenshot error, couldn't write to %s (err %i)\n",savename,errno));
582                                 break;
583                         }
584                         x+=r;y-=r;
585                 }
586                 close(f);
587         }else{
588                 mprintf((0,"screenshot error, couldn't open %s (err %i)\n",savename,errno));
589         }
590 }
591 void save_screen_shot(int automap_flag)
592 {
593 //      fix t1;
594         char message[100];
595         static int savenum=0;
596         char savename[13];
597         unsigned char *buf;
598
599         if (!ogl_readpixels_ok){
600                 if (!automap_flag)
601 //                      hud_message(MSGC_GAME_FEEDBACK,"glReadPixels not supported on your configuration");
602                 return;
603         }
604
605         stop_time();
606
607 //added/changed on 10/31/98 by Victor Rachels to fix overwrite each new game
608         if ( savenum == 9999 ) savenum = 0;
609         sprintf(savename,"scrn%04d.tga",savenum++);
610
611         while(!access(savename,0))
612         {
613                 if ( savenum == 9999 ) savenum = 0;
614                 sprintf(savename,"scrn%04d.tga",savenum++);
615         }
616         sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
617 //end this section addition/change - Victor Rachels
618
619         if (automap_flag) {
620 //      save_font = grd_curcanv->cv_font;
621 //      gr_set_curfont(GAME_FONT);
622 //      gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
623 //      gr_get_string_size(message,&w,&h,&aw);
624 //              modex_print_message(32, 2, message);
625         } else {
626 //              hud_message(MSGC_GAME_FEEDBACK,message);
627         }
628         
629         buf = d_malloc(grd_curscreen->sc_w*grd_curscreen->sc_h*3);
630         glReadBuffer(GL_FRONT);
631         glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
632         write_bmp(savename,grd_curscreen->sc_w,grd_curscreen->sc_h,buf);
633         d_free(buf);
634
635         key_flush();
636         start_time();
637 }