1 /* $Id: gr.c,v 1.31 2004-05-22 23:06:58 btb Exp $ */
4 * OGL video functions. - Added 9/15/99 Matthew Mueller
20 #if defined(__APPLE__) && defined(__MACH__)
21 //#include <OpenGL/gl.h>
28 #include <sys/types.h>
53 #if defined(__APPLE__) && defined(__MACH__)
54 #include <OpenGL/glu.h>
55 #undef GL_ARB_multitexture // hack!
65 void gr_palette_clear(); // Function prototype for gr_init;
71 int gr_check_fullscreen(void){
72 return ogl_fullscreen;
75 void gr_do_fullscreen(int f){
77 ogl_fullscreen=1;//force fullscreen mode on voodoos.
81 ogl_do_fullscreen_internal();
85 int gr_toggle_fullscreen(void){
86 gr_do_fullscreen(!ogl_fullscreen);
87 // grd_curscreen->sc_mode=0;//hack to get it to reset screen mode
88 return ogl_fullscreen;
91 int arch_toggle_fullscreen_menu(void){
92 unsigned char *buf=NULL;
94 if (ogl_readpixels_ok){
95 MALLOC(buf,unsigned char,grd_curscreen->sc_w*grd_curscreen->sc_h*3);
96 glReadBuffer(GL_FRONT);
97 glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
100 gr_do_fullscreen(!ogl_fullscreen);
102 if (ogl_readpixels_ok){
103 // glWritePixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
105 glDrawPixels(grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
108 // grd_curscreen->sc_mode=0;//hack to get it to reset screen mode
110 return ogl_fullscreen;
113 void ogl_init_state(void){
114 /* select clearing (background) color */
115 glClearColor(0.0, 0.0, 0.0, 0.0);
116 glShadeModel(GL_SMOOTH);
118 /* initialize viewing values */
119 glMatrixMode(GL_PROJECTION);
121 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
122 glScalef(1.0, -1.0, 1.0);
123 glTranslatef(0.0, -1.0, 0.0);
124 gr_palette_step_up(0,0,0);//in case its left over from in game
127 int last_screen_mode=-1;
129 void ogl_set_screen_mode(void){
130 if (last_screen_mode==Screen_mode)
132 OGL_VIEWPORT(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h);
133 // 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);
134 if (Screen_mode==SCREEN_GAME){
135 glDrawBuffer(GL_BACK);
137 glClearColor(0.0, 0.0, 0.0, 0.0);
138 glDrawBuffer(GL_FRONT);
139 glClear(GL_COLOR_BUFFER_BIT);
140 glMatrixMode(GL_PROJECTION);
141 glLoadIdentity();//clear matrix
142 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
143 glMatrixMode(GL_MODELVIEW);
144 glLoadIdentity();//clear matrix
146 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
148 last_screen_mode=Screen_mode;
155 if(Screen_mode != SCREEN_GAME){
161 const char *gl_vendor,*gl_renderer,*gl_version,*gl_extensions;
163 void ogl_get_verinfo(void)
165 int t, arb_max_textures = -1, sgi_max_textures = -1;
166 #ifdef GL_NV_register_combiners
167 int nv_register_combiners = -1;
169 float anisotropic_max = 0;
171 gl_vendor=glGetString(GL_VENDOR);
172 gl_renderer=glGetString(GL_RENDERER);
173 gl_version=glGetString(GL_VERSION);
174 gl_extensions=glGetString(GL_EXTENSIONS);
176 con_printf(CON_VERBOSE, "gl vendor:%s renderer:%s version:%s extensions:%s\n",gl_vendor,gl_renderer,gl_version,gl_extensions);
178 ogl_intensity4_ok = 1;
179 ogl_luminance4_alpha4_ok = 1;
181 ogl_gettexlevelparam_ok = 1;
182 ogl_setgammaramp_ok = 1;
185 dglMultiTexCoord2fARB = (glMultiTexCoord2fARB_fp)wglGetProcAddress("glMultiTexCoord2fARB");
186 dglActiveTextureARB = (glActiveTextureARB_fp)wglGetProcAddress("glActiveTextureARB");
187 dglMultiTexCoord2fSGIS = (glMultiTexCoord2fSGIS_fp)wglGetProcAddress("glMultiTexCoord2fSGIS");
188 dglSelectTextureSGIS = (glSelectTextureSGIS_fp)wglGetProcAddress("glSelectTextureSGIS");
189 dglColorTableEXT = (glColorTableEXT_fp)wglGetProcAddress("glColorTableEXT");
190 dglCombinerParameteriNV = (glCombinerParameteriNV_fp)wglGetProcAddress("glCombinerParameteriNV");
191 dglCombinerInputNV = (glCombinerInputNV_fp)wglGetProcAddress("glCombinerInputNV");
192 dglCombinerOutputNV = (glCombinerOutputNV_fp)wglGetProcAddress("glCombinerOutputNV");
193 dglFinalCombinerInputNV = (glFinalCombinerInputNV_fp)wglGetProcAddress("glFinalCombinerInputNV");
196 #ifdef GL_ARB_multitexture
197 ogl_arb_multitexture_ok = (strstr(gl_extensions, "GL_ARB_multitexture") != 0 && glActiveTextureARB != 0);
198 mprintf((0,"c:%p d:%p e:%p\n",strstr(gl_extensions,"GL_ARB_multitexture"),glActiveTextureARB,glBegin));
200 #ifdef GL_SGIS_multitexture
201 ogl_sgis_multitexture_ok = (strstr(gl_extensions, "GL_SGIS_multitexture") != 0 && glSelectTextureSGIS != 0);
202 mprintf((0,"a:%p b:%p\n",strstr(gl_extensions,"GL_SGIS_multitexture"),glSelectTextureSGIS));
204 ogl_nv_texture_env_combine4_ok = (strstr(gl_extensions, "GL_NV_texture_env_combine4") != 0);
205 #ifdef GL_NV_register_combiners
206 ogl_nv_register_combiners_ok=(strstr(gl_extensions,"GL_NV_register_combiners")!=0 && glCombinerOutputNV!=0);
209 ogl_ext_texture_filter_anisotropic_ok = (strstr(gl_extensions, "GL_EXT_texture_filter_anisotropic") != 0);
210 if (ogl_ext_texture_filter_anisotropic_ok)
211 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_max);
213 #ifdef GL_EXT_paletted_texture
214 ogl_paletted_texture_ok = (strstr(gl_extensions, "GL_EXT_paletted_texture") != 0 && glColorTableEXT != 0);
215 ogl_shared_palette_ok = (strstr(gl_extensions, "GL_EXT_shared_texture_palette") != 0 && ogl_paletted_texture_ok);
217 //add driver specific hacks here. whee.
218 if ((stricmp(gl_renderer,"Mesa NVIDIA RIVA 1.0\n")==0 || stricmp(gl_renderer,"Mesa NVIDIA RIVA 1.2\n")==0) && stricmp(gl_version,"1.2 Mesa 3.0")==0){
219 ogl_intensity4_ok=0;//ignores alpha, always black background instead of transparent.
220 ogl_readpixels_ok=0;//either just returns all black, or kills the X server entirely
221 ogl_gettexlevelparam_ok=0;//returns random data..
223 if (stricmp(gl_vendor,"Matrox Graphics Inc.")==0){
224 //displays garbage. reported by
225 // redomen@crcwnet.com (render="Matrox G400" version="1.1.3 5.52.015")
226 // orulz (Matrox G200)
230 //allow overriding of stuff.
231 #ifdef GL_ARB_multitexture
232 if ((t=FindArg("-gl_arb_multitexture_ok"))){
233 ogl_arb_multitexture_ok=atoi(Args[t+1]);
235 if (ogl_arb_multitexture_ok)
236 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &arb_max_textures);
238 #ifdef GL_SGIS_multitexture
239 if ((t=FindArg("-gl_sgis_multitexture_ok"))){
240 ogl_sgis_multitexture_ok=atoi(Args[t+1]);
242 if (ogl_sgis_multitexture_ok)
243 glGetIntegerv(GL_MAX_TEXTURES_SGIS, &sgi_max_textures);
245 #ifdef GL_NV_register_combiners
246 if ((t = FindArg("-gl_nv_register_combiners_ok")))
248 ogl_nv_register_combiners_ok=atoi(Args[t + 1]);
250 if (ogl_nv_register_combiners_ok)
251 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &nv_register_combiners);
253 #ifdef GL_EXT_paletted_texture
254 if ((t = FindArg("-gl_paletted_texture_ok")))
256 ogl_paletted_texture_ok = atoi(Args[t + 1]);
258 if ((t = FindArg("-gl_shared_palette_ok")))
260 ogl_shared_palette_ok = atoi(Args[t + 1]);
262 ogl_shared_palette_ok = ogl_shared_palette_ok && ogl_paletted_texture_ok; // shared palettes require palette support in the first place, obviously ;)
263 printf("gl_paletted_texture: %i gl_shared_palette: %i (using paletted textures: %i)\n", ogl_paletted_texture_ok, ogl_shared_palette_ok, ogl_shared_palette_ok);
265 if ((t=FindArg("-gl_intensity4_ok"))){
266 ogl_intensity4_ok=atoi(Args[t+1]);
268 if ((t=FindArg("-gl_luminance4_alpha4_ok"))){
269 ogl_luminance4_alpha4_ok=atoi(Args[t+1]);
271 if ((t=FindArg("-gl_rgba2_ok"))){
272 ogl_rgba2_ok=atoi(Args[t+1]);
274 if ((t=FindArg("-gl_readpixels_ok"))){
275 ogl_readpixels_ok=atoi(Args[t+1]);
277 if ((t=FindArg("-gl_gettexlevelparam_ok"))){
278 ogl_gettexlevelparam_ok=atoi(Args[t+1]);
280 if ((t=FindArg("-gl_setgammaramp_ok")))
282 ogl_setgammaramp_ok = atoi(Args[t + 1]);
285 con_printf(CON_VERBOSE, "gl_arb_multitexture:%i(%i units) gl_sgis_multitexture:%i(%i units) gl_nv_texture_env_combine4:%i\n", ogl_arb_multitexture_ok, arb_max_textures, ogl_sgis_multitexture_ok, sgi_max_textures, ogl_nv_texture_env_combine4_ok);
286 #ifdef GL_NV_register_combiners
287 con_printf(CON_VERBOSE, "gl_nv_register_combiners:%i(%i stages)\n", ogl_nv_register_combiners_ok, nv_register_combiners);
289 con_printf(CON_VERBOSE, "gl_intensity4:%i gl_luminance4_alpha4:%i gl_rgba2:%i gl_readpixels:%i gl_gettexlevelparam:%i gl_setgammaramp_ok:%i gl_ext_texture_filter_anisotropic:%i(%f max)\n", ogl_intensity4_ok, ogl_luminance4_alpha4_ok, ogl_rgba2_ok, ogl_readpixels_ok, ogl_gettexlevelparam_ok, ogl_setgammaramp_ok, ogl_ext_texture_filter_anisotropic_ok, anisotropic_max);
293 int gr_check_mode(u_int32_t mode)
299 return ogl_check_mode(w, h); // platform specific code
303 extern int VGA_current_mode; // DPH: kludge - remove at all costs
305 int gr_set_mode(u_int32_t mode)
319 VGA_current_mode = mode;
321 //if (screen != NULL) gr_palette_clear();
325 gr_bm_data=grd_curscreen->sc_canvas.cv_bitmap.bm_data;//since we use realloc, we want to keep this pointer around.
326 memset( grd_curscreen, 0, sizeof(grs_screen));
327 grd_curscreen->sc_mode = mode;
328 grd_curscreen->sc_w = w;
329 grd_curscreen->sc_h = h;
330 grd_curscreen->sc_aspect = fixdiv(grd_curscreen->sc_w*3,grd_curscreen->sc_h*4);
331 grd_curscreen->sc_canvas.cv_bitmap.bm_x = 0;
332 grd_curscreen->sc_canvas.cv_bitmap.bm_y = 0;
333 grd_curscreen->sc_canvas.cv_bitmap.bm_w = w;
334 grd_curscreen->sc_canvas.cv_bitmap.bm_h = h;
335 //grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = screen->pitch;
336 grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = w;
337 grd_curscreen->sc_canvas.cv_bitmap.bm_type = BM_OGL;
338 //grd_curscreen->sc_canvas.cv_bitmap.bm_data = (unsigned char *)screen->pixels;
339 // mprintf((0,"ogl/gr.c: reallocing %p to %i\n",grd_curscreen->sc_canvas.cv_bitmap.bm_data,w*h));
340 grd_curscreen->sc_canvas.cv_bitmap.bm_data = d_realloc(gr_bm_data,w*h);
341 gr_set_current_canvas(NULL);
342 //gr_enable_default_palette_loading();
344 ogl_init_window(w,h);//platform specific code
348 OGL_VIEWPORT(0,0,w,h);
350 ogl_set_screen_mode();
352 // gamefont_choose_game_font(w,h);
357 #define GLstrcmptestr(a,b) if (stricmp(a,#b)==0 || stricmp(a,"GL_" #b)==0)return GL_ ## b;
358 int ogl_atotexfilti(char *a,int min){
359 GLstrcmptestr(a,NEAREST);
360 GLstrcmptestr(a,LINEAR);
361 if (min){//mipmaps are valid only for the min filter
362 GLstrcmptestr(a,NEAREST_MIPMAP_NEAREST);
363 GLstrcmptestr(a,NEAREST_MIPMAP_LINEAR);
364 GLstrcmptestr(a,LINEAR_MIPMAP_NEAREST);
365 GLstrcmptestr(a,LINEAR_MIPMAP_LINEAR);
367 Error("unknown/invalid texture filter %s\n",a);
368 // return GL_NEAREST;
370 int ogl_testneedmipmaps(int i){
375 case GL_NEAREST_MIPMAP_NEAREST:
376 case GL_NEAREST_MIPMAP_LINEAR:
377 case GL_LINEAR_MIPMAP_NEAREST:
378 case GL_LINEAR_MIPMAP_LINEAR:
381 Error("unknown texture filter %x\n",i);
384 #ifdef OGL_RUNTIME_LOAD
386 char *OglLibPath="opengl32.dll";
389 char *OglLibPath="libGL.so";
393 int ogl_init_load_library(void)
398 if ((t=FindArg("-gl_library")))
399 OglLibPath=Args[t+1];
401 retcode = OpenGL_LoadLibrary(true);
404 mprintf((0,"Opengl loaded ok\n"));
408 Error("Opengl: Functions not imported\n");
411 Error("Opengl: error loading %s\n",OglLibPath);
421 int mode = SM(640,480);
422 int retcode, t, glt = 0;
424 // Only do this function once!
429 #ifdef OGL_RUNTIME_LOAD
430 ogl_init_load_library();
433 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
434 if (FindArg("-gl_voodoo")){
436 gr_toggle_fullscreen();
438 if (FindArg("-fullscreen"))
439 gr_toggle_fullscreen();
441 if ((glt=FindArg("-gl_alttexmerge")))
443 if ((t=FindArg("-gl_stdtexmerge")))
444 if (t>=glt)//allow overriding of earlier args
447 if ((glt = FindArg("-gl_16bittextures")))
449 ogl_rgba_internalformat = GL_RGB5_A1;
450 ogl_rgb_internalformat = GL_RGB5;
453 if ((glt=FindArg("-gl_mipmap"))){
454 GL_texmagfilt=GL_LINEAR;
455 GL_texminfilt=GL_LINEAR_MIPMAP_NEAREST;
457 if ((glt=FindArg("-gl_trilinear")))
459 GL_texmagfilt = GL_LINEAR;
460 GL_texminfilt = GL_LINEAR_MIPMAP_LINEAR;
462 if ((t=FindArg("-gl_simple"))){
463 if (t>=glt){//allow overriding of earlier args
465 GL_texmagfilt=GL_NEAREST;
466 GL_texminfilt=GL_NEAREST;
469 if ((t=FindArg("-gl_texmagfilt")) || (t=FindArg("-gl_texmagfilter"))){
470 if (t>=glt)//allow overriding of earlier args
471 GL_texmagfilt=ogl_atotexfilti(Args[t+1],0);
473 if ((t=FindArg("-gl_texminfilt")) || (t=FindArg("-gl_texminfilter"))){
474 if (t>=glt)//allow overriding of earlier args
475 GL_texminfilt=ogl_atotexfilti(Args[t+1],1);
477 GL_needmipmaps=ogl_testneedmipmaps(GL_texminfilt);
479 if ((t = FindArg("-gl_anisotropy")) || (t = FindArg("-gl_anisotropic")))
481 GL_texanisofilt=atof(Args[t + 1]);
484 mprintf((0,"gr_init: texmagfilt:%x texminfilt:%x needmipmaps=%i anisotropic:%f\n",GL_texmagfilt,GL_texminfilt,GL_needmipmaps,GL_texanisofilt));
487 if ((t=FindArg("-gl_vidmem"))){
488 ogl_mem_target=atoi(Args[t+1])*1024*1024;
490 if ((t=FindArg("-gl_reticle"))){
491 gl_reticle=atoi(Args[t+1]);
493 //printf("ogl_mem_target=%i\n",ogl_mem_target);
495 ogl_init();//platform specific initialization
497 ogl_init_texture_list_internal();
499 MALLOC( grd_curscreen,grs_screen,1 );
500 memset( grd_curscreen, 0, sizeof(grs_screen));
501 grd_curscreen->sc_canvas.cv_bitmap.bm_data = NULL;
504 if ((retcode=gr_set_mode(mode)))
509 grd_curscreen->sc_canvas.cv_color = 0;
510 grd_curscreen->sc_canvas.cv_drawmode = 0;
511 grd_curscreen->sc_canvas.cv_font = NULL;
512 grd_curscreen->sc_canvas.cv_font_fg_color = 0;
513 grd_curscreen->sc_canvas.cv_font_bg_color = 0;
514 gr_set_current_canvas( &grd_curscreen->sc_canvas );
525 // mprintf((0,"ogl init: %s %s %s - %s\n",glGetString(GL_VENDOR),glGetString(GL_RENDERER),glGetString(GL_VERSION),glGetString,(GL_EXTENSIONS)));
527 ogl_close();//platform specific code
529 if (grd_curscreen->sc_canvas.cv_bitmap.bm_data)
530 d_free(grd_curscreen->sc_canvas.cv_bitmap.bm_data);
531 d_free(grd_curscreen);
533 #ifdef OGL_RUNTIME_LOAD
535 OpenGL_LoadLibrary(false);
538 extern int r_upixelc;
539 void ogl_upixelc(int x, int y, int c){
541 // printf("gr_upixelc(%i,%i,%i)%i\n",x,y,c,Function_mode==FMODE_GAME);
542 // if(Function_mode != FMODE_GAME){
543 // grd_curcanv->cv_bitmap.bm_data[y*grd_curscreen->sc_canvas.cv_bitmap.bm_w+x]=c;
545 OGL_DISABLE(TEXTURE_2D);
548 // glBegin(GL_LINES);
549 // ogl_pal=gr_current_pal;
550 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
551 // ogl_pal=gr_palette;
552 glVertex2f((x + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width, 1.0 - (y + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height);
553 // glVertex2f(x/((float)last_width+1),1.0-y/((float)last_height+1));
557 void ogl_urect(int left,int top,int right,int bot){
561 xo=(left+grd_curcanv->cv_bitmap.bm_x)/(float)last_width;
562 xf = (right + 1 + grd_curcanv->cv_bitmap.bm_x) / (float)last_width;
563 yo=1.0-(top+grd_curcanv->cv_bitmap.bm_y)/(float)last_height;
564 yf = 1.0 - (bot + 1 + grd_curcanv->cv_bitmap.bm_y) / (float)last_height;
566 OGL_DISABLE(TEXTURE_2D);
567 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
575 void ogl_ulinec(int left,int top,int right,int bot,int c){
578 xo = (left + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
579 xf = (right + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
580 yo = 1.0 - (top + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
581 yf = 1.0 - (bot + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
583 OGL_DISABLE(TEXTURE_2D);
584 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
592 GLfloat last_r=0, last_g=0, last_b=0;
594 void ogl_do_palfx(void){
596 OGL_DISABLE(TEXTURE_2D);
597 if (gr_palette_faded_out){
598 /* glEnable(GL_BLEND);
599 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
604 //glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
606 glBlendFunc(GL_ONE,GL_ONE);
607 glColor3f(last_r,last_g,last_b);
608 // r=f2fl(last_r);g=f2fl(last_g);b=f2fl(last_b);a=0.5;
622 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
625 void gr_palette_clear()
627 gr_palette_faded_out=1;
631 int ogl_brightness_ok = 0;
632 int ogl_setgammaramp_ok = 1;
633 int ogl_brightness_r = 0, ogl_brightness_g = 0, ogl_brightness_b = 0;
634 static int old_b_r = 0, old_b_g = 0, old_b_b = 0;
636 void gr_palette_step_up(int r, int g, int b)
638 if (gr_palette_faded_out)
641 old_b_r = ogl_brightness_r;
642 old_b_g = ogl_brightness_g;
643 old_b_b = ogl_brightness_b;
645 ogl_brightness_r = max(r + gr_palette_gamma, 0);
646 ogl_brightness_g = max(g + gr_palette_gamma, 0);
647 ogl_brightness_b = max(b + gr_palette_gamma, 0);
649 if (ogl_setgammaramp_ok &&
650 (old_b_r != ogl_brightness_r ||
651 old_b_g != ogl_brightness_g ||
652 old_b_b != ogl_brightness_b))
653 ogl_brightness_ok = !ogl_setbrightness_internal();
655 if (!ogl_setgammaramp_ok || !ogl_brightness_ok)
657 last_r = ogl_brightness_r / 63.0;
658 last_g = ogl_brightness_g / 63.0;
659 last_b = ogl_brightness_b / 63.0;
661 do_pal_step = (r || g || b || gr_palette_gamma);
669 //added on 980913 by adb to fix palette problems
670 // need a min without side effects...
672 static inline int min(int x, int y) { return x < y ? x : y; }
675 void gr_palette_load( ubyte *pal )
679 for (i=0; i<768; i++ ) {
680 gr_current_pal[i] = pal[i];
681 if (gr_current_pal[i] > 63) gr_current_pal[i] = 63;
683 //palette = screen->format->palette;
685 gr_palette_faded_out=0;
687 gr_palette_step_up(0, 0, 0); // make ogl_setbrightness_internal get run so that menus get brightened too.
689 init_computed_colors();
691 ogl_init_shared_palette();
696 int gr_palette_fade_out(ubyte *pal, int nsteps, int allow_keys)
698 gr_palette_faded_out=1;
704 int gr_palette_fade_in(ubyte *pal, int nsteps, int allow_keys)
706 gr_palette_faded_out=0;
712 void gr_palette_read(ubyte * pal)
715 for (i=0; i<768; i++ ) {
716 pal[i]=gr_current_pal[i];
717 if (pal[i] > 63) pal[i] = 63;
721 //writes out an uncompressed RGB .tga file
722 //if we got really spiffy, we could optionally link in libpng or something, and use that.
723 void write_bmp(char *savename,int w,int h,unsigned char *buf){
726 f=open(savename,O_CREAT|O_EXCL|O_WRONLY,S_IREAD|S_IWRITE);
728 f=open(savename,O_CREAT|O_EXCL|O_WRONLY,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
731 GLubyte targaMagic[12] = { 0, //no identification field
733 2,//RGB image (well, BGR, actually)
734 0, 0, 0, 0, 0, 0, 0, 0, 0 };//no colormap or image origin stuff.
741 write (f,targaMagic,sizeof(targaMagic));
742 blah=w%256;write (f,&blah,1);//w, low
743 blah=w/256;write (f,&blah,1);//w, high
744 blah=h%256;write (f,&blah,1);//h, low
745 blah=h/256;write (f,&blah,1);//h, high
746 blah=24;write (f,&blah,1);//24 bpp
747 blah=0;write (f,&blah,1);//no attribute bits, origin is lowerleft, no interleave
750 for (y=0;y<h;y++){//TGAs use BGR ordering of data.
763 mprintf((0,"screenshot error, couldn't write to %s (err %i)\n",savename,errno));
770 mprintf((0,"screenshot error, couldn't open %s (err %i)\n",savename,errno));
773 void save_screen_shot(int automap_flag)
777 static int savenum=0;
781 if (!ogl_readpixels_ok){
783 hud_message(MSGC_GAME_FEEDBACK,"glReadPixels not supported on your configuration");
789 //added/changed on 10/31/98 by Victor Rachels to fix overwrite each new game
790 if ( savenum == 9999 ) savenum = 0;
791 sprintf(savename,"scrn%04d.tga",savenum++);
793 while(!access(savename,0))
795 if ( savenum == 9999 ) savenum = 0;
796 sprintf(savename,"scrn%04d.tga",savenum++);
798 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
799 //end this section addition/change - Victor Rachels
802 // save_font = grd_curcanv->cv_font;
803 // gr_set_curfont(GAME_FONT);
804 // gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
805 // gr_get_string_size(message,&w,&h,&aw);
806 // modex_print_message(32, 2, message);
808 hud_message(MSGC_GAME_FEEDBACK,message);
811 buf = d_malloc(grd_curscreen->sc_w*grd_curscreen->sc_h*3);
812 glReadBuffer(GL_FRONT);
813 glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
814 write_bmp(savename,grd_curscreen->sc_w,grd_curscreen->sc_h,buf);