3 * OGL video functions. - Added 9/15/99 Matthew Mueller
21 #if !defined(_MSC_VER) && !defined(macintosh)
24 #if !defined(macintosh)
25 #include <sys/types.h>
45 #if defined(__APPLE__) && defined(__MACH__)
46 #include <OpenGL/glu.h>
47 #undef GL_ARB_multitexture // hack!
55 int vid_installed = 0;
58 void gr_palette_clear(); // Function prototype for gr_init;
65 int vid_check_fullscreen(void)
67 return ogl_fullscreen;
71 static void do_fullscreen(int f)
74 ogl_fullscreen=1;//force fullscreen mode on voodoos.
78 ogl_do_fullscreen_internal();
83 int vid_toggle_fullscreen(void)
85 do_fullscreen(!ogl_fullscreen);
86 // grd_curscreen->sc_mode=0;//hack to get it to reset screen mode
87 return ogl_fullscreen;
91 int vid_toggle_fullscreen_menu(void)
93 unsigned char *buf=NULL;
95 if (ogl_readpixels_ok){
96 MALLOC(buf,unsigned char,grd_curscreen->sc_w*grd_curscreen->sc_h*3);
97 glReadBuffer(GL_FRONT);
98 glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
101 do_fullscreen(!ogl_fullscreen);
103 if (ogl_readpixels_ok){
104 // glWritePixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
106 glDrawPixels(grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
109 // grd_curscreen->sc_mode=0;//hack to get it to reset screen mode
111 return ogl_fullscreen;
114 void ogl_init_state(void){
115 /* select clearing (background) color */
116 glClearColor(0.0, 0.0, 0.0, 0.0);
117 glShadeModel(GL_SMOOTH);
119 /* initialize viewing values */
120 glMatrixMode(GL_PROJECTION);
122 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
123 glScalef(1.0, -1.0, 1.0);
124 glTranslatef(0.0, -1.0, 0.0);
125 gr_palette_step_up(0,0,0);//in case its left over from in game
128 int last_screen_mode=-1;
130 void ogl_set_screen_mode(void){
131 if (last_screen_mode==Screen_mode)
133 OGL_VIEWPORT(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h);
134 // 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);
135 if (Screen_mode==SCREEN_GAME){
136 glDrawBuffer(GL_BACK);
138 glClearColor(0.0, 0.0, 0.0, 0.0);
139 glDrawBuffer(GL_FRONT);
140 glClear(GL_COLOR_BUFFER_BIT);
141 glMatrixMode(GL_PROJECTION);
142 glLoadIdentity();//clear matrix
143 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
144 glMatrixMode(GL_MODELVIEW);
145 glLoadIdentity();//clear matrix
147 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
149 last_screen_mode=Screen_mode;
156 if(Screen_mode != SCREEN_GAME){
162 const char *gl_vendor, *gl_renderer, *gl_version, *gl_extensions;
164 void ogl_get_verinfo(void)
166 long t, sgi_max_textures = -1;
167 GLint arb_max_textures = -1;
168 #ifdef GL_NV_register_combiners
169 GLint nv_register_combiners = -1;
171 float anisotropic_max = 0;
173 gl_vendor = (const char *) glGetString (GL_VENDOR);
174 gl_renderer = (const char *) glGetString (GL_RENDERER);
175 gl_version = (const char *) glGetString (GL_VERSION);
176 gl_extensions = (const char *) glGetString (GL_EXTENSIONS);
178 con_printf(CON_VERBOSE, "OpenGL: vendor: %s\nOpenGL: renderer: %s\nOpenGL: version: %s\n",gl_vendor,gl_renderer,gl_version);
180 ogl_intensity4_ok = 1;
181 ogl_luminance4_alpha4_ok = 1;
183 ogl_gettexlevelparam_ok = 1;
184 ogl_setgammaramp_ok = 1;
187 dglMultiTexCoord2fARB = (glMultiTexCoord2fARB_fp)wglGetProcAddress("glMultiTexCoord2fARB");
188 dglActiveTextureARB = (glActiveTextureARB_fp)wglGetProcAddress("glActiveTextureARB");
189 dglMultiTexCoord2fSGIS = (glMultiTexCoord2fSGIS_fp)wglGetProcAddress("glMultiTexCoord2fSGIS");
190 dglSelectTextureSGIS = (glSelectTextureSGIS_fp)wglGetProcAddress("glSelectTextureSGIS");
191 dglColorTableEXT = (glColorTableEXT_fp)wglGetProcAddress("glColorTableEXT");
192 dglCombinerParameteriNV = (glCombinerParameteriNV_fp)wglGetProcAddress("glCombinerParameteriNV");
193 dglCombinerInputNV = (glCombinerInputNV_fp)wglGetProcAddress("glCombinerInputNV");
194 dglCombinerOutputNV = (glCombinerOutputNV_fp)wglGetProcAddress("glCombinerOutputNV");
195 dglFinalCombinerInputNV = (glFinalCombinerInputNV_fp)wglGetProcAddress("glFinalCombinerInputNV");
198 #ifdef GL_ARB_multitexture
199 ogl_arb_multitexture_ok = (strstr(gl_extensions, "GL_ARB_multitexture") != 0 && glActiveTextureARB != 0);
200 mprintf((0,"c:%p d:%p e:%p\n",strstr(gl_extensions,"GL_ARB_multitexture"),glActiveTextureARB,glBegin));
202 #ifdef GL_SGIS_multitexture
203 ogl_sgis_multitexture_ok = (strstr(gl_extensions, "GL_SGIS_multitexture") != 0 && glSelectTextureSGIS != 0);
204 mprintf((0,"a:%p b:%p\n",strstr(gl_extensions,"GL_SGIS_multitexture"),glSelectTextureSGIS));
206 ogl_nv_texture_env_combine4_ok = (strstr(gl_extensions, "GL_NV_texture_env_combine4") != 0);
207 #ifdef GL_NV_register_combiners
208 ogl_nv_register_combiners_ok=(strstr(gl_extensions,"GL_NV_register_combiners")!=0 && glCombinerOutputNV!=0);
211 ogl_ext_texture_filter_anisotropic_ok = (strstr(gl_extensions, "GL_EXT_texture_filter_anisotropic") != 0);
212 if (ogl_ext_texture_filter_anisotropic_ok)
213 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_max);
215 #ifdef GL_EXT_paletted_texture
216 ogl_paletted_texture_ok = (strstr(gl_extensions, "GL_EXT_paletted_texture") != 0 && glColorTableEXT != 0);
217 ogl_shared_palette_ok = (strstr(gl_extensions, "GL_EXT_shared_texture_palette") != 0 && ogl_paletted_texture_ok);
219 //add driver specific hacks here. whee.
220 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){
221 ogl_intensity4_ok=0;//ignores alpha, always black background instead of transparent.
222 ogl_readpixels_ok=0;//either just returns all black, or kills the X server entirely
223 ogl_gettexlevelparam_ok=0;//returns random data..
225 if (stricmp(gl_vendor,"Matrox Graphics Inc.")==0){
226 //displays garbage. reported by
227 // redomen@crcwnet.com (render="Matrox G400" version="1.1.3 5.52.015")
228 // orulz (Matrox G200)
232 if (stricmp(gl_renderer,"3dfx Voodoo 3")==0){ // strangely, includes Voodoo 2
233 ogl_gettexlevelparam_ok=0; // Always returns 0
237 //allow overriding of stuff.
238 #ifdef GL_ARB_multitexture
239 if ((t=FindArg("-gl_arb_multitexture_ok"))){
240 ogl_arb_multitexture_ok=atoi(Args[t+1]);
242 if (ogl_arb_multitexture_ok)
243 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &arb_max_textures);
245 #ifdef GL_SGIS_multitexture
246 if ((t=FindArg("-gl_sgis_multitexture_ok"))){
247 ogl_sgis_multitexture_ok=atoi(Args[t+1]);
249 if (ogl_sgis_multitexture_ok)
250 glGetIntegerv(GL_MAX_TEXTURES_SGIS, &sgi_max_textures);
252 #ifdef GL_NV_register_combiners
253 if ((t = FindArg("-gl_nv_register_combiners_ok")))
255 ogl_nv_register_combiners_ok=atoi(Args[t + 1]);
257 if (ogl_nv_register_combiners_ok)
258 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &nv_register_combiners);
260 #ifdef GL_EXT_paletted_texture
261 if ((t = FindArg("-gl_paletted_texture_ok")))
263 ogl_paletted_texture_ok = atoi(Args[t + 1]);
265 if ((t = FindArg("-gl_shared_palette_ok")))
267 ogl_shared_palette_ok = atoi(Args[t + 1]);
269 ogl_shared_palette_ok = ogl_shared_palette_ok && ogl_paletted_texture_ok; // shared palettes require palette support in the first place, obviously ;)
270 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);
272 if ((t=FindArg("-gl_intensity4_ok"))){
273 ogl_intensity4_ok=atoi(Args[t+1]);
275 if ((t=FindArg("-gl_luminance4_alpha4_ok"))){
276 ogl_luminance4_alpha4_ok=atoi(Args[t+1]);
278 if ((t=FindArg("-gl_rgba2_ok"))){
279 ogl_rgba2_ok=atoi(Args[t+1]);
281 if ((t=FindArg("-gl_readpixels_ok"))){
282 ogl_readpixels_ok=atoi(Args[t+1]);
284 if ((t=FindArg("-gl_gettexlevelparam_ok"))){
285 ogl_gettexlevelparam_ok=atoi(Args[t+1]);
287 if ((t=FindArg("-gl_setgammaramp_ok")))
289 ogl_setgammaramp_ok = atoi(Args[t + 1]);
292 con_printf(CON_DEBUG, "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);
293 #ifdef GL_NV_register_combiners
294 con_printf(CON_DEBUG, "gl_nv_register_combiners:%i(%i stages)\n", ogl_nv_register_combiners_ok, nv_register_combiners);
296 con_printf(CON_DEBUG, "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);
300 int vid_check_mode(uint32_t mode)
306 return ogl_check_mode(w, h); // platform specific code
310 uint32_t Vid_current_mode;
313 int vid_set_mode(uint32_t mode)
324 if (mode == Vid_current_mode)
329 Vid_current_mode = mode;
331 //if (screen != NULL) gr_palette_clear();
335 gr_init_screen(BM_OGL, w, h, 0, 0, w, NULL);
337 //gr_enable_default_palette_loading();
339 ogl_init_window(w,h);//platform specific code
343 OGL_VIEWPORT(0,0,w,h);
345 ogl_set_screen_mode();
347 // gamefont_choose_game_font(w,h);
352 #define GLstrcmptestr(a,b) if (stricmp(a,#b)==0 || stricmp(a,"GL_" #b)==0)return GL_ ## b;
353 int ogl_atotexfilti(char *a,int min){
354 GLstrcmptestr(a,NEAREST);
355 GLstrcmptestr(a,LINEAR);
356 if (min){//mipmaps are valid only for the min filter
357 GLstrcmptestr(a,NEAREST_MIPMAP_NEAREST);
358 GLstrcmptestr(a,NEAREST_MIPMAP_LINEAR);
359 GLstrcmptestr(a,LINEAR_MIPMAP_NEAREST);
360 GLstrcmptestr(a,LINEAR_MIPMAP_LINEAR);
362 Error("unknown/invalid texture filter %s\n",a);
363 // return GL_NEAREST;
365 int ogl_testneedmipmaps(int i){
370 case GL_NEAREST_MIPMAP_NEAREST:
371 case GL_NEAREST_MIPMAP_LINEAR:
372 case GL_LINEAR_MIPMAP_NEAREST:
373 case GL_LINEAR_MIPMAP_LINEAR:
376 Error("unknown texture filter %x\n",i);
381 void ogl_cmd_texturemode(int argc, char **argv)
384 cmd_insertf("help %s", argv[0]);
388 if (!stricmp(argv[1], "GL_NEAREST")) {
389 GL_texminfilt = GL_NEAREST;
390 GL_texmagfilt = GL_NEAREST;
391 } else if (!stricmp(argv[1], "GL_LINEAR")) {
392 GL_texminfilt = GL_LINEAR;
393 GL_texmagfilt = GL_LINEAR;
394 } else if (!stricmp(argv[1], "GL_NEAREST_MIPMAP_NEAREST")) {
395 GL_texminfilt = GL_NEAREST_MIPMAP_NEAREST;
396 GL_texmagfilt = GL_NEAREST;
397 } else if (!stricmp(argv[1], "GL_LINEAR_MIPMAP_NEAREST")) {
398 GL_texminfilt = GL_LINEAR_MIPMAP_NEAREST;
399 GL_texmagfilt = GL_LINEAR;
400 } else if (!stricmp(argv[1], "GL_NEAREST_MIPMAP_LINEAR")) {
401 GL_texminfilt = GL_NEAREST_MIPMAP_LINEAR;
402 GL_texmagfilt = GL_NEAREST;
403 } else if (!stricmp(argv[1], "GL_LINEAR_MIPMAP_LINEAR")) {
404 GL_texminfilt = GL_LINEAR_MIPMAP_LINEAR;
405 GL_texmagfilt = GL_LINEAR;
409 GL_needmipmaps=ogl_testneedmipmaps(GL_texminfilt);
411 ogl_smash_texture_list_internal();
416 char *OglLibPath="opengl32.dll";
419 int ogl_init_load_library(void)
423 retcode = OpenGL_LoadLibrary(true);
426 mprintf((0,"Opengl loaded ok\n"));
430 Error("Opengl: Functions not imported\n");
433 Error("Opengl: error loading %s\n", OglLibPath);
446 // Only do this function once!
447 if (vid_installed == 1)
451 ogl_init_load_library();
454 #ifdef VID_SUPPORTS_FULLSCREEN_TOGGLE
455 if (FindArg("-gl_voodoo")){
457 vid_toggle_fullscreen();
459 if (FindArg("-fullscreen"))
460 vid_toggle_fullscreen();
462 if ((glt=FindArg("-gl_alttexmerge")))
464 if ((t=FindArg("-gl_stdtexmerge")))
465 if (t>=glt)//allow overriding of earlier args
468 if ((glt = FindArg("-gl_16bittextures")))
470 ogl_rgba_internalformat = GL_RGB5_A1;
471 ogl_rgb_internalformat = GL_RGB5;
474 if ((glt=FindArg("-gl_mipmap"))){
475 GL_texmagfilt=GL_LINEAR;
476 GL_texminfilt=GL_LINEAR_MIPMAP_NEAREST;
478 if ((glt=FindArg("-gl_trilinear")))
480 GL_texmagfilt = GL_LINEAR;
481 GL_texminfilt = GL_LINEAR_MIPMAP_LINEAR;
483 if ((t=FindArg("-gl_simple"))){
484 if (t>=glt){//allow overriding of earlier args
486 GL_texmagfilt=GL_NEAREST;
487 GL_texminfilt=GL_NEAREST;
490 if ((t=FindArg("-gl_texmagfilt")) || (t=FindArg("-gl_texmagfilter"))){
491 if (t>=glt)//allow overriding of earlier args
492 GL_texmagfilt=ogl_atotexfilti(Args[t+1],0);
494 if ((t=FindArg("-gl_texminfilt")) || (t=FindArg("-gl_texminfilter"))){
495 if (t>=glt)//allow overriding of earlier args
496 GL_texminfilt=ogl_atotexfilti(Args[t+1],1);
498 GL_needmipmaps=ogl_testneedmipmaps(GL_texminfilt);
500 if ((t = FindArg("-gl_anisotropy")) || (t = FindArg("-gl_anisotropic")))
502 GL_texanisofilt=atof(Args[t + 1]);
505 mprintf((0,"gr_init: texmagfilt:%x texminfilt:%x needmipmaps=%i anisotropic:%f\n",GL_texmagfilt,GL_texminfilt,GL_needmipmaps,GL_texanisofilt));
508 if ((t=FindArg("-gl_vidmem"))){
509 ogl_mem_target=atoi(Args[t+1])*1024*1024;
511 if ((t=FindArg("-gl_reticle"))){
512 gl_reticle=atoi(Args[t+1]);
514 //printf("ogl_mem_target=%i\n",ogl_mem_target);
516 ogl_init();//platform specific initialization
518 ogl_init_texture_list_internal();
520 cmd_addcommand("gl_texturemode", ogl_cmd_texturemode, "gl_texturemode <x>\n" " use OpenGL texture mode <x>. Available mode are\n"
523 " GL_NEAREST_MIPMAP_NEAREST\n"
524 " GL_LINEAR_MIPMAP_NEAREST\n"
525 " GL_NEAREST_MIPMAP_LINEAR\n"
526 " GL_LINEAR_MIPMAP_LINEAR");
538 // mprintf((0,"ogl init: %s %s %s - %s\n",glGetString(GL_VENDOR),glGetString(GL_RENDERER),glGetString(GL_VERSION),glGetString,(GL_EXTENSIONS)));
539 ogl_brightness_r = ogl_brightness_g = ogl_brightness_b = 0;
540 ogl_setbrightness_internal();
542 ogl_close();//platform specific code
546 OpenGL_LoadLibrary(false);
549 extern int r_upixelc;
550 void ogl_upixelc(int x, int y, int c){
552 // printf("gr_upixelc(%i,%i,%i)%i\n",x,y,c,Function_mode==FMODE_GAME);
553 // if(Function_mode != FMODE_GAME){
554 // grd_curcanv->cv_bitmap.bm_data[y*grd_curscreen->sc_canvas.cv_bitmap.bm_w+x]=c;
556 OGL_DISABLE(TEXTURE_2D);
559 // glBegin(GL_LINES);
560 // ogl_pal=gr_current_pal;
561 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
562 // ogl_pal=gr_palette;
563 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);
564 // glVertex2f(x/((float)last_width+1),1.0-y/((float)last_height+1));
568 void ogl_urect(int left,int top,int right,int bot){
572 xo=(left+grd_curcanv->cv_bitmap.bm_x)/(float)last_width;
573 xf = (right + 1 + grd_curcanv->cv_bitmap.bm_x) / (float)last_width;
574 yo=1.0-(top+grd_curcanv->cv_bitmap.bm_y)/(float)last_height;
575 yf = 1.0 - (bot + 1 + grd_curcanv->cv_bitmap.bm_y) / (float)last_height;
577 OGL_DISABLE(TEXTURE_2D);
578 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS)
579 glColor3f(CPAL2Tr(c), CPAL2Tg(c), CPAL2Tb(c));
581 glColor4f(CPAL2Tr(c), CPAL2Tg(c), CPAL2Tb(c), 1.0 - (float)Gr_scanline_darkening_level / ((float)GR_FADE_LEVELS - 1.0));
589 void ogl_ulinec(int left,int top,int right,int bot,int c){
592 xo = (left + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
593 xf = (right + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
594 yo = 1.0 - (top + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
595 yf = 1.0 - (bot + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
597 OGL_DISABLE(TEXTURE_2D);
598 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
606 GLfloat last_r=0, last_g=0, last_b=0;
608 void ogl_do_palfx(void){
610 OGL_DISABLE(TEXTURE_2D);
611 if (gr_palette_faded_out){
612 /* glEnable(GL_BLEND);
613 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
618 //glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
620 glBlendFunc(GL_ONE,GL_ONE);
621 glColor3f(last_r,last_g,last_b);
622 // r=f2fl(last_r);g=f2fl(last_g);b=f2fl(last_b);a=0.5;
636 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
639 void gr_palette_clear()
641 gr_palette_faded_out=1;
645 int ogl_brightness_ok = 0;
646 int ogl_setgammaramp_ok = 1;
647 int ogl_brightness_r = 0, ogl_brightness_g = 0, ogl_brightness_b = 0;
648 static int old_b_r = 0, old_b_g = 0, old_b_b = 0;
650 void gr_palette_step_up(int r, int g, int b)
652 if (gr_palette_faded_out)
655 old_b_r = ogl_brightness_r;
656 old_b_g = ogl_brightness_g;
657 old_b_b = ogl_brightness_b;
659 ogl_brightness_r = max(r + gr_palette_gamma.intval, 0);
660 ogl_brightness_g = max(g + gr_palette_gamma.intval, 0);
661 ogl_brightness_b = max(b + gr_palette_gamma.intval, 0);
663 if (ogl_setgammaramp_ok &&
664 (old_b_r != ogl_brightness_r ||
665 old_b_g != ogl_brightness_g ||
666 old_b_b != ogl_brightness_b))
667 ogl_brightness_ok = !ogl_setbrightness_internal();
669 if (!ogl_setgammaramp_ok || !ogl_brightness_ok)
671 last_r = ogl_brightness_r / 63.0;
672 last_g = ogl_brightness_g / 63.0;
673 last_b = ogl_brightness_b / 63.0;
675 do_pal_step = (r || g || b || gr_palette_gamma.intval);
684 void gr_palette_load( ubyte *pal )
688 for (i=0; i<768; i++ ) {
689 gr_current_pal[i] = pal[i];
690 if (gr_current_pal[i] > 63) gr_current_pal[i] = 63;
692 //palette = screen->format->palette;
694 gr_palette_faded_out=0;
696 gr_palette_step_up(0, 0, 0); // make ogl_setbrightness_internal get run so that menus get brightened too.
698 init_computed_colors();
700 ogl_init_shared_palette();
705 int gr_palette_fade_out(ubyte *pal, int nsteps, int allow_keys)
710 if (gr_palette_faded_out) return 0;
712 if (grd_fades_disabled || !ogl_readpixels_ok) {
713 gr_palette_faded_out = 1;
717 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
719 glDisable(GL_DEPTH_TEST);
721 MALLOC(buf, unsigned char, grd_curscreen->sc_w * grd_curscreen->sc_h * 3);
722 glReadBuffer(GL_FRONT);
723 glReadPixels(0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
725 for (j = 0; j < nsteps; j++) {
727 glDrawPixels(grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
729 glColor4f(0.0, 0.0, 0.0, (float)(j) / (nsteps - 1)); // go from 0 to 1
739 timer_delay(f0_1 / 10);
743 gr_palette_faded_out=1;
749 int gr_palette_fade_in(ubyte *pal, int nsteps, int allow_keys)
754 if (!gr_palette_faded_out) return 0;
756 if (grd_fades_disabled || !ogl_readpixels_ok) {
757 gr_palette_faded_out = 0;
761 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
763 glDisable(GL_DEPTH_TEST);
765 MALLOC(buf, unsigned char, grd_curscreen->sc_w * grd_curscreen->sc_h * 3);
766 glReadBuffer(GL_FRONT);
767 glReadPixels(0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
769 for (j = 0; j < nsteps; j++) {
771 glDrawPixels(grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
773 glColor4f(0.0, 0.0, 0.0, (float)(nsteps - 1 - j) / (nsteps - 1)); // go from 1 to 0
783 timer_delay(f0_1 / 10);
787 gr_palette_faded_out=0;
793 void gr_palette_read(ubyte * pal)
796 for (i=0; i<768; i++ ) {
797 pal[i]=gr_current_pal[i];
798 if (pal[i] > 63) pal[i] = 63;
802 //writes out an uncompressed RGB .tga file
803 //if we got really spiffy, we could optionally link in libpng or something, and use that.
804 void write_bmp(char *savename,int w,int h,unsigned char *buf){
807 f = PHYSFSX_openWriteBuffered(savename);
810 GLubyte targaMagic[12] = { 0, //no identification field
812 2,//RGB image (well, BGR, actually)
813 0, 0, 0, 0, 0, 0, 0, 0, 0 };//no colormap or image origin stuff.
820 PHYSFS_write(f, targaMagic, sizeof(targaMagic), 1);
821 PHYSFS_writeSLE16(f, w);
822 PHYSFS_writeSLE16(f, h);
823 PHYSFSX_writeU8(f, 24); // 24 bpp
824 PHYSFSX_writeU8(f, 0); // no attribute bits, origin is lowerleft, no interleave
827 for (y=0;y<h;y++){//TGAs use BGR ordering of data.
838 r = (int)PHYSFS_write(f, buf + x, 1, y);
840 mprintf((0,"screenshot error, couldn't write to %s (err %i)\n",savename,errno));
847 mprintf((0,"screenshot error, couldn't open %s (err %i)\n",savename,errno));
850 void save_screen_shot(int automap_flag)
854 static int savenum=0;
858 if (!ogl_readpixels_ok){
860 hud_message(MSGC_GAME_FEEDBACK,"glReadPixels not supported on your configuration");
866 //added/changed on 10/31/98 by Victor Rachels to fix overwrite each new game
871 sprintf(savename, "scrn%04d.tga", savenum++);
872 } while (PHYSFS_exists(savename));
874 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
875 //end this section addition/change - Victor Rachels
878 // save_font = grd_curcanv->cv_font;
879 // gr_set_curfont(GAME_FONT);
880 // gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
881 // gr_get_string_size(message,&w,&h,&aw);
882 // modex_print_message(32, 2, message);
884 hud_message(MSGC_GAME_FEEDBACK, "%s", message);
887 buf = d_malloc(grd_curscreen->sc_w*grd_curscreen->sc_h*3);
888 glReadBuffer(GL_FRONT);
889 glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
890 write_bmp(savename,grd_curscreen->sc_w,grd_curscreen->sc_h,buf);