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>
52 #if defined(__APPLE__) && defined(__MACH__)
53 #include <OpenGL/glu.h>
54 #undef GL_ARB_multitexture // hack!
61 int vid_installed = 0;
64 void gr_palette_clear(); // Function prototype for gr_init;
71 int vid_check_fullscreen(void)
73 return ogl_fullscreen;
77 static void do_fullscreen(int f)
80 ogl_fullscreen=1;//force fullscreen mode on voodoos.
84 ogl_do_fullscreen_internal();
89 int vid_toggle_fullscreen(void)
91 do_fullscreen(!ogl_fullscreen);
92 // grd_curscreen->sc_mode=0;//hack to get it to reset screen mode
93 return ogl_fullscreen;
97 int vid_toggle_fullscreen_menu(void)
99 unsigned char *buf=NULL;
101 if (ogl_readpixels_ok){
102 MALLOC(buf,unsigned char,grd_curscreen->sc_w*grd_curscreen->sc_h*3);
103 glReadBuffer(GL_FRONT);
104 glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
107 do_fullscreen(!ogl_fullscreen);
109 if (ogl_readpixels_ok){
110 // glWritePixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
112 glDrawPixels(grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
115 // grd_curscreen->sc_mode=0;//hack to get it to reset screen mode
117 return ogl_fullscreen;
120 void ogl_init_state(void){
121 /* select clearing (background) color */
122 glClearColor(0.0, 0.0, 0.0, 0.0);
123 glShadeModel(GL_SMOOTH);
125 /* initialize viewing values */
126 glMatrixMode(GL_PROJECTION);
128 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
129 glScalef(1.0, -1.0, 1.0);
130 glTranslatef(0.0, -1.0, 0.0);
131 gr_palette_step_up(0,0,0);//in case its left over from in game
134 int last_screen_mode=-1;
136 void ogl_set_screen_mode(void){
137 if (last_screen_mode==Screen_mode)
139 OGL_VIEWPORT(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h);
140 // 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);
141 if (Screen_mode==SCREEN_GAME){
142 glDrawBuffer(GL_BACK);
144 glClearColor(0.0, 0.0, 0.0, 0.0);
145 glDrawBuffer(GL_FRONT);
146 glClear(GL_COLOR_BUFFER_BIT);
147 glMatrixMode(GL_PROJECTION);
148 glLoadIdentity();//clear matrix
149 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
150 glMatrixMode(GL_MODELVIEW);
151 glLoadIdentity();//clear matrix
153 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
155 last_screen_mode=Screen_mode;
162 if(Screen_mode != SCREEN_GAME){
168 const char *gl_vendor, *gl_renderer, *gl_version, *gl_extensions;
170 void ogl_get_verinfo(void)
172 long t, sgi_max_textures = -1;
173 GLint arb_max_textures = -1;
174 #ifdef GL_NV_register_combiners
175 long nv_register_combiners = -1;
177 float anisotropic_max = 0;
179 gl_vendor = (const char *) glGetString (GL_VENDOR);
180 gl_renderer = (const char *) glGetString (GL_RENDERER);
181 gl_version = (const char *) glGetString (GL_VERSION);
182 gl_extensions = (const char *) glGetString (GL_EXTENSIONS);
184 con_printf(CON_VERBOSE, "OpenGL: vendor: %s\nOpenGL: renderer: %s\nOpenGL: version: %s\n",gl_vendor,gl_renderer,gl_version);
186 ogl_intensity4_ok = 1;
187 ogl_luminance4_alpha4_ok = 1;
189 ogl_gettexlevelparam_ok = 1;
190 ogl_setgammaramp_ok = 1;
193 dglMultiTexCoord2fARB = (glMultiTexCoord2fARB_fp)wglGetProcAddress("glMultiTexCoord2fARB");
194 dglActiveTextureARB = (glActiveTextureARB_fp)wglGetProcAddress("glActiveTextureARB");
195 dglMultiTexCoord2fSGIS = (glMultiTexCoord2fSGIS_fp)wglGetProcAddress("glMultiTexCoord2fSGIS");
196 dglSelectTextureSGIS = (glSelectTextureSGIS_fp)wglGetProcAddress("glSelectTextureSGIS");
197 dglColorTableEXT = (glColorTableEXT_fp)wglGetProcAddress("glColorTableEXT");
198 dglCombinerParameteriNV = (glCombinerParameteriNV_fp)wglGetProcAddress("glCombinerParameteriNV");
199 dglCombinerInputNV = (glCombinerInputNV_fp)wglGetProcAddress("glCombinerInputNV");
200 dglCombinerOutputNV = (glCombinerOutputNV_fp)wglGetProcAddress("glCombinerOutputNV");
201 dglFinalCombinerInputNV = (glFinalCombinerInputNV_fp)wglGetProcAddress("glFinalCombinerInputNV");
204 #ifdef GL_ARB_multitexture
205 ogl_arb_multitexture_ok = (strstr(gl_extensions, "GL_ARB_multitexture") != 0 && glActiveTextureARB != 0);
206 mprintf((0,"c:%p d:%p e:%p\n",strstr(gl_extensions,"GL_ARB_multitexture"),glActiveTextureARB,glBegin));
208 #ifdef GL_SGIS_multitexture
209 ogl_sgis_multitexture_ok = (strstr(gl_extensions, "GL_SGIS_multitexture") != 0 && glSelectTextureSGIS != 0);
210 mprintf((0,"a:%p b:%p\n",strstr(gl_extensions,"GL_SGIS_multitexture"),glSelectTextureSGIS));
212 ogl_nv_texture_env_combine4_ok = (strstr(gl_extensions, "GL_NV_texture_env_combine4") != 0);
213 #ifdef GL_NV_register_combiners
214 ogl_nv_register_combiners_ok=(strstr(gl_extensions,"GL_NV_register_combiners")!=0 && glCombinerOutputNV!=0);
217 ogl_ext_texture_filter_anisotropic_ok = (strstr(gl_extensions, "GL_EXT_texture_filter_anisotropic") != 0);
218 if (ogl_ext_texture_filter_anisotropic_ok)
219 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_max);
221 #ifdef GL_EXT_paletted_texture
222 ogl_paletted_texture_ok = (strstr(gl_extensions, "GL_EXT_paletted_texture") != 0 && glColorTableEXT != 0);
223 ogl_shared_palette_ok = (strstr(gl_extensions, "GL_EXT_shared_texture_palette") != 0 && ogl_paletted_texture_ok);
225 //add driver specific hacks here. whee.
226 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){
227 ogl_intensity4_ok=0;//ignores alpha, always black background instead of transparent.
228 ogl_readpixels_ok=0;//either just returns all black, or kills the X server entirely
229 ogl_gettexlevelparam_ok=0;//returns random data..
231 if (stricmp(gl_vendor,"Matrox Graphics Inc.")==0){
232 //displays garbage. reported by
233 // redomen@crcwnet.com (render="Matrox G400" version="1.1.3 5.52.015")
234 // orulz (Matrox G200)
238 if (stricmp(gl_renderer,"3dfx Voodoo 3")==0){ // strangely, includes Voodoo 2
239 ogl_gettexlevelparam_ok=0; // Always returns 0
243 //allow overriding of stuff.
244 #ifdef GL_ARB_multitexture
245 if ((t=FindArg("-gl_arb_multitexture_ok"))){
246 ogl_arb_multitexture_ok=atoi(Args[t+1]);
248 if (ogl_arb_multitexture_ok)
249 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &arb_max_textures);
251 #ifdef GL_SGIS_multitexture
252 if ((t=FindArg("-gl_sgis_multitexture_ok"))){
253 ogl_sgis_multitexture_ok=atoi(Args[t+1]);
255 if (ogl_sgis_multitexture_ok)
256 glGetIntegerv(GL_MAX_TEXTURES_SGIS, &sgi_max_textures);
258 #ifdef GL_NV_register_combiners
259 if ((t = FindArg("-gl_nv_register_combiners_ok")))
261 ogl_nv_register_combiners_ok=atoi(Args[t + 1]);
263 if (ogl_nv_register_combiners_ok)
264 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &nv_register_combiners);
266 #ifdef GL_EXT_paletted_texture
267 if ((t = FindArg("-gl_paletted_texture_ok")))
269 ogl_paletted_texture_ok = atoi(Args[t + 1]);
271 if ((t = FindArg("-gl_shared_palette_ok")))
273 ogl_shared_palette_ok = atoi(Args[t + 1]);
275 ogl_shared_palette_ok = ogl_shared_palette_ok && ogl_paletted_texture_ok; // shared palettes require palette support in the first place, obviously ;)
276 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);
278 if ((t=FindArg("-gl_intensity4_ok"))){
279 ogl_intensity4_ok=atoi(Args[t+1]);
281 if ((t=FindArg("-gl_luminance4_alpha4_ok"))){
282 ogl_luminance4_alpha4_ok=atoi(Args[t+1]);
284 if ((t=FindArg("-gl_rgba2_ok"))){
285 ogl_rgba2_ok=atoi(Args[t+1]);
287 if ((t=FindArg("-gl_readpixels_ok"))){
288 ogl_readpixels_ok=atoi(Args[t+1]);
290 if ((t=FindArg("-gl_gettexlevelparam_ok"))){
291 ogl_gettexlevelparam_ok=atoi(Args[t+1]);
293 if ((t=FindArg("-gl_setgammaramp_ok")))
295 ogl_setgammaramp_ok = atoi(Args[t + 1]);
298 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);
299 #ifdef GL_NV_register_combiners
300 con_printf(CON_DEBUG, "gl_nv_register_combiners:%i(%i stages)\n", ogl_nv_register_combiners_ok, nv_register_combiners);
302 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);
306 int vid_check_mode(uint32_t mode)
312 return ogl_check_mode(w, h); // platform specific code
316 uint32_t Vid_current_mode;
319 int vid_set_mode(uint32_t mode)
330 if (mode == Vid_current_mode)
335 Vid_current_mode = mode;
337 //if (screen != NULL) gr_palette_clear();
341 gr_init_screen(BM_OGL, w, h, 0, 0, w, NULL);
343 //gr_enable_default_palette_loading();
345 ogl_init_window(w,h);//platform specific code
349 OGL_VIEWPORT(0,0,w,h);
351 ogl_set_screen_mode();
353 // gamefont_choose_game_font(w,h);
358 #define GLstrcmptestr(a,b) if (stricmp(a,#b)==0 || stricmp(a,"GL_" #b)==0)return GL_ ## b;
359 int ogl_atotexfilti(char *a,int min){
360 GLstrcmptestr(a,NEAREST);
361 GLstrcmptestr(a,LINEAR);
362 if (min){//mipmaps are valid only for the min filter
363 GLstrcmptestr(a,NEAREST_MIPMAP_NEAREST);
364 GLstrcmptestr(a,NEAREST_MIPMAP_LINEAR);
365 GLstrcmptestr(a,LINEAR_MIPMAP_NEAREST);
366 GLstrcmptestr(a,LINEAR_MIPMAP_LINEAR);
368 Error("unknown/invalid texture filter %s\n",a);
369 // return GL_NEAREST;
371 int ogl_testneedmipmaps(int i){
376 case GL_NEAREST_MIPMAP_NEAREST:
377 case GL_NEAREST_MIPMAP_LINEAR:
378 case GL_LINEAR_MIPMAP_NEAREST:
379 case GL_LINEAR_MIPMAP_LINEAR:
382 Error("unknown texture filter %x\n",i);
387 void ogl_cmd_texturemode(int argc, char **argv)
392 if (!stricmp(argv[1], "GL_NEAREST")) {
393 GL_texminfilt = GL_NEAREST;
394 GL_texmagfilt = GL_NEAREST;
395 } else if (!stricmp(argv[1], "GL_LINEAR")) {
396 GL_texminfilt = GL_LINEAR;
397 GL_texmagfilt = GL_LINEAR;
398 } else if (!stricmp(argv[1], "GL_NEAREST_MIPMAP_NEAREST")) {
399 GL_texminfilt = GL_NEAREST_MIPMAP_NEAREST;
400 GL_texmagfilt = GL_NEAREST;
401 } else if (!stricmp(argv[1], "GL_LINEAR_MIPMAP_NEAREST")) {
402 GL_texminfilt = GL_LINEAR_MIPMAP_NEAREST;
403 GL_texmagfilt = GL_LINEAR;
404 } else if (!stricmp(argv[1], "GL_NEAREST_MIPMAP_LINEAR")) {
405 GL_texminfilt = GL_NEAREST_MIPMAP_LINEAR;
406 GL_texmagfilt = GL_NEAREST;
407 } else if (!stricmp(argv[1], "GL_LINEAR_MIPMAP_LINEAR")) {
408 GL_texminfilt = GL_LINEAR_MIPMAP_LINEAR;
409 GL_texmagfilt = GL_LINEAR;
413 GL_needmipmaps=ogl_testneedmipmaps(GL_texminfilt);
415 ogl_smash_texture_list_internal();
419 #ifdef OGL_RUNTIME_LOAD
421 char *OglLibPath="opengl32.dll";
424 char *OglLibPath="libGL.so";
427 char *OglLibPath = NULL;
431 int ogl_init_load_library(void)
436 if ((t=FindArg("-gl_library")))
437 OglLibPath=Args[t+1];
439 retcode = OpenGL_LoadLibrary(true);
442 mprintf((0,"Opengl loaded ok\n"));
446 Error("Opengl: Functions not imported\n");
449 Error("Opengl: error loading %s\n", OglLibPath? OglLibPath : SDL_GetError());
462 // Only do this function once!
463 if (vid_installed == 1)
467 #ifdef OGL_RUNTIME_LOAD
468 ogl_init_load_library();
471 #ifdef VID_SUPPORTS_FULLSCREEN_TOGGLE
472 if (FindArg("-gl_voodoo")){
474 vid_toggle_fullscreen();
476 if (FindArg("-fullscreen"))
477 vid_toggle_fullscreen();
479 if ((glt=FindArg("-gl_alttexmerge")))
481 if ((t=FindArg("-gl_stdtexmerge")))
482 if (t>=glt)//allow overriding of earlier args
485 if ((glt = FindArg("-gl_16bittextures")))
487 ogl_rgba_internalformat = GL_RGB5_A1;
488 ogl_rgb_internalformat = GL_RGB5;
491 if ((glt=FindArg("-gl_mipmap"))){
492 GL_texmagfilt=GL_LINEAR;
493 GL_texminfilt=GL_LINEAR_MIPMAP_NEAREST;
495 if ((glt=FindArg("-gl_trilinear")))
497 GL_texmagfilt = GL_LINEAR;
498 GL_texminfilt = GL_LINEAR_MIPMAP_LINEAR;
500 if ((t=FindArg("-gl_simple"))){
501 if (t>=glt){//allow overriding of earlier args
503 GL_texmagfilt=GL_NEAREST;
504 GL_texminfilt=GL_NEAREST;
507 if ((t=FindArg("-gl_texmagfilt")) || (t=FindArg("-gl_texmagfilter"))){
508 if (t>=glt)//allow overriding of earlier args
509 GL_texmagfilt=ogl_atotexfilti(Args[t+1],0);
511 if ((t=FindArg("-gl_texminfilt")) || (t=FindArg("-gl_texminfilter"))){
512 if (t>=glt)//allow overriding of earlier args
513 GL_texminfilt=ogl_atotexfilti(Args[t+1],1);
515 GL_needmipmaps=ogl_testneedmipmaps(GL_texminfilt);
517 if ((t = FindArg("-gl_anisotropy")) || (t = FindArg("-gl_anisotropic")))
519 GL_texanisofilt=atof(Args[t + 1]);
522 mprintf((0,"gr_init: texmagfilt:%x texminfilt:%x needmipmaps=%i anisotropic:%f\n",GL_texmagfilt,GL_texminfilt,GL_needmipmaps,GL_texanisofilt));
525 if ((t=FindArg("-gl_vidmem"))){
526 ogl_mem_target=atoi(Args[t+1])*1024*1024;
528 if ((t=FindArg("-gl_reticle"))){
529 gl_reticle=atoi(Args[t+1]);
531 //printf("ogl_mem_target=%i\n",ogl_mem_target);
533 ogl_init();//platform specific initialization
535 ogl_init_texture_list_internal();
537 cmd_addcommand("gl_texturemode", ogl_cmd_texturemode);
549 // mprintf((0,"ogl init: %s %s %s - %s\n",glGetString(GL_VENDOR),glGetString(GL_RENDERER),glGetString(GL_VERSION),glGetString,(GL_EXTENSIONS)));
550 ogl_brightness_r = ogl_brightness_g = ogl_brightness_b = 0;
551 ogl_setbrightness_internal();
553 ogl_close();//platform specific code
555 #ifdef OGL_RUNTIME_LOAD
557 OpenGL_LoadLibrary(false);
560 extern int r_upixelc;
561 void ogl_upixelc(int x, int y, int c){
563 // printf("gr_upixelc(%i,%i,%i)%i\n",x,y,c,Function_mode==FMODE_GAME);
564 // if(Function_mode != FMODE_GAME){
565 // grd_curcanv->cv_bitmap.bm_data[y*grd_curscreen->sc_canvas.cv_bitmap.bm_w+x]=c;
567 OGL_DISABLE(TEXTURE_2D);
570 // glBegin(GL_LINES);
571 // ogl_pal=gr_current_pal;
572 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
573 // ogl_pal=gr_palette;
574 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);
575 // glVertex2f(x/((float)last_width+1),1.0-y/((float)last_height+1));
579 void ogl_urect(int left,int top,int right,int bot){
583 xo=(left+grd_curcanv->cv_bitmap.bm_x)/(float)last_width;
584 xf = (right + 1 + grd_curcanv->cv_bitmap.bm_x) / (float)last_width;
585 yo=1.0-(top+grd_curcanv->cv_bitmap.bm_y)/(float)last_height;
586 yf = 1.0 - (bot + 1 + grd_curcanv->cv_bitmap.bm_y) / (float)last_height;
588 OGL_DISABLE(TEXTURE_2D);
589 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS)
590 glColor3f(CPAL2Tr(c), CPAL2Tg(c), CPAL2Tb(c));
592 glColor4f(CPAL2Tr(c), CPAL2Tg(c), CPAL2Tb(c), 1.0 - (float)Gr_scanline_darkening_level / ((float)GR_FADE_LEVELS - 1.0));
600 void ogl_ulinec(int left,int top,int right,int bot,int c){
603 xo = (left + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
604 xf = (right + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
605 yo = 1.0 - (top + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
606 yf = 1.0 - (bot + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
608 OGL_DISABLE(TEXTURE_2D);
609 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
617 GLfloat last_r=0, last_g=0, last_b=0;
619 void ogl_do_palfx(void){
621 OGL_DISABLE(TEXTURE_2D);
622 if (gr_palette_faded_out){
623 /* glEnable(GL_BLEND);
624 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
629 //glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
631 glBlendFunc(GL_ONE,GL_ONE);
632 glColor3f(last_r,last_g,last_b);
633 // r=f2fl(last_r);g=f2fl(last_g);b=f2fl(last_b);a=0.5;
647 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
650 void gr_palette_clear()
652 gr_palette_faded_out=1;
656 int ogl_brightness_ok = 0;
657 int ogl_setgammaramp_ok = 1;
658 int ogl_brightness_r = 0, ogl_brightness_g = 0, ogl_brightness_b = 0;
659 static int old_b_r = 0, old_b_g = 0, old_b_b = 0;
661 void gr_palette_step_up(int r, int g, int b)
663 if (gr_palette_faded_out)
666 old_b_r = ogl_brightness_r;
667 old_b_g = ogl_brightness_g;
668 old_b_b = ogl_brightness_b;
670 ogl_brightness_r = max(r + gr_palette_gamma.intval, 0);
671 ogl_brightness_g = max(g + gr_palette_gamma.intval, 0);
672 ogl_brightness_b = max(b + gr_palette_gamma.intval, 0);
674 if (ogl_setgammaramp_ok &&
675 (old_b_r != ogl_brightness_r ||
676 old_b_g != ogl_brightness_g ||
677 old_b_b != ogl_brightness_b))
678 ogl_brightness_ok = !ogl_setbrightness_internal();
680 if (!ogl_setgammaramp_ok || !ogl_brightness_ok)
682 last_r = ogl_brightness_r / 63.0;
683 last_g = ogl_brightness_g / 63.0;
684 last_b = ogl_brightness_b / 63.0;
686 do_pal_step = (r || g || b || gr_palette_gamma.intval);
695 void gr_palette_load( ubyte *pal )
699 for (i=0; i<768; i++ ) {
700 gr_current_pal[i] = pal[i];
701 if (gr_current_pal[i] > 63) gr_current_pal[i] = 63;
703 //palette = screen->format->palette;
705 gr_palette_faded_out=0;
707 gr_palette_step_up(0, 0, 0); // make ogl_setbrightness_internal get run so that menus get brightened too.
709 init_computed_colors();
711 ogl_init_shared_palette();
716 int gr_palette_fade_out(ubyte *pal, int nsteps, int allow_keys)
721 if (gr_palette_faded_out) return 0;
723 if (grd_fades_disabled || !ogl_readpixels_ok) {
724 gr_palette_faded_out = 1;
728 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
730 glDisable(GL_DEPTH_TEST);
732 MALLOC(buf, unsigned char, grd_curscreen->sc_w * grd_curscreen->sc_h * 3);
733 glReadBuffer(GL_FRONT);
734 glReadPixels(0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
736 for (j = 0; j < nsteps; j++) {
738 glDrawPixels(grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
740 glColor4f(0.0, 0.0, 0.0, (float)(j) / (nsteps - 1)); // go from 0 to 1
750 timer_delay(f0_1 / 10);
754 gr_palette_faded_out=1;
760 int gr_palette_fade_in(ubyte *pal, int nsteps, int allow_keys)
765 if (!gr_palette_faded_out) return 0;
767 if (grd_fades_disabled || !ogl_readpixels_ok) {
768 gr_palette_faded_out = 0;
772 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
774 glDisable(GL_DEPTH_TEST);
776 MALLOC(buf, unsigned char, grd_curscreen->sc_w * grd_curscreen->sc_h * 3);
777 glReadBuffer(GL_FRONT);
778 glReadPixels(0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
780 for (j = 0; j < nsteps; j++) {
782 glDrawPixels(grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
784 glColor4f(0.0, 0.0, 0.0, (float)(nsteps - 1 - j) / (nsteps - 1)); // go from 1 to 0
794 timer_delay(f0_1 / 10);
798 gr_palette_faded_out=0;
804 void gr_palette_read(ubyte * pal)
807 for (i=0; i<768; i++ ) {
808 pal[i]=gr_current_pal[i];
809 if (pal[i] > 63) pal[i] = 63;
813 //writes out an uncompressed RGB .tga file
814 //if we got really spiffy, we could optionally link in libpng or something, and use that.
815 void write_bmp(char *savename,int w,int h,unsigned char *buf){
818 f = PHYSFSX_openWriteBuffered(savename);
821 GLubyte targaMagic[12] = { 0, //no identification field
823 2,//RGB image (well, BGR, actually)
824 0, 0, 0, 0, 0, 0, 0, 0, 0 };//no colormap or image origin stuff.
831 PHYSFS_write(f, targaMagic, sizeof(targaMagic), 1);
832 PHYSFS_writeSLE16(f, w);
833 PHYSFS_writeSLE16(f, h);
834 PHYSFSX_writeU8(f, 24); // 24 bpp
835 PHYSFSX_writeU8(f, 0); // no attribute bits, origin is lowerleft, no interleave
838 for (y=0;y<h;y++){//TGAs use BGR ordering of data.
849 r = (int)PHYSFS_write(f, buf + x, 1, y);
851 mprintf((0,"screenshot error, couldn't write to %s (err %i)\n",savename,errno));
858 mprintf((0,"screenshot error, couldn't open %s (err %i)\n",savename,errno));
861 void save_screen_shot(int automap_flag)
865 static int savenum=0;
869 if (!ogl_readpixels_ok){
871 hud_message(MSGC_GAME_FEEDBACK,"glReadPixels not supported on your configuration");
877 //added/changed on 10/31/98 by Victor Rachels to fix overwrite each new game
882 sprintf(savename, "scrn%04d.tga", savenum++);
883 } while (PHYSFS_exists(savename));
885 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
886 //end this section addition/change - Victor Rachels
889 // save_font = grd_curcanv->cv_font;
890 // gr_set_curfont(GAME_FONT);
891 // gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
892 // gr_get_string_size(message,&w,&h,&aw);
893 // modex_print_message(32, 2, message);
895 hud_message(MSGC_GAME_FEEDBACK, "%s", message);
898 buf = d_malloc(grd_curscreen->sc_w*grd_curscreen->sc_h*3);
899 glReadBuffer(GL_FRONT);
900 glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
901 write_bmp(savename,grd_curscreen->sc_w,grd_curscreen->sc_h,buf);