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