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(void); // 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)
167 GLint sgi_max_textures = -1;
168 GLint arb_max_textures = -1;
169 #ifdef GL_NV_register_combiners
170 GLint nv_register_combiners = -1;
172 float anisotropic_max = 0;
174 gl_vendor = (const char *) glGetString (GL_VENDOR);
175 gl_renderer = (const char *) glGetString (GL_RENDERER);
176 gl_version = (const char *) glGetString (GL_VERSION);
177 gl_extensions = (const char *) glGetString (GL_EXTENSIONS);
179 con_printf(CON_VERBOSE, "OpenGL: vendor: %s\nOpenGL: renderer: %s\nOpenGL: version: %s\n",gl_vendor,gl_renderer,gl_version);
181 ogl_intensity4_ok = 1;
182 ogl_luminance4_alpha4_ok = 1;
184 ogl_gettexlevelparam_ok = 1;
185 ogl_setgammaramp_ok = 1;
188 dglMultiTexCoord2fARB = (glMultiTexCoord2fARB_fp)wglGetProcAddress("glMultiTexCoord2fARB");
189 dglActiveTextureARB = (glActiveTextureARB_fp)wglGetProcAddress("glActiveTextureARB");
190 dglMultiTexCoord2fSGIS = (glMultiTexCoord2fSGIS_fp)wglGetProcAddress("glMultiTexCoord2fSGIS");
191 dglSelectTextureSGIS = (glSelectTextureSGIS_fp)wglGetProcAddress("glSelectTextureSGIS");
192 dglColorTableEXT = (glColorTableEXT_fp)wglGetProcAddress("glColorTableEXT");
193 dglCombinerParameteriNV = (glCombinerParameteriNV_fp)wglGetProcAddress("glCombinerParameteriNV");
194 dglCombinerInputNV = (glCombinerInputNV_fp)wglGetProcAddress("glCombinerInputNV");
195 dglCombinerOutputNV = (glCombinerOutputNV_fp)wglGetProcAddress("glCombinerOutputNV");
196 dglFinalCombinerInputNV = (glFinalCombinerInputNV_fp)wglGetProcAddress("glFinalCombinerInputNV");
199 #ifdef GL_ARB_multitexture
200 ogl_arb_multitexture_ok = (strstr(gl_extensions, "GL_ARB_multitexture") != 0 && glActiveTextureARB != 0);
201 mprintf((0,"c:%p d:%p e:%p\n",strstr(gl_extensions,"GL_ARB_multitexture"),glActiveTextureARB,glBegin));
203 #ifdef GL_SGIS_multitexture
204 ogl_sgis_multitexture_ok = (strstr(gl_extensions, "GL_SGIS_multitexture") != 0 && glSelectTextureSGIS != 0);
205 mprintf((0,"a:%p b:%p\n",strstr(gl_extensions,"GL_SGIS_multitexture"),glSelectTextureSGIS));
207 ogl_nv_texture_env_combine4_ok = (strstr(gl_extensions, "GL_NV_texture_env_combine4") != 0);
208 #ifdef GL_NV_register_combiners
209 ogl_nv_register_combiners_ok=(strstr(gl_extensions,"GL_NV_register_combiners")!=0 && glCombinerOutputNV!=0);
212 ogl_ext_texture_filter_anisotropic_ok = (strstr(gl_extensions, "GL_EXT_texture_filter_anisotropic") != 0);
213 if (ogl_ext_texture_filter_anisotropic_ok)
214 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_max);
216 #ifdef GL_EXT_paletted_texture
217 ogl_paletted_texture_ok = (strstr(gl_extensions, "GL_EXT_paletted_texture") != 0 && glColorTableEXT != 0);
218 ogl_shared_palette_ok = (strstr(gl_extensions, "GL_EXT_shared_texture_palette") != 0 && ogl_paletted_texture_ok);
220 //add driver specific hacks here. whee.
221 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){
222 ogl_intensity4_ok=0;//ignores alpha, always black background instead of transparent.
223 ogl_readpixels_ok=0;//either just returns all black, or kills the X server entirely
224 ogl_gettexlevelparam_ok=0;//returns random data..
226 if (stricmp(gl_vendor,"Matrox Graphics Inc.")==0){
227 //displays garbage. reported by
228 // redomen@crcwnet.com (render="Matrox G400" version="1.1.3 5.52.015")
229 // orulz (Matrox G200)
233 if (stricmp(gl_renderer,"3dfx Voodoo 3")==0){ // strangely, includes Voodoo 2
234 ogl_gettexlevelparam_ok=0; // Always returns 0
238 //allow overriding of stuff.
239 #ifdef GL_ARB_multitexture
240 if ((t=FindArg("-gl_arb_multitexture_ok"))){
241 ogl_arb_multitexture_ok=atoi(Args[t+1]);
243 if (ogl_arb_multitexture_ok)
244 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &arb_max_textures);
246 #ifdef GL_SGIS_multitexture
247 if ((t=FindArg("-gl_sgis_multitexture_ok"))){
248 ogl_sgis_multitexture_ok=atoi(Args[t+1]);
250 if (ogl_sgis_multitexture_ok)
251 glGetIntegerv(GL_MAX_TEXTURES_SGIS, &sgi_max_textures);
253 #ifdef GL_NV_register_combiners
254 if ((t = FindArg("-gl_nv_register_combiners_ok")))
256 ogl_nv_register_combiners_ok=atoi(Args[t + 1]);
258 if (ogl_nv_register_combiners_ok)
259 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &nv_register_combiners);
261 #ifdef GL_EXT_paletted_texture
262 if ((t = FindArg("-gl_paletted_texture_ok")))
264 ogl_paletted_texture_ok = atoi(Args[t + 1]);
266 if ((t = FindArg("-gl_shared_palette_ok")))
268 ogl_shared_palette_ok = atoi(Args[t + 1]);
270 ogl_shared_palette_ok = ogl_shared_palette_ok && ogl_paletted_texture_ok; // shared palettes require palette support in the first place, obviously ;)
271 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);
273 if ((t=FindArg("-gl_intensity4_ok"))){
274 ogl_intensity4_ok=atoi(Args[t+1]);
276 if ((t=FindArg("-gl_luminance4_alpha4_ok"))){
277 ogl_luminance4_alpha4_ok=atoi(Args[t+1]);
279 if ((t=FindArg("-gl_rgba2_ok"))){
280 ogl_rgba2_ok=atoi(Args[t+1]);
282 if ((t=FindArg("-gl_readpixels_ok"))){
283 ogl_readpixels_ok=atoi(Args[t+1]);
285 if ((t=FindArg("-gl_gettexlevelparam_ok"))){
286 ogl_gettexlevelparam_ok=atoi(Args[t+1]);
288 if ((t=FindArg("-gl_setgammaramp_ok")))
290 ogl_setgammaramp_ok = atoi(Args[t + 1]);
293 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);
294 #ifdef GL_NV_register_combiners
295 con_printf(CON_DEBUG, "gl_nv_register_combiners:%i(%i stages)\n", ogl_nv_register_combiners_ok, nv_register_combiners);
297 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);
301 int vid_check_mode(uint32_t mode)
307 return ogl_check_mode(w, h); // platform specific code
311 uint32_t Vid_current_mode;
314 int vid_set_mode(uint32_t mode)
325 if (mode == Vid_current_mode)
330 Vid_current_mode = mode;
332 //if (screen != NULL) gr_palette_clear();
336 gr_init_screen(BM_OGL, w, h, 0, 0, w, NULL);
338 //gr_enable_default_palette_loading();
340 ogl_init_window(w,h);//platform specific code
344 OGL_VIEWPORT(0,0,w,h);
346 ogl_set_screen_mode();
348 // gamefont_choose_game_font(w,h);
353 #define GLstrcmptestr(a,b) if (stricmp(a,#b)==0 || stricmp(a,"GL_" #b)==0)return GL_ ## b;
354 int ogl_atotexfilti(char *a,int min){
355 GLstrcmptestr(a,NEAREST);
356 GLstrcmptestr(a,LINEAR);
357 if (min){//mipmaps are valid only for the min filter
358 GLstrcmptestr(a,NEAREST_MIPMAP_NEAREST);
359 GLstrcmptestr(a,NEAREST_MIPMAP_LINEAR);
360 GLstrcmptestr(a,LINEAR_MIPMAP_NEAREST);
361 GLstrcmptestr(a,LINEAR_MIPMAP_LINEAR);
363 Error("unknown/invalid texture filter %s\n",a);
364 // return GL_NEAREST;
366 int ogl_testneedmipmaps(int i){
371 case GL_NEAREST_MIPMAP_NEAREST:
372 case GL_NEAREST_MIPMAP_LINEAR:
373 case GL_LINEAR_MIPMAP_NEAREST:
374 case GL_LINEAR_MIPMAP_LINEAR:
377 Error("unknown texture filter %x\n",i);
382 void ogl_cmd_texturemode(int argc, char **argv)
385 cmd_insertf("help %s", argv[0]);
389 if (!stricmp(argv[1], "GL_NEAREST")) {
390 GL_texminfilt = GL_NEAREST;
391 GL_texmagfilt = GL_NEAREST;
392 } else if (!stricmp(argv[1], "GL_LINEAR")) {
393 GL_texminfilt = GL_LINEAR;
394 GL_texmagfilt = GL_LINEAR;
395 } else if (!stricmp(argv[1], "GL_NEAREST_MIPMAP_NEAREST")) {
396 GL_texminfilt = GL_NEAREST_MIPMAP_NEAREST;
397 GL_texmagfilt = GL_NEAREST;
398 } else if (!stricmp(argv[1], "GL_LINEAR_MIPMAP_NEAREST")) {
399 GL_texminfilt = GL_LINEAR_MIPMAP_NEAREST;
400 GL_texmagfilt = GL_LINEAR;
401 } else if (!stricmp(argv[1], "GL_NEAREST_MIPMAP_LINEAR")) {
402 GL_texminfilt = GL_NEAREST_MIPMAP_LINEAR;
403 GL_texmagfilt = GL_NEAREST;
404 } else if (!stricmp(argv[1], "GL_LINEAR_MIPMAP_LINEAR")) {
405 GL_texminfilt = GL_LINEAR_MIPMAP_LINEAR;
406 GL_texmagfilt = GL_LINEAR;
410 GL_needmipmaps=ogl_testneedmipmaps(GL_texminfilt);
412 ogl_smash_texture_list_internal();
417 char *OglLibPath="opengl32.dll";
420 int ogl_init_load_library(void)
424 retcode = OpenGL_LoadLibrary(true);
427 mprintf((0,"Opengl loaded ok\n"));
431 Error("Opengl: Functions not imported\n");
434 Error("Opengl: error loading %s\n", OglLibPath);
447 // Only do this function once!
448 if (vid_installed == 1)
452 ogl_init_load_library();
455 #ifdef VID_SUPPORTS_FULLSCREEN_TOGGLE
456 if (FindArg("-gl_voodoo")){
458 vid_toggle_fullscreen();
460 if (FindArg("-fullscreen"))
461 vid_toggle_fullscreen();
463 if ((glt=FindArg("-gl_alttexmerge")))
465 if ((t=FindArg("-gl_stdtexmerge")))
466 if (t>=glt)//allow overriding of earlier args
469 if ((glt = FindArg("-gl_16bittextures")))
471 ogl_rgba_internalformat = GL_RGB5_A1;
472 ogl_rgb_internalformat = GL_RGB5;
475 if ((glt=FindArg("-gl_mipmap"))){
476 GL_texmagfilt=GL_LINEAR;
477 GL_texminfilt=GL_LINEAR_MIPMAP_NEAREST;
479 if ((glt=FindArg("-gl_trilinear")))
481 GL_texmagfilt = GL_LINEAR;
482 GL_texminfilt = GL_LINEAR_MIPMAP_LINEAR;
484 if ((t=FindArg("-gl_simple"))){
485 if (t>=glt){//allow overriding of earlier args
487 GL_texmagfilt=GL_NEAREST;
488 GL_texminfilt=GL_NEAREST;
491 if ((t=FindArg("-gl_texmagfilt")) || (t=FindArg("-gl_texmagfilter"))){
492 if (t>=glt)//allow overriding of earlier args
493 GL_texmagfilt=ogl_atotexfilti(Args[t+1],0);
495 if ((t=FindArg("-gl_texminfilt")) || (t=FindArg("-gl_texminfilter"))){
496 if (t>=glt)//allow overriding of earlier args
497 GL_texminfilt=ogl_atotexfilti(Args[t+1],1);
499 GL_needmipmaps=ogl_testneedmipmaps(GL_texminfilt);
501 if ((t = FindArg("-gl_anisotropy")) || (t = FindArg("-gl_anisotropic")))
503 GL_texanisofilt=atof(Args[t + 1]);
506 mprintf((0,"gr_init: texmagfilt:%x texminfilt:%x needmipmaps=%i anisotropic:%f\n",GL_texmagfilt,GL_texminfilt,GL_needmipmaps,GL_texanisofilt));
509 if ((t=FindArg("-gl_vidmem"))){
510 ogl_mem_target=atoi(Args[t+1])*1024*1024;
512 if ((t=FindArg("-gl_reticle"))){
513 gl_reticle=atoi(Args[t+1]);
515 //printf("ogl_mem_target=%i\n",ogl_mem_target);
517 ogl_init();//platform specific initialization
519 ogl_init_texture_list_internal();
521 cmd_addcommand("gl_texturemode", ogl_cmd_texturemode, "gl_texturemode <x>\n" " use OpenGL texture mode <x>. Available mode are\n"
524 " GL_NEAREST_MIPMAP_NEAREST\n"
525 " GL_LINEAR_MIPMAP_NEAREST\n"
526 " GL_NEAREST_MIPMAP_LINEAR\n"
527 " GL_LINEAR_MIPMAP_LINEAR");
539 // mprintf((0,"ogl init: %s %s %s - %s\n",glGetString(GL_VENDOR),glGetString(GL_RENDERER),glGetString(GL_VERSION),glGetString,(GL_EXTENSIONS)));
540 ogl_brightness_r = ogl_brightness_g = ogl_brightness_b = 0;
541 ogl_setbrightness_internal();
543 ogl_close();//platform specific code
547 OpenGL_LoadLibrary(false);
550 extern int r_upixelc;
551 void ogl_upixelc(int x, int y, int c){
553 // printf("gr_upixelc(%i,%i,%i)%i\n",x,y,c,Function_mode==FMODE_GAME);
554 // if(Function_mode != FMODE_GAME){
555 // grd_curcanv->cv_bitmap.bm_data[y*grd_curscreen->sc_canvas.cv_bitmap.bm_w+x]=c;
557 OGL_DISABLE(TEXTURE_2D);
560 // glBegin(GL_LINES);
561 // ogl_pal=gr_current_pal;
562 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
563 // ogl_pal=gr_palette;
564 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);
565 // glVertex2f(x/((float)last_width+1),1.0-y/((float)last_height+1));
569 void ogl_urect(int left,int top,int right,int bot){
573 xo=(left+grd_curcanv->cv_bitmap.bm_x)/(float)last_width;
574 xf = (right + 1 + grd_curcanv->cv_bitmap.bm_x) / (float)last_width;
575 yo=1.0-(top+grd_curcanv->cv_bitmap.bm_y)/(float)last_height;
576 yf = 1.0 - (bot + 1 + grd_curcanv->cv_bitmap.bm_y) / (float)last_height;
578 OGL_DISABLE(TEXTURE_2D);
579 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS)
580 glColor3f(CPAL2Tr(c), CPAL2Tg(c), CPAL2Tb(c));
582 glColor4f(CPAL2Tr(c), CPAL2Tg(c), CPAL2Tb(c), 1.0 - (float)Gr_scanline_darkening_level / ((float)GR_FADE_LEVELS - 1.0));
590 void ogl_ulinec(int left,int top,int right,int bot,int c){
593 xo = (left + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
594 xf = (right + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
595 yo = 1.0 - (top + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
596 yf = 1.0 - (bot + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
598 OGL_DISABLE(TEXTURE_2D);
599 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
607 GLfloat last_r=0, last_g=0, last_b=0;
609 void ogl_do_palfx(void){
611 OGL_DISABLE(TEXTURE_2D);
612 if (gr_palette_faded_out){
613 /* glEnable(GL_BLEND);
614 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
619 //glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
621 glBlendFunc(GL_ONE,GL_ONE);
622 glColor3f(last_r,last_g,last_b);
623 // r=f2fl(last_r);g=f2fl(last_g);b=f2fl(last_b);a=0.5;
637 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
640 void gr_palette_clear()
642 gr_palette_faded_out=1;
646 int ogl_brightness_ok = 0;
647 int ogl_setgammaramp_ok = 1;
648 int ogl_brightness_r = 0, ogl_brightness_g = 0, ogl_brightness_b = 0;
649 static int old_b_r = 0, old_b_g = 0, old_b_b = 0;
651 void gr_palette_step_up(int r, int g, int b)
653 if (gr_palette_faded_out)
656 old_b_r = ogl_brightness_r;
657 old_b_g = ogl_brightness_g;
658 old_b_b = ogl_brightness_b;
660 ogl_brightness_r = max(r + gr_palette_gamma.intval, 0);
661 ogl_brightness_g = max(g + gr_palette_gamma.intval, 0);
662 ogl_brightness_b = max(b + gr_palette_gamma.intval, 0);
664 if (ogl_setgammaramp_ok &&
665 (old_b_r != ogl_brightness_r ||
666 old_b_g != ogl_brightness_g ||
667 old_b_b != ogl_brightness_b))
668 ogl_brightness_ok = !ogl_setbrightness_internal();
670 if (!ogl_setgammaramp_ok || !ogl_brightness_ok)
672 last_r = ogl_brightness_r / 63.0;
673 last_g = ogl_brightness_g / 63.0;
674 last_b = ogl_brightness_b / 63.0;
676 do_pal_step = (r || g || b || gr_palette_gamma.intval);
685 void gr_palette_load( ubyte *pal )
689 for (i=0; i<768; i++ ) {
690 gr_current_pal[i] = pal[i];
691 if (gr_current_pal[i] > 63) gr_current_pal[i] = 63;
693 //palette = screen->format->palette;
695 gr_palette_faded_out=0;
697 gr_palette_step_up(0, 0, 0); // make ogl_setbrightness_internal get run so that menus get brightened too.
699 init_computed_colors();
701 ogl_init_shared_palette();
706 int gr_palette_fade_out(ubyte *pal, int nsteps, int allow_keys)
711 if (gr_palette_faded_out) return 0;
713 if (grd_fades_disabled || !ogl_readpixels_ok) {
714 gr_palette_faded_out = 1;
718 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
720 glDisable(GL_DEPTH_TEST);
722 MALLOC(buf, unsigned char, grd_curscreen->sc_w * grd_curscreen->sc_h * 3);
723 glReadBuffer(GL_FRONT);
724 glReadPixels(0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
726 for (j = 0; j < nsteps; j++) {
728 glDrawPixels(grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
730 glColor4f(0.0, 0.0, 0.0, (float)(j) / (nsteps - 1)); // go from 0 to 1
740 timer_delay(f0_1 / 10);
744 gr_palette_faded_out=1;
750 int gr_palette_fade_in(ubyte *pal, int nsteps, int allow_keys)
755 if (!gr_palette_faded_out) return 0;
757 if (grd_fades_disabled || !ogl_readpixels_ok) {
758 gr_palette_faded_out = 0;
762 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
764 glDisable(GL_DEPTH_TEST);
766 MALLOC(buf, unsigned char, grd_curscreen->sc_w * grd_curscreen->sc_h * 3);
767 glReadBuffer(GL_FRONT);
768 glReadPixels(0, 0, grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
770 for (j = 0; j < nsteps; j++) {
772 glDrawPixels(grd_curscreen->sc_w, grd_curscreen->sc_h, GL_RGB, GL_UNSIGNED_BYTE, buf);
774 glColor4f(0.0, 0.0, 0.0, (float)(nsteps - 1 - j) / (nsteps - 1)); // go from 1 to 0
784 timer_delay(f0_1 / 10);
788 gr_palette_faded_out=0;
794 void gr_palette_read(ubyte * pal)
797 for (i=0; i<768; i++ ) {
798 pal[i]=gr_current_pal[i];
799 if (pal[i] > 63) pal[i] = 63;
803 //writes out an uncompressed RGB .tga file
804 //if we got really spiffy, we could optionally link in libpng or something, and use that.
805 void write_bmp(char *savename,int w,int h,unsigned char *buf){
808 f = PHYSFSX_openWriteBuffered(savename);
811 GLubyte targaMagic[12] = { 0, //no identification field
813 2,//RGB image (well, BGR, actually)
814 0, 0, 0, 0, 0, 0, 0, 0, 0 };//no colormap or image origin stuff.
821 PHYSFS_write(f, targaMagic, sizeof(targaMagic), 1);
822 PHYSFS_writeSLE16(f, w);
823 PHYSFS_writeSLE16(f, h);
824 PHYSFSX_writeU8(f, 24); // 24 bpp
825 PHYSFSX_writeU8(f, 0); // no attribute bits, origin is lowerleft, no interleave
828 for (y=0;y<h;y++){//TGAs use BGR ordering of data.
839 r = (int)PHYSFS_write(f, buf + x, 1, y);
841 mprintf((0,"screenshot error, couldn't write to %s (err %i)\n",savename,errno));
848 mprintf((0,"screenshot error, couldn't open %s (err %i)\n",savename,errno));
851 void save_screen_shot(int automap_flag)
855 static int savenum=0;
859 if (!ogl_readpixels_ok){
861 hud_message(MSGC_GAME_FEEDBACK,"glReadPixels not supported on your configuration");
867 //added/changed on 10/31/98 by Victor Rachels to fix overwrite each new game
872 sprintf(savename, "scrn%04d.tga", savenum++);
873 } while (PHYSFS_exists(savename));
875 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
876 //end this section addition/change - Victor Rachels
879 // save_font = grd_curcanv->cv_font;
880 // gr_set_curfont(GAME_FONT);
881 // gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
882 // gr_get_string_size(message,&w,&h,&aw);
883 // modex_print_message(32, 2, message);
885 hud_message(MSGC_GAME_FEEDBACK, "%s", message);
888 buf = d_malloc(grd_curscreen->sc_w*grd_curscreen->sc_h*3);
889 glReadBuffer(GL_FRONT);
890 glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
891 write_bmp(savename,grd_curscreen->sc_w,grd_curscreen->sc_h,buf);