3 * OGL video functions. - Added 9/15/99 Matthew Mueller
19 #if !defined(_MSC_VER) && !defined(macintosh)
22 #if !defined(macintosh)
23 #include <sys/types.h>
44 #if defined(__APPLE__) && defined(__MACH__)
45 #include <OpenGL/glu.h>
46 #undef GL_ARB_multitexture // hack!
54 int vid_installed = 0;
57 void gr_palette_clear(); // Function prototype for gr_init;
64 int vid_check_fullscreen(void)
66 return ogl_fullscreen;
70 static void do_fullscreen(int f)
73 ogl_fullscreen=1;//force fullscreen mode on voodoos.
77 ogl_do_fullscreen_internal();
82 int vid_toggle_fullscreen(void)
84 do_fullscreen(!ogl_fullscreen);
85 // grd_curscreen->sc_mode=0;//hack to get it to reset screen mode
86 return ogl_fullscreen;
90 int vid_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 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 long t, sgi_max_textures = -1;
166 GLint arb_max_textures = -1;
167 #ifdef GL_NV_register_combiners
168 long nv_register_combiners = -1;
170 float anisotropic_max = 0;
172 gl_vendor = (const char *) glGetString (GL_VENDOR);
173 gl_renderer = (const char *) glGetString (GL_RENDERER);
174 gl_version = (const char *) glGetString (GL_VERSION);
175 gl_extensions = (const char *) glGetString (GL_EXTENSIONS);
177 con_printf(CON_VERBOSE, "OpenGL: vendor: %s\nOpenGL: renderer: %s\nOpenGL: version: %s\n",gl_vendor,gl_renderer,gl_version);
179 ogl_intensity4_ok = 1;
180 ogl_luminance4_alpha4_ok = 1;
182 ogl_gettexlevelparam_ok = 1;
183 ogl_setgammaramp_ok = 1;
186 dglMultiTexCoord2fARB = (glMultiTexCoord2fARB_fp)wglGetProcAddress("glMultiTexCoord2fARB");
187 dglActiveTextureARB = (glActiveTextureARB_fp)wglGetProcAddress("glActiveTextureARB");
188 dglMultiTexCoord2fSGIS = (glMultiTexCoord2fSGIS_fp)wglGetProcAddress("glMultiTexCoord2fSGIS");
189 dglSelectTextureSGIS = (glSelectTextureSGIS_fp)wglGetProcAddress("glSelectTextureSGIS");
190 dglColorTableEXT = (glColorTableEXT_fp)wglGetProcAddress("glColorTableEXT");
191 dglCombinerParameteriNV = (glCombinerParameteriNV_fp)wglGetProcAddress("glCombinerParameteriNV");
192 dglCombinerInputNV = (glCombinerInputNV_fp)wglGetProcAddress("glCombinerInputNV");
193 dglCombinerOutputNV = (glCombinerOutputNV_fp)wglGetProcAddress("glCombinerOutputNV");
194 dglFinalCombinerInputNV = (glFinalCombinerInputNV_fp)wglGetProcAddress("glFinalCombinerInputNV");
197 #ifdef GL_ARB_multitexture
198 ogl_arb_multitexture_ok = (strstr(gl_extensions, "GL_ARB_multitexture") != 0 && glActiveTextureARB != 0);
199 mprintf((0,"c:%p d:%p e:%p\n",strstr(gl_extensions,"GL_ARB_multitexture"),glActiveTextureARB,glBegin));
201 #ifdef GL_SGIS_multitexture
202 ogl_sgis_multitexture_ok = (strstr(gl_extensions, "GL_SGIS_multitexture") != 0 && glSelectTextureSGIS != 0);
203 mprintf((0,"a:%p b:%p\n",strstr(gl_extensions,"GL_SGIS_multitexture"),glSelectTextureSGIS));
205 ogl_nv_texture_env_combine4_ok = (strstr(gl_extensions, "GL_NV_texture_env_combine4") != 0);
206 #ifdef GL_NV_register_combiners
207 ogl_nv_register_combiners_ok=(strstr(gl_extensions,"GL_NV_register_combiners")!=0 && glCombinerOutputNV!=0);
210 ogl_ext_texture_filter_anisotropic_ok = (strstr(gl_extensions, "GL_EXT_texture_filter_anisotropic") != 0);
211 if (ogl_ext_texture_filter_anisotropic_ok)
212 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_max);
214 #ifdef GL_EXT_paletted_texture
215 ogl_paletted_texture_ok = (strstr(gl_extensions, "GL_EXT_paletted_texture") != 0 && glColorTableEXT != 0);
216 ogl_shared_palette_ok = (strstr(gl_extensions, "GL_EXT_shared_texture_palette") != 0 && ogl_paletted_texture_ok);
218 //add driver specific hacks here. whee.
219 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){
220 ogl_intensity4_ok=0;//ignores alpha, always black background instead of transparent.
221 ogl_readpixels_ok=0;//either just returns all black, or kills the X server entirely
222 ogl_gettexlevelparam_ok=0;//returns random data..
224 if (stricmp(gl_vendor,"Matrox Graphics Inc.")==0){
225 //displays garbage. reported by
226 // redomen@crcwnet.com (render="Matrox G400" version="1.1.3 5.52.015")
227 // orulz (Matrox G200)
231 if (stricmp(gl_renderer,"3dfx Voodoo 3")==0){ // strangely, includes Voodoo 2
232 ogl_gettexlevelparam_ok=0; // Always returns 0
236 //allow overriding of stuff.
237 #ifdef GL_ARB_multitexture
238 if ((t=FindArg("-gl_arb_multitexture_ok"))){
239 ogl_arb_multitexture_ok=atoi(Args[t+1]);
241 if (ogl_arb_multitexture_ok)
242 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &arb_max_textures);
244 #ifdef GL_SGIS_multitexture
245 if ((t=FindArg("-gl_sgis_multitexture_ok"))){
246 ogl_sgis_multitexture_ok=atoi(Args[t+1]);
248 if (ogl_sgis_multitexture_ok)
249 glGetIntegerv(GL_MAX_TEXTURES_SGIS, &sgi_max_textures);
251 #ifdef GL_NV_register_combiners
252 if ((t = FindArg("-gl_nv_register_combiners_ok")))
254 ogl_nv_register_combiners_ok=atoi(Args[t + 1]);
256 if (ogl_nv_register_combiners_ok)
257 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &nv_register_combiners);
259 #ifdef GL_EXT_paletted_texture
260 if ((t = FindArg("-gl_paletted_texture_ok")))
262 ogl_paletted_texture_ok = atoi(Args[t + 1]);
264 if ((t = FindArg("-gl_shared_palette_ok")))
266 ogl_shared_palette_ok = atoi(Args[t + 1]);
268 ogl_shared_palette_ok = ogl_shared_palette_ok && ogl_paletted_texture_ok; // shared palettes require palette support in the first place, obviously ;)
269 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);
271 if ((t=FindArg("-gl_intensity4_ok"))){
272 ogl_intensity4_ok=atoi(Args[t+1]);
274 if ((t=FindArg("-gl_luminance4_alpha4_ok"))){
275 ogl_luminance4_alpha4_ok=atoi(Args[t+1]);
277 if ((t=FindArg("-gl_rgba2_ok"))){
278 ogl_rgba2_ok=atoi(Args[t+1]);
280 if ((t=FindArg("-gl_readpixels_ok"))){
281 ogl_readpixels_ok=atoi(Args[t+1]);
283 if ((t=FindArg("-gl_gettexlevelparam_ok"))){
284 ogl_gettexlevelparam_ok=atoi(Args[t+1]);
286 if ((t=FindArg("-gl_setgammaramp_ok")))
288 ogl_setgammaramp_ok = atoi(Args[t + 1]);
291 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);
292 #ifdef GL_NV_register_combiners
293 con_printf(CON_DEBUG, "gl_nv_register_combiners:%i(%i stages)\n", ogl_nv_register_combiners_ok, nv_register_combiners);
295 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);
299 int vid_check_mode(uint32_t mode)
305 return ogl_check_mode(w, h); // platform specific code
309 uint32_t Vid_current_mode;
312 int vid_set_mode(uint32_t mode)
323 if (mode == Vid_current_mode)
328 Vid_current_mode = mode;
330 //if (screen != NULL) gr_palette_clear();
334 gr_init_screen(BM_OGL, w, h, 0, 0, w, NULL);
336 //gr_enable_default_palette_loading();
338 ogl_init_window(w,h);//platform specific code
342 OGL_VIEWPORT(0,0,w,h);
344 ogl_set_screen_mode();
346 // gamefont_choose_game_font(w,h);
351 #define GLstrcmptestr(a,b) if (stricmp(a,#b)==0 || stricmp(a,"GL_" #b)==0)return GL_ ## b;
352 int ogl_atotexfilti(char *a,int min){
353 GLstrcmptestr(a,NEAREST);
354 GLstrcmptestr(a,LINEAR);
355 if (min){//mipmaps are valid only for the min filter
356 GLstrcmptestr(a,NEAREST_MIPMAP_NEAREST);
357 GLstrcmptestr(a,NEAREST_MIPMAP_LINEAR);
358 GLstrcmptestr(a,LINEAR_MIPMAP_NEAREST);
359 GLstrcmptestr(a,LINEAR_MIPMAP_LINEAR);
361 Error("unknown/invalid texture filter %s\n",a);
362 // return GL_NEAREST;
364 int ogl_testneedmipmaps(int i){
369 case GL_NEAREST_MIPMAP_NEAREST:
370 case GL_NEAREST_MIPMAP_LINEAR:
371 case GL_LINEAR_MIPMAP_NEAREST:
372 case GL_LINEAR_MIPMAP_LINEAR:
375 Error("unknown texture filter %x\n",i);
380 void ogl_cmd_texturemode(int argc, char **argv)
385 if (!stricmp(argv[1], "GL_NEAREST")) {
386 GL_texminfilt = GL_NEAREST;
387 GL_texmagfilt = GL_NEAREST;
388 } else if (!stricmp(argv[1], "GL_LINEAR")) {
389 GL_texminfilt = GL_LINEAR;
390 GL_texmagfilt = GL_LINEAR;
391 } else if (!stricmp(argv[1], "GL_NEAREST_MIPMAP_NEAREST")) {
392 GL_texminfilt = GL_NEAREST_MIPMAP_NEAREST;
393 GL_texmagfilt = GL_NEAREST;
394 } else if (!stricmp(argv[1], "GL_LINEAR_MIPMAP_NEAREST")) {
395 GL_texminfilt = GL_LINEAR_MIPMAP_NEAREST;
396 GL_texmagfilt = GL_LINEAR;
397 } else if (!stricmp(argv[1], "GL_NEAREST_MIPMAP_LINEAR")) {
398 GL_texminfilt = GL_NEAREST_MIPMAP_LINEAR;
399 GL_texmagfilt = GL_NEAREST;
400 } else if (!stricmp(argv[1], "GL_LINEAR_MIPMAP_LINEAR")) {
401 GL_texminfilt = GL_LINEAR_MIPMAP_LINEAR;
402 GL_texmagfilt = GL_LINEAR;
406 GL_needmipmaps=ogl_testneedmipmaps(GL_texminfilt);
408 ogl_smash_texture_list_internal();
412 #ifdef OGL_RUNTIME_LOAD
414 char *OglLibPath="opengl32.dll";
417 char *OglLibPath="libGL.so";
420 char *OglLibPath = NULL;
424 int ogl_init_load_library(void)
429 if ((t=FindArg("-gl_library")))
430 OglLibPath=Args[t+1];
432 retcode = OpenGL_LoadLibrary(true);
435 mprintf((0,"Opengl loaded ok\n"));
439 Error("Opengl: Functions not imported\n");
442 Error("Opengl: error loading %s\n", OglLibPath? OglLibPath : SDL_GetError());
455 // Only do this function once!
456 if (vid_installed == 1)
460 #ifdef OGL_RUNTIME_LOAD
461 ogl_init_load_library();
464 #ifdef VID_SUPPORTS_FULLSCREEN_TOGGLE
465 if (FindArg("-gl_voodoo")){
467 vid_toggle_fullscreen();
469 if (FindArg("-fullscreen"))
470 vid_toggle_fullscreen();
472 if ((glt=FindArg("-gl_alttexmerge")))
474 if ((t=FindArg("-gl_stdtexmerge")))
475 if (t>=glt)//allow overriding of earlier args
478 if ((glt = FindArg("-gl_16bittextures")))
480 ogl_rgba_internalformat = GL_RGB5_A1;
481 ogl_rgb_internalformat = GL_RGB5;
484 if ((glt=FindArg("-gl_mipmap"))){
485 GL_texmagfilt=GL_LINEAR;
486 GL_texminfilt=GL_LINEAR_MIPMAP_NEAREST;
488 if ((glt=FindArg("-gl_trilinear")))
490 GL_texmagfilt = GL_LINEAR;
491 GL_texminfilt = GL_LINEAR_MIPMAP_LINEAR;
493 if ((t=FindArg("-gl_simple"))){
494 if (t>=glt){//allow overriding of earlier args
496 GL_texmagfilt=GL_NEAREST;
497 GL_texminfilt=GL_NEAREST;
500 if ((t=FindArg("-gl_texmagfilt")) || (t=FindArg("-gl_texmagfilter"))){
501 if (t>=glt)//allow overriding of earlier args
502 GL_texmagfilt=ogl_atotexfilti(Args[t+1],0);
504 if ((t=FindArg("-gl_texminfilt")) || (t=FindArg("-gl_texminfilter"))){
505 if (t>=glt)//allow overriding of earlier args
506 GL_texminfilt=ogl_atotexfilti(Args[t+1],1);
508 GL_needmipmaps=ogl_testneedmipmaps(GL_texminfilt);
510 if ((t = FindArg("-gl_anisotropy")) || (t = FindArg("-gl_anisotropic")))
512 GL_texanisofilt=atof(Args[t + 1]);
515 mprintf((0,"gr_init: texmagfilt:%x texminfilt:%x needmipmaps=%i anisotropic:%f\n",GL_texmagfilt,GL_texminfilt,GL_needmipmaps,GL_texanisofilt));
518 if ((t=FindArg("-gl_vidmem"))){
519 ogl_mem_target=atoi(Args[t+1])*1024*1024;
521 if ((t=FindArg("-gl_reticle"))){
522 gl_reticle=atoi(Args[t+1]);
524 //printf("ogl_mem_target=%i\n",ogl_mem_target);
526 ogl_init();//platform specific initialization
528 ogl_init_texture_list_internal();
530 cmd_addcommand("gl_texturemode", ogl_cmd_texturemode);
542 // mprintf((0,"ogl init: %s %s %s - %s\n",glGetString(GL_VENDOR),glGetString(GL_RENDERER),glGetString(GL_VERSION),glGetString,(GL_EXTENSIONS)));
543 ogl_brightness_r = ogl_brightness_g = ogl_brightness_b = 0;
544 ogl_setbrightness_internal();
546 ogl_close();//platform specific code
548 #ifdef OGL_RUNTIME_LOAD
550 OpenGL_LoadLibrary(false);
553 extern int r_upixelc;
554 void ogl_upixelc(int x, int y, int c){
556 // printf("gr_upixelc(%i,%i,%i)%i\n",x,y,c,Function_mode==FMODE_GAME);
557 // if(Function_mode != FMODE_GAME){
558 // grd_curcanv->cv_bitmap.bm_data[y*grd_curscreen->sc_canvas.cv_bitmap.bm_w+x]=c;
560 OGL_DISABLE(TEXTURE_2D);
563 // glBegin(GL_LINES);
564 // ogl_pal=gr_current_pal;
565 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
566 // ogl_pal=gr_palette;
567 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);
568 // glVertex2f(x/((float)last_width+1),1.0-y/((float)last_height+1));
572 void ogl_urect(int left,int top,int right,int bot){
576 xo=(left+grd_curcanv->cv_bitmap.bm_x)/(float)last_width;
577 xf = (right + 1 + grd_curcanv->cv_bitmap.bm_x) / (float)last_width;
578 yo=1.0-(top+grd_curcanv->cv_bitmap.bm_y)/(float)last_height;
579 yf = 1.0 - (bot + 1 + grd_curcanv->cv_bitmap.bm_y) / (float)last_height;
581 OGL_DISABLE(TEXTURE_2D);
582 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS)
583 glColor3f(CPAL2Tr(c), CPAL2Tg(c), CPAL2Tb(c));
585 glColor4f(CPAL2Tr(c), CPAL2Tg(c), CPAL2Tb(c), 1.0 - (float)Gr_scanline_darkening_level / ((float)GR_FADE_LEVELS - 1.0));
593 void ogl_ulinec(int left,int top,int right,int bot,int c){
596 xo = (left + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
597 xf = (right + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
598 yo = 1.0 - (top + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
599 yf = 1.0 - (bot + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
601 OGL_DISABLE(TEXTURE_2D);
602 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
610 GLfloat last_r=0, last_g=0, last_b=0;
612 void ogl_do_palfx(void){
614 OGL_DISABLE(TEXTURE_2D);
615 if (gr_palette_faded_out){
616 /* glEnable(GL_BLEND);
617 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
622 //glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
624 glBlendFunc(GL_ONE,GL_ONE);
625 glColor3f(last_r,last_g,last_b);
626 // r=f2fl(last_r);g=f2fl(last_g);b=f2fl(last_b);a=0.5;
640 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
643 void gr_palette_clear()
645 gr_palette_faded_out=1;
649 int ogl_brightness_ok = 0;
650 int ogl_setgammaramp_ok = 1;
651 int ogl_brightness_r = 0, ogl_brightness_g = 0, ogl_brightness_b = 0;
652 static int old_b_r = 0, old_b_g = 0, old_b_b = 0;
654 void gr_palette_step_up(int r, int g, int b)
656 if (gr_palette_faded_out)
659 old_b_r = ogl_brightness_r;
660 old_b_g = ogl_brightness_g;
661 old_b_b = ogl_brightness_b;
663 ogl_brightness_r = max(r + gr_palette_gamma.intval, 0);
664 ogl_brightness_g = max(g + gr_palette_gamma.intval, 0);
665 ogl_brightness_b = max(b + gr_palette_gamma.intval, 0);
667 if (ogl_setgammaramp_ok &&
668 (old_b_r != ogl_brightness_r ||
669 old_b_g != ogl_brightness_g ||
670 old_b_b != ogl_brightness_b))
671 ogl_brightness_ok = !ogl_setbrightness_internal();
673 if (!ogl_setgammaramp_ok || !ogl_brightness_ok)
675 last_r = ogl_brightness_r / 63.0;
676 last_g = ogl_brightness_g / 63.0;
677 last_b = ogl_brightness_b / 63.0;
679 do_pal_step = (r || g || b || gr_palette_gamma.intval);
688 void gr_palette_load( ubyte *pal )
692 for (i=0; i<768; i++ ) {
693 gr_current_pal[i] = pal[i];
694 if (gr_current_pal[i] > 63) gr_current_pal[i] = 63;
696 //palette = screen->format->palette;
698 gr_palette_faded_out=0;
700 gr_palette_step_up(0, 0, 0); // make ogl_setbrightness_internal get run so that menus get brightened too.
702 init_computed_colors();
704 ogl_init_shared_palette();
709 int gr_palette_fade_out(ubyte *pal, int nsteps, int allow_keys)
714 if (gr_palette_faded_out) return 0;
716 if (grd_fades_disabled || !ogl_readpixels_ok) {
717 gr_palette_faded_out = 1;
721 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
723 glDisable(GL_DEPTH_TEST);
725 MALLOC(buf, unsigned char, grd_curscreen->sc_w * grd_curscreen->sc_h * 3);
726 glReadBuffer(GL_FRONT);
727 glReadPixels(0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
729 for (j = 0; j < nsteps; j++) {
731 glDrawPixels(grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
733 glColor4f(0.0, 0.0, 0.0, (float)(j) / (nsteps - 1)); // go from 0 to 1
743 timer_delay(f0_1 / 10);
747 gr_palette_faded_out=1;
753 int gr_palette_fade_in(ubyte *pal, int nsteps, int allow_keys)
758 if (!gr_palette_faded_out) return 0;
760 if (grd_fades_disabled || !ogl_readpixels_ok) {
761 gr_palette_faded_out = 0;
765 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
767 glDisable(GL_DEPTH_TEST);
769 MALLOC(buf, unsigned char, grd_curscreen->sc_w * grd_curscreen->sc_h * 3);
770 glReadBuffer(GL_FRONT);
771 glReadPixels(0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
773 for (j = 0; j < nsteps; j++) {
775 glDrawPixels(grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
777 glColor4f(0.0, 0.0, 0.0, (float)(nsteps - 1 - j) / (nsteps - 1)); // go from 1 to 0
787 timer_delay(f0_1 / 10);
791 gr_palette_faded_out=0;
797 void gr_palette_read(ubyte * pal)
800 for (i=0; i<768; i++ ) {
801 pal[i]=gr_current_pal[i];
802 if (pal[i] > 63) pal[i] = 63;
806 //writes out an uncompressed RGB .tga file
807 //if we got really spiffy, we could optionally link in libpng or something, and use that.
808 void write_bmp(char *savename,int w,int h,unsigned char *buf){
811 f = PHYSFSX_openWriteBuffered(savename);
814 GLubyte targaMagic[12] = { 0, //no identification field
816 2,//RGB image (well, BGR, actually)
817 0, 0, 0, 0, 0, 0, 0, 0, 0 };//no colormap or image origin stuff.
824 PHYSFS_write(f, targaMagic, sizeof(targaMagic), 1);
825 PHYSFS_writeSLE16(f, w);
826 PHYSFS_writeSLE16(f, h);
827 PHYSFSX_writeU8(f, 24); // 24 bpp
828 PHYSFSX_writeU8(f, 0); // no attribute bits, origin is lowerleft, no interleave
831 for (y=0;y<h;y++){//TGAs use BGR ordering of data.
842 r = (int)PHYSFS_write(f, buf + x, 1, y);
844 mprintf((0,"screenshot error, couldn't write to %s (err %i)\n",savename,errno));
851 mprintf((0,"screenshot error, couldn't open %s (err %i)\n",savename,errno));
854 void save_screen_shot(int automap_flag)
858 static int savenum=0;
862 if (!ogl_readpixels_ok){
864 hud_message(MSGC_GAME_FEEDBACK,"glReadPixels not supported on your configuration");
870 //added/changed on 10/31/98 by Victor Rachels to fix overwrite each new game
875 sprintf(savename, "scrn%04d.tga", savenum++);
876 } while (PHYSFS_exists(savename));
878 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
879 //end this section addition/change - Victor Rachels
882 // save_font = grd_curcanv->cv_font;
883 // gr_set_curfont(GAME_FONT);
884 // gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
885 // gr_get_string_size(message,&w,&h,&aw);
886 // modex_print_message(32, 2, message);
888 hud_message(MSGC_GAME_FEEDBACK, "%s", message);
891 buf = d_malloc(grd_curscreen->sc_w*grd_curscreen->sc_h*3);
892 glReadBuffer(GL_FRONT);
893 glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
894 write_bmp(savename,grd_curscreen->sc_w,grd_curscreen->sc_h,buf);