1 /* $Id: gr.c,v 1.36 2004-11-14 09:34:23 schaffner Exp $ */
4 * OGL video functions. - Added 9/15/99 Matthew Mueller
20 #if !defined(_MSC_VER) && !defined(macintosh)
23 #if !defined(macintosh)
24 #include <sys/types.h>
51 #if defined(__APPLE__) && defined(__MACH__)
52 #include <OpenGL/glu.h>
53 #undef GL_ARB_multitexture // hack!
63 void gr_palette_clear(); // Function prototype for gr_init;
69 int gr_check_fullscreen(void){
70 return ogl_fullscreen;
73 void gr_do_fullscreen(int f){
75 ogl_fullscreen=1;//force fullscreen mode on voodoos.
79 ogl_do_fullscreen_internal();
83 int gr_toggle_fullscreen(void){
84 gr_do_fullscreen(!ogl_fullscreen);
85 // grd_curscreen->sc_mode=0;//hack to get it to reset screen mode
86 return ogl_fullscreen;
89 int arch_toggle_fullscreen_menu(void){
90 unsigned char *buf=NULL;
92 if (ogl_readpixels_ok){
93 MALLOC(buf,unsigned char,grd_curscreen->sc_w*grd_curscreen->sc_h*3);
94 glReadBuffer(GL_FRONT);
95 glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
98 gr_do_fullscreen(!ogl_fullscreen);
100 if (ogl_readpixels_ok){
101 // glWritePixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
103 glDrawPixels(grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
106 // grd_curscreen->sc_mode=0;//hack to get it to reset screen mode
108 return ogl_fullscreen;
111 void ogl_init_state(void){
112 /* select clearing (background) color */
113 glClearColor(0.0, 0.0, 0.0, 0.0);
114 glShadeModel(GL_SMOOTH);
116 /* initialize viewing values */
117 glMatrixMode(GL_PROJECTION);
119 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
120 glScalef(1.0, -1.0, 1.0);
121 glTranslatef(0.0, -1.0, 0.0);
122 gr_palette_step_up(0,0,0);//in case its left over from in game
125 int last_screen_mode=-1;
127 void ogl_set_screen_mode(void){
128 if (last_screen_mode==Screen_mode)
130 OGL_VIEWPORT(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h);
131 // 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);
132 if (Screen_mode==SCREEN_GAME){
133 glDrawBuffer(GL_BACK);
135 glClearColor(0.0, 0.0, 0.0, 0.0);
136 glDrawBuffer(GL_FRONT);
137 glClear(GL_COLOR_BUFFER_BIT);
138 glMatrixMode(GL_PROJECTION);
139 glLoadIdentity();//clear matrix
140 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
141 glMatrixMode(GL_MODELVIEW);
142 glLoadIdentity();//clear matrix
144 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
146 last_screen_mode=Screen_mode;
153 if(Screen_mode != SCREEN_GAME){
159 const char *gl_vendor, *gl_renderer, *gl_version, *gl_extensions;
161 void ogl_get_verinfo(void)
163 int t, arb_max_textures = -1, sgi_max_textures = -1;
164 #ifdef GL_NV_register_combiners
165 int nv_register_combiners = -1;
167 float anisotropic_max = 0;
169 gl_vendor = (const char *) glGetString (GL_VENDOR);
170 gl_renderer = (const char *) glGetString (GL_RENDERER);
171 gl_version = (const char *) glGetString (GL_VERSION);
172 gl_extensions = (const char *) glGetString (GL_EXTENSIONS);
174 con_printf(CON_VERBOSE, "gl vendor:%s renderer:%s version:%s extensions:%s\n",gl_vendor,gl_renderer,gl_version,gl_extensions);
176 ogl_intensity4_ok = 1;
177 ogl_luminance4_alpha4_ok = 1;
179 ogl_gettexlevelparam_ok = 1;
180 ogl_setgammaramp_ok = 1;
183 dglMultiTexCoord2fARB = (glMultiTexCoord2fARB_fp)wglGetProcAddress("glMultiTexCoord2fARB");
184 dglActiveTextureARB = (glActiveTextureARB_fp)wglGetProcAddress("glActiveTextureARB");
185 dglMultiTexCoord2fSGIS = (glMultiTexCoord2fSGIS_fp)wglGetProcAddress("glMultiTexCoord2fSGIS");
186 dglSelectTextureSGIS = (glSelectTextureSGIS_fp)wglGetProcAddress("glSelectTextureSGIS");
187 dglColorTableEXT = (glColorTableEXT_fp)wglGetProcAddress("glColorTableEXT");
188 dglCombinerParameteriNV = (glCombinerParameteriNV_fp)wglGetProcAddress("glCombinerParameteriNV");
189 dglCombinerInputNV = (glCombinerInputNV_fp)wglGetProcAddress("glCombinerInputNV");
190 dglCombinerOutputNV = (glCombinerOutputNV_fp)wglGetProcAddress("glCombinerOutputNV");
191 dglFinalCombinerInputNV = (glFinalCombinerInputNV_fp)wglGetProcAddress("glFinalCombinerInputNV");
194 #ifdef GL_ARB_multitexture
195 ogl_arb_multitexture_ok = (strstr(gl_extensions, "GL_ARB_multitexture") != 0 && glActiveTextureARB != 0);
196 mprintf((0,"c:%p d:%p e:%p\n",strstr(gl_extensions,"GL_ARB_multitexture"),glActiveTextureARB,glBegin));
198 #ifdef GL_SGIS_multitexture
199 ogl_sgis_multitexture_ok = (strstr(gl_extensions, "GL_SGIS_multitexture") != 0 && glSelectTextureSGIS != 0);
200 mprintf((0,"a:%p b:%p\n",strstr(gl_extensions,"GL_SGIS_multitexture"),glSelectTextureSGIS));
202 ogl_nv_texture_env_combine4_ok = (strstr(gl_extensions, "GL_NV_texture_env_combine4") != 0);
203 #ifdef GL_NV_register_combiners
204 ogl_nv_register_combiners_ok=(strstr(gl_extensions,"GL_NV_register_combiners")!=0 && glCombinerOutputNV!=0);
207 ogl_ext_texture_filter_anisotropic_ok = (strstr(gl_extensions, "GL_EXT_texture_filter_anisotropic") != 0);
208 if (ogl_ext_texture_filter_anisotropic_ok)
209 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_max);
211 #ifdef GL_EXT_paletted_texture
212 ogl_paletted_texture_ok = (strstr(gl_extensions, "GL_EXT_paletted_texture") != 0 && glColorTableEXT != 0);
213 ogl_shared_palette_ok = (strstr(gl_extensions, "GL_EXT_shared_texture_palette") != 0 && ogl_paletted_texture_ok);
215 //add driver specific hacks here. whee.
216 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){
217 ogl_intensity4_ok=0;//ignores alpha, always black background instead of transparent.
218 ogl_readpixels_ok=0;//either just returns all black, or kills the X server entirely
219 ogl_gettexlevelparam_ok=0;//returns random data..
221 if (stricmp(gl_vendor,"Matrox Graphics Inc.")==0){
222 //displays garbage. reported by
223 // redomen@crcwnet.com (render="Matrox G400" version="1.1.3 5.52.015")
224 // orulz (Matrox G200)
228 if (stricmp(gl_renderer,"3dfx Voodoo 3")==0){ // strangely, includes Voodoo 2
229 ogl_gettexlevelparam_ok=0; // Always returns 0
233 //allow overriding of stuff.
234 #ifdef GL_ARB_multitexture
235 if ((t=FindArg("-gl_arb_multitexture_ok"))){
236 ogl_arb_multitexture_ok=atoi(Args[t+1]);
238 if (ogl_arb_multitexture_ok)
239 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &arb_max_textures);
241 #ifdef GL_SGIS_multitexture
242 if ((t=FindArg("-gl_sgis_multitexture_ok"))){
243 ogl_sgis_multitexture_ok=atoi(Args[t+1]);
245 if (ogl_sgis_multitexture_ok)
246 glGetIntegerv(GL_MAX_TEXTURES_SGIS, &sgi_max_textures);
248 #ifdef GL_NV_register_combiners
249 if ((t = FindArg("-gl_nv_register_combiners_ok")))
251 ogl_nv_register_combiners_ok=atoi(Args[t + 1]);
253 if (ogl_nv_register_combiners_ok)
254 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &nv_register_combiners);
256 #ifdef GL_EXT_paletted_texture
257 if ((t = FindArg("-gl_paletted_texture_ok")))
259 ogl_paletted_texture_ok = atoi(Args[t + 1]);
261 if ((t = FindArg("-gl_shared_palette_ok")))
263 ogl_shared_palette_ok = atoi(Args[t + 1]);
265 ogl_shared_palette_ok = ogl_shared_palette_ok && ogl_paletted_texture_ok; // shared palettes require palette support in the first place, obviously ;)
266 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);
268 if ((t=FindArg("-gl_intensity4_ok"))){
269 ogl_intensity4_ok=atoi(Args[t+1]);
271 if ((t=FindArg("-gl_luminance4_alpha4_ok"))){
272 ogl_luminance4_alpha4_ok=atoi(Args[t+1]);
274 if ((t=FindArg("-gl_rgba2_ok"))){
275 ogl_rgba2_ok=atoi(Args[t+1]);
277 if ((t=FindArg("-gl_readpixels_ok"))){
278 ogl_readpixels_ok=atoi(Args[t+1]);
280 if ((t=FindArg("-gl_gettexlevelparam_ok"))){
281 ogl_gettexlevelparam_ok=atoi(Args[t+1]);
283 if ((t=FindArg("-gl_setgammaramp_ok")))
285 ogl_setgammaramp_ok = atoi(Args[t + 1]);
288 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);
289 #ifdef GL_NV_register_combiners
290 con_printf(CON_VERBOSE, "gl_nv_register_combiners:%i(%i stages)\n", ogl_nv_register_combiners_ok, nv_register_combiners);
292 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);
296 int gr_check_mode(u_int32_t mode)
302 return ogl_check_mode(w, h); // platform specific code
306 extern int VGA_current_mode; // DPH: kludge - remove at all costs
308 int gr_set_mode(u_int32_t mode)
322 VGA_current_mode = mode;
324 //if (screen != NULL) gr_palette_clear();
328 gr_bm_data=(char *)grd_curscreen->sc_canvas.cv_bitmap.bm_data;//since we use realloc, we want to keep this pointer around.
329 memset( grd_curscreen, 0, sizeof(grs_screen));
330 grd_curscreen->sc_mode = mode;
331 grd_curscreen->sc_w = w;
332 grd_curscreen->sc_h = h;
333 grd_curscreen->sc_aspect = fixdiv(grd_curscreen->sc_w*3,grd_curscreen->sc_h*4);
334 grd_curscreen->sc_canvas.cv_bitmap.bm_x = 0;
335 grd_curscreen->sc_canvas.cv_bitmap.bm_y = 0;
336 grd_curscreen->sc_canvas.cv_bitmap.bm_w = w;
337 grd_curscreen->sc_canvas.cv_bitmap.bm_h = h;
338 //grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = screen->pitch;
339 grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = w;
340 grd_curscreen->sc_canvas.cv_bitmap.bm_type = BM_OGL;
341 //grd_curscreen->sc_canvas.cv_bitmap.bm_data = (unsigned char *)screen->pixels;
342 // mprintf((0,"ogl/gr.c: reallocing %p to %i\n",grd_curscreen->sc_canvas.cv_bitmap.bm_data,w*h));
343 grd_curscreen->sc_canvas.cv_bitmap.bm_data = d_realloc(gr_bm_data,w*h);
344 gr_set_current_canvas(NULL);
345 //gr_enable_default_palette_loading();
347 ogl_init_window(w,h);//platform specific code
351 OGL_VIEWPORT(0,0,w,h);
353 ogl_set_screen_mode();
355 // gamefont_choose_game_font(w,h);
360 #define GLstrcmptestr(a,b) if (stricmp(a,#b)==0 || stricmp(a,"GL_" #b)==0)return GL_ ## b;
361 int ogl_atotexfilti(char *a,int min){
362 GLstrcmptestr(a,NEAREST);
363 GLstrcmptestr(a,LINEAR);
364 if (min){//mipmaps are valid only for the min filter
365 GLstrcmptestr(a,NEAREST_MIPMAP_NEAREST);
366 GLstrcmptestr(a,NEAREST_MIPMAP_LINEAR);
367 GLstrcmptestr(a,LINEAR_MIPMAP_NEAREST);
368 GLstrcmptestr(a,LINEAR_MIPMAP_LINEAR);
370 Error("unknown/invalid texture filter %s\n",a);
371 // return GL_NEAREST;
373 int ogl_testneedmipmaps(int i){
378 case GL_NEAREST_MIPMAP_NEAREST:
379 case GL_NEAREST_MIPMAP_LINEAR:
380 case GL_LINEAR_MIPMAP_NEAREST:
381 case GL_LINEAR_MIPMAP_LINEAR:
384 Error("unknown texture filter %x\n",i);
387 #ifdef OGL_RUNTIME_LOAD
389 char *OglLibPath="opengl32.dll";
392 char *OglLibPath="libGL.so";
396 int ogl_init_load_library(void)
401 if ((t=FindArg("-gl_library")))
402 OglLibPath=Args[t+1];
404 retcode = OpenGL_LoadLibrary(true);
407 mprintf((0,"Opengl loaded ok\n"));
411 Error("Opengl: Functions not imported\n");
414 Error("Opengl: error loading %s\n",OglLibPath);
424 int mode = SM(640,480);
425 int retcode, t, glt = 0;
427 // Only do this function once!
432 #ifdef OGL_RUNTIME_LOAD
433 ogl_init_load_library();
436 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
437 if (FindArg("-gl_voodoo")){
439 gr_toggle_fullscreen();
441 if (FindArg("-fullscreen"))
442 gr_toggle_fullscreen();
444 if ((glt=FindArg("-gl_alttexmerge")))
446 if ((t=FindArg("-gl_stdtexmerge")))
447 if (t>=glt)//allow overriding of earlier args
450 if ((glt = FindArg("-gl_16bittextures")))
452 ogl_rgba_internalformat = GL_RGB5_A1;
453 ogl_rgb_internalformat = GL_RGB5;
456 if ((glt=FindArg("-gl_mipmap"))){
457 GL_texmagfilt=GL_LINEAR;
458 GL_texminfilt=GL_LINEAR_MIPMAP_NEAREST;
460 if ((glt=FindArg("-gl_trilinear")))
462 GL_texmagfilt = GL_LINEAR;
463 GL_texminfilt = GL_LINEAR_MIPMAP_LINEAR;
465 if ((t=FindArg("-gl_simple"))){
466 if (t>=glt){//allow overriding of earlier args
468 GL_texmagfilt=GL_NEAREST;
469 GL_texminfilt=GL_NEAREST;
472 if ((t=FindArg("-gl_texmagfilt")) || (t=FindArg("-gl_texmagfilter"))){
473 if (t>=glt)//allow overriding of earlier args
474 GL_texmagfilt=ogl_atotexfilti(Args[t+1],0);
476 if ((t=FindArg("-gl_texminfilt")) || (t=FindArg("-gl_texminfilter"))){
477 if (t>=glt)//allow overriding of earlier args
478 GL_texminfilt=ogl_atotexfilti(Args[t+1],1);
480 GL_needmipmaps=ogl_testneedmipmaps(GL_texminfilt);
482 if ((t = FindArg("-gl_anisotropy")) || (t = FindArg("-gl_anisotropic")))
484 GL_texanisofilt=atof(Args[t + 1]);
487 mprintf((0,"gr_init: texmagfilt:%x texminfilt:%x needmipmaps=%i anisotropic:%f\n",GL_texmagfilt,GL_texminfilt,GL_needmipmaps,GL_texanisofilt));
490 if ((t=FindArg("-gl_vidmem"))){
491 ogl_mem_target=atoi(Args[t+1])*1024*1024;
493 if ((t=FindArg("-gl_reticle"))){
494 gl_reticle=atoi(Args[t+1]);
496 //printf("ogl_mem_target=%i\n",ogl_mem_target);
498 ogl_init();//platform specific initialization
500 ogl_init_texture_list_internal();
502 MALLOC( grd_curscreen,grs_screen,1 );
503 memset( grd_curscreen, 0, sizeof(grs_screen));
504 grd_curscreen->sc_canvas.cv_bitmap.bm_data = NULL;
507 if ((retcode=gr_set_mode(mode)))
512 grd_curscreen->sc_canvas.cv_color = 0;
513 grd_curscreen->sc_canvas.cv_drawmode = 0;
514 grd_curscreen->sc_canvas.cv_font = NULL;
515 grd_curscreen->sc_canvas.cv_font_fg_color = 0;
516 grd_curscreen->sc_canvas.cv_font_bg_color = 0;
517 gr_set_current_canvas( &grd_curscreen->sc_canvas );
528 // mprintf((0,"ogl init: %s %s %s - %s\n",glGetString(GL_VENDOR),glGetString(GL_RENDERER),glGetString(GL_VERSION),glGetString,(GL_EXTENSIONS)));
530 ogl_close();//platform specific code
532 if (grd_curscreen->sc_canvas.cv_bitmap.bm_data)
533 d_free(grd_curscreen->sc_canvas.cv_bitmap.bm_data);
534 d_free(grd_curscreen);
536 #ifdef OGL_RUNTIME_LOAD
538 OpenGL_LoadLibrary(false);
541 extern int r_upixelc;
542 void ogl_upixelc(int x, int y, int c){
544 // printf("gr_upixelc(%i,%i,%i)%i\n",x,y,c,Function_mode==FMODE_GAME);
545 // if(Function_mode != FMODE_GAME){
546 // grd_curcanv->cv_bitmap.bm_data[y*grd_curscreen->sc_canvas.cv_bitmap.bm_w+x]=c;
548 OGL_DISABLE(TEXTURE_2D);
551 // glBegin(GL_LINES);
552 // ogl_pal=gr_current_pal;
553 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
554 // ogl_pal=gr_palette;
555 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);
556 // glVertex2f(x/((float)last_width+1),1.0-y/((float)last_height+1));
560 void ogl_urect(int left,int top,int right,int bot){
564 xo=(left+grd_curcanv->cv_bitmap.bm_x)/(float)last_width;
565 xf = (right + 1 + grd_curcanv->cv_bitmap.bm_x) / (float)last_width;
566 yo=1.0-(top+grd_curcanv->cv_bitmap.bm_y)/(float)last_height;
567 yf = 1.0 - (bot + 1 + grd_curcanv->cv_bitmap.bm_y) / (float)last_height;
569 OGL_DISABLE(TEXTURE_2D);
570 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
578 void ogl_ulinec(int left,int top,int right,int bot,int c){
581 xo = (left + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
582 xf = (right + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
583 yo = 1.0 - (top + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
584 yf = 1.0 - (bot + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
586 OGL_DISABLE(TEXTURE_2D);
587 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
595 GLfloat last_r=0, last_g=0, last_b=0;
597 void ogl_do_palfx(void){
599 OGL_DISABLE(TEXTURE_2D);
600 if (gr_palette_faded_out){
601 /* glEnable(GL_BLEND);
602 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
607 //glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
609 glBlendFunc(GL_ONE,GL_ONE);
610 glColor3f(last_r,last_g,last_b);
611 // r=f2fl(last_r);g=f2fl(last_g);b=f2fl(last_b);a=0.5;
625 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
628 void gr_palette_clear()
630 gr_palette_faded_out=1;
634 int ogl_brightness_ok = 0;
635 int ogl_setgammaramp_ok = 1;
636 int ogl_brightness_r = 0, ogl_brightness_g = 0, ogl_brightness_b = 0;
637 static int old_b_r = 0, old_b_g = 0, old_b_b = 0;
639 void gr_palette_step_up(int r, int g, int b)
641 if (gr_palette_faded_out)
644 old_b_r = ogl_brightness_r;
645 old_b_g = ogl_brightness_g;
646 old_b_b = ogl_brightness_b;
648 ogl_brightness_r = max(r + gr_palette_gamma, 0);
649 ogl_brightness_g = max(g + gr_palette_gamma, 0);
650 ogl_brightness_b = max(b + gr_palette_gamma, 0);
652 if (ogl_setgammaramp_ok &&
653 (old_b_r != ogl_brightness_r ||
654 old_b_g != ogl_brightness_g ||
655 old_b_b != ogl_brightness_b))
656 ogl_brightness_ok = !ogl_setbrightness_internal();
658 if (!ogl_setgammaramp_ok || !ogl_brightness_ok)
660 last_r = ogl_brightness_r / 63.0;
661 last_g = ogl_brightness_g / 63.0;
662 last_b = ogl_brightness_b / 63.0;
664 do_pal_step = (r || g || b || gr_palette_gamma);
672 //added on 980913 by adb to fix palette problems
673 // need a min without side effects...
675 static inline int min(int x, int y) { return x < y ? x : y; }
678 void gr_palette_load( ubyte *pal )
682 for (i=0; i<768; i++ ) {
683 gr_current_pal[i] = pal[i];
684 if (gr_current_pal[i] > 63) gr_current_pal[i] = 63;
686 //palette = screen->format->palette;
688 gr_palette_faded_out=0;
690 gr_palette_step_up(0, 0, 0); // make ogl_setbrightness_internal get run so that menus get brightened too.
692 init_computed_colors();
694 ogl_init_shared_palette();
699 int gr_palette_fade_out(ubyte *pal, int nsteps, int allow_keys)
701 gr_palette_faded_out=1;
707 int gr_palette_fade_in(ubyte *pal, int nsteps, int allow_keys)
709 gr_palette_faded_out=0;
715 void gr_palette_read(ubyte * pal)
718 for (i=0; i<768; i++ ) {
719 pal[i]=gr_current_pal[i];
720 if (pal[i] > 63) pal[i] = 63;
724 //writes out an uncompressed RGB .tga file
725 //if we got really spiffy, we could optionally link in libpng or something, and use that.
726 void write_bmp(char *savename,int w,int h,unsigned char *buf){
729 f = cfopen(savename, "wb");
732 GLubyte targaMagic[12] = { 0, //no identification field
734 2,//RGB image (well, BGR, actually)
735 0, 0, 0, 0, 0, 0, 0, 0, 0 };//no colormap or image origin stuff.
742 cfwrite (targaMagic,sizeof(targaMagic),1,f);
743 cfile_write_short (w,f);
744 cfile_write_short (h,f);
745 cfile_write_byte (24,f);//24 bpp
746 cfile_write_byte (0,f);//no attribute bits, origin is lowerleft, no interleave
749 for (y=0;y<h;y++){//TGAs use BGR ordering of data.
760 r=cfwrite(buf+x,1,y,f);
762 mprintf((0,"screenshot error, couldn't write to %s (err %i)\n",savename,errno));
769 mprintf((0,"screenshot error, couldn't open %s (err %i)\n",savename,errno));
772 void save_screen_shot(int automap_flag)
776 static int savenum=0;
780 if (!ogl_readpixels_ok){
782 hud_message(MSGC_GAME_FEEDBACK,"glReadPixels not supported on your configuration");
788 //added/changed on 10/31/98 by Victor Rachels to fix overwrite each new game
789 if ( savenum == 9999 ) savenum = 0;
790 sprintf(savename,"scrn%04d.tga",savenum++);
792 while(!access(savename,0))
794 if ( savenum == 9999 ) savenum = 0;
795 sprintf(savename,"scrn%04d.tga",savenum++);
797 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
798 //end this section addition/change - Victor Rachels
801 // save_font = grd_curcanv->cv_font;
802 // gr_set_curfont(GAME_FONT);
803 // gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
804 // gr_get_string_size(message,&w,&h,&aw);
805 // modex_print_message(32, 2, message);
807 hud_message(MSGC_GAME_FEEDBACK,message);
810 buf = d_malloc(grd_curscreen->sc_w*grd_curscreen->sc_h*3);
811 glReadBuffer(GL_FRONT);
812 glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
813 write_bmp(savename,grd_curscreen->sc_w,grd_curscreen->sc_h,buf);