1 /* $Id: gr.c,v 1.44 2005-02-25 06:31:53 btb 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>
52 #if defined(__APPLE__) && defined(__MACH__)
53 #include <OpenGL/glu.h>
54 #undef GL_ARB_multitexture // hack!
64 void gr_palette_clear(); // Function prototype for gr_init;
70 int gr_check_fullscreen(void){
71 return ogl_fullscreen;
74 void gr_do_fullscreen(int f){
76 ogl_fullscreen=1;//force fullscreen mode on voodoos.
80 ogl_do_fullscreen_internal();
84 int gr_toggle_fullscreen(void){
85 gr_do_fullscreen(!ogl_fullscreen);
86 // grd_curscreen->sc_mode=0;//hack to get it to reset screen mode
87 return ogl_fullscreen;
90 int arch_toggle_fullscreen_menu(void){
91 unsigned char *buf=NULL;
93 if (ogl_readpixels_ok){
94 MALLOC(buf,unsigned char,grd_curscreen->sc_w*grd_curscreen->sc_h*3);
95 glReadBuffer(GL_FRONT);
96 glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
99 gr_do_fullscreen(!ogl_fullscreen);
101 if (ogl_readpixels_ok){
102 // glWritePixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
104 glDrawPixels(grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
107 // grd_curscreen->sc_mode=0;//hack to get it to reset screen mode
109 return ogl_fullscreen;
112 void ogl_init_state(void){
113 /* select clearing (background) color */
114 glClearColor(0.0, 0.0, 0.0, 0.0);
115 glShadeModel(GL_SMOOTH);
117 /* initialize viewing values */
118 glMatrixMode(GL_PROJECTION);
120 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
121 glScalef(1.0, -1.0, 1.0);
122 glTranslatef(0.0, -1.0, 0.0);
123 gr_palette_step_up(0,0,0);//in case its left over from in game
126 int last_screen_mode=-1;
128 void ogl_set_screen_mode(void){
129 if (last_screen_mode==Screen_mode)
131 OGL_VIEWPORT(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h);
132 // 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);
133 if (Screen_mode==SCREEN_GAME){
134 glDrawBuffer(GL_BACK);
136 glClearColor(0.0, 0.0, 0.0, 0.0);
137 glDrawBuffer(GL_FRONT);
138 glClear(GL_COLOR_BUFFER_BIT);
139 glMatrixMode(GL_PROJECTION);
140 glLoadIdentity();//clear matrix
141 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
142 glMatrixMode(GL_MODELVIEW);
143 glLoadIdentity();//clear matrix
145 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
147 last_screen_mode=Screen_mode;
154 if(Screen_mode != SCREEN_GAME){
160 const char *gl_vendor, *gl_renderer, *gl_version, *gl_extensions;
162 void ogl_get_verinfo(void)
164 long t, sgi_max_textures = -1;
165 GLint arb_max_textures = -1;
166 #ifdef GL_NV_register_combiners
167 long nv_register_combiners = -1;
169 float anisotropic_max = 0;
171 gl_vendor = (const char *) glGetString (GL_VENDOR);
172 gl_renderer = (const char *) glGetString (GL_RENDERER);
173 gl_version = (const char *) glGetString (GL_VERSION);
174 gl_extensions = (const char *) glGetString (GL_EXTENSIONS);
176 con_printf(CON_VERBOSE, "OpenGL: vendor: %s\nOpenGL: renderer: %s\nOpenGL: version: %s\n",gl_vendor,gl_renderer,gl_version);
178 ogl_intensity4_ok = 1;
179 ogl_luminance4_alpha4_ok = 1;
181 ogl_gettexlevelparam_ok = 1;
182 ogl_setgammaramp_ok = 1;
185 dglMultiTexCoord2fARB = (glMultiTexCoord2fARB_fp)wglGetProcAddress("glMultiTexCoord2fARB");
186 dglActiveTextureARB = (glActiveTextureARB_fp)wglGetProcAddress("glActiveTextureARB");
187 dglMultiTexCoord2fSGIS = (glMultiTexCoord2fSGIS_fp)wglGetProcAddress("glMultiTexCoord2fSGIS");
188 dglSelectTextureSGIS = (glSelectTextureSGIS_fp)wglGetProcAddress("glSelectTextureSGIS");
189 dglColorTableEXT = (glColorTableEXT_fp)wglGetProcAddress("glColorTableEXT");
190 dglCombinerParameteriNV = (glCombinerParameteriNV_fp)wglGetProcAddress("glCombinerParameteriNV");
191 dglCombinerInputNV = (glCombinerInputNV_fp)wglGetProcAddress("glCombinerInputNV");
192 dglCombinerOutputNV = (glCombinerOutputNV_fp)wglGetProcAddress("glCombinerOutputNV");
193 dglFinalCombinerInputNV = (glFinalCombinerInputNV_fp)wglGetProcAddress("glFinalCombinerInputNV");
196 #ifdef GL_ARB_multitexture
197 ogl_arb_multitexture_ok = (strstr(gl_extensions, "GL_ARB_multitexture") != 0 && glActiveTextureARB != 0);
198 mprintf((0,"c:%p d:%p e:%p\n",strstr(gl_extensions,"GL_ARB_multitexture"),glActiveTextureARB,glBegin));
200 #ifdef GL_SGIS_multitexture
201 ogl_sgis_multitexture_ok = (strstr(gl_extensions, "GL_SGIS_multitexture") != 0 && glSelectTextureSGIS != 0);
202 mprintf((0,"a:%p b:%p\n",strstr(gl_extensions,"GL_SGIS_multitexture"),glSelectTextureSGIS));
204 ogl_nv_texture_env_combine4_ok = (strstr(gl_extensions, "GL_NV_texture_env_combine4") != 0);
205 #ifdef GL_NV_register_combiners
206 ogl_nv_register_combiners_ok=(strstr(gl_extensions,"GL_NV_register_combiners")!=0 && glCombinerOutputNV!=0);
209 ogl_ext_texture_filter_anisotropic_ok = (strstr(gl_extensions, "GL_EXT_texture_filter_anisotropic") != 0);
210 if (ogl_ext_texture_filter_anisotropic_ok)
211 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic_max);
213 #ifdef GL_EXT_paletted_texture
214 ogl_paletted_texture_ok = (strstr(gl_extensions, "GL_EXT_paletted_texture") != 0 && glColorTableEXT != 0);
215 ogl_shared_palette_ok = (strstr(gl_extensions, "GL_EXT_shared_texture_palette") != 0 && ogl_paletted_texture_ok);
217 //add driver specific hacks here. whee.
218 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){
219 ogl_intensity4_ok=0;//ignores alpha, always black background instead of transparent.
220 ogl_readpixels_ok=0;//either just returns all black, or kills the X server entirely
221 ogl_gettexlevelparam_ok=0;//returns random data..
223 if (stricmp(gl_vendor,"Matrox Graphics Inc.")==0){
224 //displays garbage. reported by
225 // redomen@crcwnet.com (render="Matrox G400" version="1.1.3 5.52.015")
226 // orulz (Matrox G200)
230 if (stricmp(gl_renderer,"3dfx Voodoo 3")==0){ // strangely, includes Voodoo 2
231 ogl_gettexlevelparam_ok=0; // Always returns 0
235 //allow overriding of stuff.
236 #ifdef GL_ARB_multitexture
237 if ((t=FindArg("-gl_arb_multitexture_ok"))){
238 ogl_arb_multitexture_ok=atoi(Args[t+1]);
240 if (ogl_arb_multitexture_ok)
241 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &arb_max_textures);
243 #ifdef GL_SGIS_multitexture
244 if ((t=FindArg("-gl_sgis_multitexture_ok"))){
245 ogl_sgis_multitexture_ok=atoi(Args[t+1]);
247 if (ogl_sgis_multitexture_ok)
248 glGetIntegerv(GL_MAX_TEXTURES_SGIS, &sgi_max_textures);
250 #ifdef GL_NV_register_combiners
251 if ((t = FindArg("-gl_nv_register_combiners_ok")))
253 ogl_nv_register_combiners_ok=atoi(Args[t + 1]);
255 if (ogl_nv_register_combiners_ok)
256 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &nv_register_combiners);
258 #ifdef GL_EXT_paletted_texture
259 if ((t = FindArg("-gl_paletted_texture_ok")))
261 ogl_paletted_texture_ok = atoi(Args[t + 1]);
263 if ((t = FindArg("-gl_shared_palette_ok")))
265 ogl_shared_palette_ok = atoi(Args[t + 1]);
267 ogl_shared_palette_ok = ogl_shared_palette_ok && ogl_paletted_texture_ok; // shared palettes require palette support in the first place, obviously ;)
268 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);
270 if ((t=FindArg("-gl_intensity4_ok"))){
271 ogl_intensity4_ok=atoi(Args[t+1]);
273 if ((t=FindArg("-gl_luminance4_alpha4_ok"))){
274 ogl_luminance4_alpha4_ok=atoi(Args[t+1]);
276 if ((t=FindArg("-gl_rgba2_ok"))){
277 ogl_rgba2_ok=atoi(Args[t+1]);
279 if ((t=FindArg("-gl_readpixels_ok"))){
280 ogl_readpixels_ok=atoi(Args[t+1]);
282 if ((t=FindArg("-gl_gettexlevelparam_ok"))){
283 ogl_gettexlevelparam_ok=atoi(Args[t+1]);
285 if ((t=FindArg("-gl_setgammaramp_ok")))
287 ogl_setgammaramp_ok = atoi(Args[t + 1]);
290 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);
291 #ifdef GL_NV_register_combiners
292 con_printf(CON_VERBOSE, "gl_nv_register_combiners:%i(%i stages)\n", ogl_nv_register_combiners_ok, nv_register_combiners);
294 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);
298 int gr_check_mode(u_int32_t mode)
304 return ogl_check_mode(w, h); // platform specific code
308 extern int VGA_current_mode; // DPH: kludge - remove at all costs
310 int gr_set_mode(u_int32_t mode)
324 VGA_current_mode = mode;
326 //if (screen != NULL) gr_palette_clear();
330 gr_bm_data=(char *)grd_curscreen->sc_canvas.cv_bitmap.bm_data;//since we use realloc, we want to keep this pointer around.
331 memset( grd_curscreen, 0, sizeof(grs_screen));
332 grd_curscreen->sc_mode = mode;
333 grd_curscreen->sc_w = w;
334 grd_curscreen->sc_h = h;
335 grd_curscreen->sc_aspect = fixdiv(grd_curscreen->sc_w*3,grd_curscreen->sc_h*4);
336 grd_curscreen->sc_canvas.cv_bitmap.bm_x = 0;
337 grd_curscreen->sc_canvas.cv_bitmap.bm_y = 0;
338 grd_curscreen->sc_canvas.cv_bitmap.bm_w = w;
339 grd_curscreen->sc_canvas.cv_bitmap.bm_h = h;
340 //grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = screen->pitch;
341 grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = w;
342 grd_curscreen->sc_canvas.cv_bitmap.bm_type = BM_OGL;
343 //grd_curscreen->sc_canvas.cv_bitmap.bm_data = (unsigned char *)screen->pixels;
344 // mprintf((0,"ogl/gr.c: reallocing %p to %i\n",grd_curscreen->sc_canvas.cv_bitmap.bm_data,w*h));
345 grd_curscreen->sc_canvas.cv_bitmap.bm_data = d_realloc(gr_bm_data,w*h);
346 gr_set_current_canvas(NULL);
347 //gr_enable_default_palette_loading();
349 ogl_init_window(w,h);//platform specific code
353 OGL_VIEWPORT(0,0,w,h);
355 ogl_set_screen_mode();
357 // gamefont_choose_game_font(w,h);
362 #define GLstrcmptestr(a,b) if (stricmp(a,#b)==0 || stricmp(a,"GL_" #b)==0)return GL_ ## b;
363 int ogl_atotexfilti(char *a,int min){
364 GLstrcmptestr(a,NEAREST);
365 GLstrcmptestr(a,LINEAR);
366 if (min){//mipmaps are valid only for the min filter
367 GLstrcmptestr(a,NEAREST_MIPMAP_NEAREST);
368 GLstrcmptestr(a,NEAREST_MIPMAP_LINEAR);
369 GLstrcmptestr(a,LINEAR_MIPMAP_NEAREST);
370 GLstrcmptestr(a,LINEAR_MIPMAP_LINEAR);
372 Error("unknown/invalid texture filter %s\n",a);
373 // return GL_NEAREST;
375 int ogl_testneedmipmaps(int i){
380 case GL_NEAREST_MIPMAP_NEAREST:
381 case GL_NEAREST_MIPMAP_LINEAR:
382 case GL_LINEAR_MIPMAP_NEAREST:
383 case GL_LINEAR_MIPMAP_LINEAR:
386 Error("unknown texture filter %x\n",i);
389 #ifdef OGL_RUNTIME_LOAD
391 char *OglLibPath="opengl32.dll";
394 char *OglLibPath="libGL.so";
397 char *OglLibPath = NULL;
401 int ogl_init_load_library(void)
406 if ((t=FindArg("-gl_library")))
407 OglLibPath=Args[t+1];
409 retcode = OpenGL_LoadLibrary(true);
412 mprintf((0,"Opengl loaded ok\n"));
416 Error("Opengl: Functions not imported\n");
419 Error("Opengl: error loading %s\n", OglLibPath? OglLibPath : SDL_GetError());
429 int mode = SM(640,480);
430 int retcode, t, glt = 0;
432 // Only do this function once!
437 #ifdef OGL_RUNTIME_LOAD
438 ogl_init_load_library();
441 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
442 if (FindArg("-gl_voodoo")){
444 gr_toggle_fullscreen();
446 if (FindArg("-fullscreen"))
447 gr_toggle_fullscreen();
449 if ((glt=FindArg("-gl_alttexmerge")))
451 if ((t=FindArg("-gl_stdtexmerge")))
452 if (t>=glt)//allow overriding of earlier args
455 if ((glt = FindArg("-gl_16bittextures")))
457 ogl_rgba_internalformat = GL_RGB5_A1;
458 ogl_rgb_internalformat = GL_RGB5;
461 if ((glt=FindArg("-gl_mipmap"))){
462 GL_texmagfilt=GL_LINEAR;
463 GL_texminfilt=GL_LINEAR_MIPMAP_NEAREST;
465 if ((glt=FindArg("-gl_trilinear")))
467 GL_texmagfilt = GL_LINEAR;
468 GL_texminfilt = GL_LINEAR_MIPMAP_LINEAR;
470 if ((t=FindArg("-gl_simple"))){
471 if (t>=glt){//allow overriding of earlier args
473 GL_texmagfilt=GL_NEAREST;
474 GL_texminfilt=GL_NEAREST;
477 if ((t=FindArg("-gl_texmagfilt")) || (t=FindArg("-gl_texmagfilter"))){
478 if (t>=glt)//allow overriding of earlier args
479 GL_texmagfilt=ogl_atotexfilti(Args[t+1],0);
481 if ((t=FindArg("-gl_texminfilt")) || (t=FindArg("-gl_texminfilter"))){
482 if (t>=glt)//allow overriding of earlier args
483 GL_texminfilt=ogl_atotexfilti(Args[t+1],1);
485 GL_needmipmaps=ogl_testneedmipmaps(GL_texminfilt);
487 if ((t = FindArg("-gl_anisotropy")) || (t = FindArg("-gl_anisotropic")))
489 GL_texanisofilt=atof(Args[t + 1]);
492 mprintf((0,"gr_init: texmagfilt:%x texminfilt:%x needmipmaps=%i anisotropic:%f\n",GL_texmagfilt,GL_texminfilt,GL_needmipmaps,GL_texanisofilt));
495 if ((t=FindArg("-gl_vidmem"))){
496 ogl_mem_target=atoi(Args[t+1])*1024*1024;
498 if ((t=FindArg("-gl_reticle"))){
499 gl_reticle=atoi(Args[t+1]);
501 //printf("ogl_mem_target=%i\n",ogl_mem_target);
503 ogl_init();//platform specific initialization
505 ogl_init_texture_list_internal();
507 MALLOC( grd_curscreen,grs_screen,1 );
508 memset( grd_curscreen, 0, sizeof(grs_screen));
509 grd_curscreen->sc_canvas.cv_bitmap.bm_data = NULL;
512 if ((retcode=gr_set_mode(mode)))
517 grd_curscreen->sc_canvas.cv_color = 0;
518 grd_curscreen->sc_canvas.cv_drawmode = 0;
519 grd_curscreen->sc_canvas.cv_font = NULL;
520 grd_curscreen->sc_canvas.cv_font_fg_color = 0;
521 grd_curscreen->sc_canvas.cv_font_bg_color = 0;
522 gr_set_current_canvas( &grd_curscreen->sc_canvas );
533 // mprintf((0,"ogl init: %s %s %s - %s\n",glGetString(GL_VENDOR),glGetString(GL_RENDERER),glGetString(GL_VERSION),glGetString,(GL_EXTENSIONS)));
534 ogl_brightness_r = ogl_brightness_g = ogl_brightness_b = 0;
535 ogl_setbrightness_internal();
537 ogl_close();//platform specific code
539 if (grd_curscreen->sc_canvas.cv_bitmap.bm_data)
540 d_free(grd_curscreen->sc_canvas.cv_bitmap.bm_data);
541 d_free(grd_curscreen);
543 #ifdef OGL_RUNTIME_LOAD
545 OpenGL_LoadLibrary(false);
548 extern int r_upixelc;
549 void ogl_upixelc(int x, int y, int c){
551 // printf("gr_upixelc(%i,%i,%i)%i\n",x,y,c,Function_mode==FMODE_GAME);
552 // if(Function_mode != FMODE_GAME){
553 // grd_curcanv->cv_bitmap.bm_data[y*grd_curscreen->sc_canvas.cv_bitmap.bm_w+x]=c;
555 OGL_DISABLE(TEXTURE_2D);
558 // glBegin(GL_LINES);
559 // ogl_pal=gr_current_pal;
560 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
561 // ogl_pal=gr_palette;
562 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);
563 // glVertex2f(x/((float)last_width+1),1.0-y/((float)last_height+1));
567 void ogl_urect(int left,int top,int right,int bot){
571 xo=(left+grd_curcanv->cv_bitmap.bm_x)/(float)last_width;
572 xf = (right + 1 + grd_curcanv->cv_bitmap.bm_x) / (float)last_width;
573 yo=1.0-(top+grd_curcanv->cv_bitmap.bm_y)/(float)last_height;
574 yf = 1.0 - (bot + 1 + grd_curcanv->cv_bitmap.bm_y) / (float)last_height;
576 OGL_DISABLE(TEXTURE_2D);
577 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS)
578 glColor3f(CPAL2Tr(c), CPAL2Tg(c), CPAL2Tb(c));
580 glColor4f(CPAL2Tr(c), CPAL2Tg(c), CPAL2Tb(c), 1.0 - (float)Gr_scanline_darkening_level / ((float)GR_FADE_LEVELS - 1.0));
588 void ogl_ulinec(int left,int top,int right,int bot,int c){
591 xo = (left + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
592 xf = (right + grd_curcanv->cv_bitmap.bm_x + 0.5) / (float)last_width;
593 yo = 1.0 - (top + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
594 yf = 1.0 - (bot + grd_curcanv->cv_bitmap.bm_y + 0.5) / (float)last_height;
596 OGL_DISABLE(TEXTURE_2D);
597 glColor3f(CPAL2Tr(c),CPAL2Tg(c),CPAL2Tb(c));
605 GLfloat last_r=0, last_g=0, last_b=0;
607 void ogl_do_palfx(void){
609 OGL_DISABLE(TEXTURE_2D);
610 if (gr_palette_faded_out){
611 /* glEnable(GL_BLEND);
612 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/
617 //glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
619 glBlendFunc(GL_ONE,GL_ONE);
620 glColor3f(last_r,last_g,last_b);
621 // r=f2fl(last_r);g=f2fl(last_g);b=f2fl(last_b);a=0.5;
635 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
638 void gr_palette_clear()
640 gr_palette_faded_out=1;
644 int ogl_brightness_ok = 0;
645 int ogl_setgammaramp_ok = 1;
646 int ogl_brightness_r = 0, ogl_brightness_g = 0, ogl_brightness_b = 0;
647 static int old_b_r = 0, old_b_g = 0, old_b_b = 0;
649 void gr_palette_step_up(int r, int g, int b)
651 if (gr_palette_faded_out)
654 old_b_r = ogl_brightness_r;
655 old_b_g = ogl_brightness_g;
656 old_b_b = ogl_brightness_b;
658 ogl_brightness_r = max(r + gr_palette_gamma, 0);
659 ogl_brightness_g = max(g + gr_palette_gamma, 0);
660 ogl_brightness_b = max(b + gr_palette_gamma, 0);
662 if (ogl_setgammaramp_ok &&
663 (old_b_r != ogl_brightness_r ||
664 old_b_g != ogl_brightness_g ||
665 old_b_b != ogl_brightness_b))
666 ogl_brightness_ok = !ogl_setbrightness_internal();
668 if (!ogl_setgammaramp_ok || !ogl_brightness_ok)
670 last_r = ogl_brightness_r / 63.0;
671 last_g = ogl_brightness_g / 63.0;
672 last_b = ogl_brightness_b / 63.0;
674 do_pal_step = (r || g || b || gr_palette_gamma);
682 //added on 980913 by adb to fix palette problems
683 // need a min without side effects...
685 static inline int min(int x, int y) { return x < y ? x : y; }
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)
711 gr_palette_faded_out=1;
717 int gr_palette_fade_in(ubyte *pal, int nsteps, int allow_keys)
719 gr_palette_faded_out=0;
725 void gr_palette_read(ubyte * pal)
728 for (i=0; i<768; i++ ) {
729 pal[i]=gr_current_pal[i];
730 if (pal[i] > 63) pal[i] = 63;
734 //writes out an uncompressed RGB .tga file
735 //if we got really spiffy, we could optionally link in libpng or something, and use that.
736 void write_bmp(char *savename,int w,int h,unsigned char *buf){
739 f = PHYSFSX_openWriteBuffered(savename);
742 GLubyte targaMagic[12] = { 0, //no identification field
744 2,//RGB image (well, BGR, actually)
745 0, 0, 0, 0, 0, 0, 0, 0, 0 };//no colormap or image origin stuff.
752 PHYSFS_write(f, targaMagic, sizeof(targaMagic), 1);
753 PHYSFS_writeSLE32(f, w);
754 PHYSFS_writeSLE32(f, h);
755 PHYSFSX_writeU8(f, 24); // 24 bpp
756 PHYSFSX_writeU8(f, 0); // no attribute bits, origin is lowerleft, no interleave
759 for (y=0;y<h;y++){//TGAs use BGR ordering of data.
770 r = PHYSFS_write(f, buf + x, 1, y);
772 mprintf((0,"screenshot error, couldn't write to %s (err %i)\n",savename,errno));
779 mprintf((0,"screenshot error, couldn't open %s (err %i)\n",savename,errno));
782 void save_screen_shot(int automap_flag)
786 static int savenum=0;
790 if (!ogl_readpixels_ok){
792 hud_message(MSGC_GAME_FEEDBACK,"glReadPixels not supported on your configuration");
798 //added/changed on 10/31/98 by Victor Rachels to fix overwrite each new game
799 if ( savenum == 9999 ) savenum = 0;
800 sprintf(savename,"scrn%04d.tga",savenum++);
802 while(!access(savename,0))
804 if ( savenum == 9999 ) savenum = 0;
805 sprintf(savename,"scrn%04d.tga",savenum++);
807 sprintf( message, "%s '%s'", TXT_DUMPING_SCREEN, savename );
808 //end this section addition/change - Victor Rachels
811 // save_font = grd_curcanv->cv_font;
812 // gr_set_curfont(GAME_FONT);
813 // gr_set_fontcolor(gr_find_closest_color_current(0,31,0),-1);
814 // gr_get_string_size(message,&w,&h,&aw);
815 // modex_print_message(32, 2, message);
817 hud_message(MSGC_GAME_FEEDBACK,message);
820 buf = d_malloc(grd_curscreen->sc_w*grd_curscreen->sc_h*3);
821 glReadBuffer(GL_FRONT);
822 glReadPixels(0,0,grd_curscreen->sc_w,grd_curscreen->sc_h,GL_RGB,GL_UNSIGNED_BYTE,buf);
823 write_bmp(savename,grd_curscreen->sc_w,grd_curscreen->sc_h,buf);