From 130ac9dfb4d39142176bcc75a5e9d38378b6c1f2 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Thu, 20 May 2004 02:04:30 +0000 Subject: [PATCH] implement brightness/palette effects in OGL using SetGammaRamp, much faster than the hack that was being used. currently SDL only (though not too hard to add to WGL, not as easy as sdl) (d1x r1.31, r1.3, r1.13, r1.21) --- ChangeLog | 10 +++++++- arch/ogl/gr.c | 61 +++++++++++++++++++++++++++++++++------------ arch/ogl/internal.h | 3 +++ arch/ogl/sdlgl.c | 35 ++++++++++++++++++++++++-- arch/ogl/wgl.c | 6 ++++- include/ogl_init.h | 1 + 6 files changed, 96 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2072bf6..d49f7cd8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,16 @@ -2004-05-19 Bradley Bell +2004-05-19 Matthew Mueller + + * arch/ogl/gr.c, arch/ogl/internal.h, arch/ogl/sdlgl.c, + arch/ogl/wgl.c, include/ogl_init.h: implement brightness/palette + effects in OGL using SetGammaRamp, much faster than the hack that + was being used. currently SDL only (though not too hard to add to + WGL, not as easy as sdl) (d1x r1.31, r1.3, r1.13, r1.21) * main/menu.c: allow arbitrary (custom) resolution entry in change_res menu (d1x r1.14) +2004-05-19 Bradley Bell + * main/game.c, main/game.h, main/inferno.c, main/menu.c: inserted d1x-style res change menu (mostly works) diff --git a/arch/ogl/gr.c b/arch/ogl/gr.c index 2094c20e..00425dc1 100644 --- a/arch/ogl/gr.c +++ b/arch/ogl/gr.c @@ -1,4 +1,4 @@ -/* $Id: gr.c,v 1.20 2004-05-19 22:16:12 btb Exp $ */ +/* $Id: gr.c,v 1.21 2004-05-20 02:04:26 btb Exp $ */ /* * * OGL video functions. - Added 9/15/99 Matthew Mueller @@ -169,7 +169,11 @@ void ogl_get_verinfo(void){ con_printf(CON_VERBOSE, "gl vendor:%s renderer:%s version:%s extensions:%s\n",gl_vendor,gl_renderer,gl_version,gl_extensions); - ogl_intensity4_ok=1;ogl_luminance4_alpha4_ok=1;ogl_rgba2_ok=1;ogl_gettexlevelparam_ok=1; + ogl_intensity4_ok = 1; + ogl_luminance4_alpha4_ok = 1; + ogl_rgba2_ok = 1; + ogl_gettexlevelparam_ok = 1; + ogl_setgammaramp_ok = 1; #if 0 //WGL only, I think dglMultiTexCoord2fARB = (glMultiTexCoord2fARB_fp)wglGetProcAddress("glMultiTexCoord2fARB"); @@ -227,9 +231,13 @@ void ogl_get_verinfo(void){ if ((t=FindArg("-gl_gettexlevelparam_ok"))){ ogl_gettexlevelparam_ok=atoi(Args[t+1]); } + if ((t=FindArg("-gl_setgammaramp_ok"))) + { + ogl_setgammaramp_ok = atoi(Args[t + 1]); + } con_printf(CON_VERBOSE, "gl_arb_multitexture:%i gl_sgis_multitexture:%i\n",ogl_arb_multitexture_ok,ogl_sgis_multitexture_ok); - con_printf(CON_VERBOSE, "gl_intensity4:%i gl_luminance4_alpha4:%i gl_rgba2:%i gl_readpixels:%i gl_gettexlevelparam:%i\n",ogl_intensity4_ok,ogl_luminance4_alpha4_ok,ogl_rgba2_ok,ogl_readpixels_ok,ogl_gettexlevelparam_ok); + con_printf(CON_VERBOSE, "gl_intensity4:%i gl_luminance4_alpha4:%i gl_rgba2:%i gl_readpixels:%i gl_gettexlevelparam:%i gl_setgammaramp_ok:%i\n",ogl_intensity4_ok,ogl_luminance4_alpha4_ok,ogl_rgba2_ok,ogl_readpixels_ok,ogl_gettexlevelparam_ok, ogl_setgammaramp_ok); } @@ -561,23 +569,42 @@ void gr_palette_clear() } -void gr_palette_step_up( int r, int g, int b ) +int ogl_brightness_ok = 0; +int ogl_setgammaramp_ok = 1; +int ogl_brightness_r = 0, ogl_brightness_g = 0, ogl_brightness_b = 0; +static int old_b_r = 0, old_b_g = 0, old_b_b = 0; + +void gr_palette_step_up(int r, int g, int b) { - if (gr_palette_faded_out) return; + if (gr_palette_faded_out) + return; -// if ( (r==last_r) && (g==last_g) && (b==last_b) ) return; + old_b_r = ogl_brightness_r; + old_b_g = ogl_brightness_g; + old_b_b = ogl_brightness_b; -/* last_r = r/63.0; - last_g = g/63.0; - last_b = b/63.0; - do_pal_step=(r || g || b);*/ - - last_r = (r+gr_palette_gamma)/63.0; - last_g = (g+gr_palette_gamma)/63.0; - last_b = (b+gr_palette_gamma)/63.0; + ogl_brightness_r = r + gr_palette_gamma; + ogl_brightness_g = g + gr_palette_gamma; + ogl_brightness_b = b + gr_palette_gamma; - do_pal_step=(r || g || b || gr_palette_gamma); - + if (ogl_setgammaramp_ok && + (old_b_r != ogl_brightness_r || + old_b_g != ogl_brightness_g || + old_b_b != ogl_brightness_b)) + ogl_brightness_ok = !ogl_setbrightness_internal(); + + if (!ogl_setgammaramp_ok || !ogl_brightness_ok) + { + last_r = ogl_brightness_r / 63.0; + last_g = ogl_brightness_g / 63.0; + last_b = ogl_brightness_b / 63.0; + + do_pal_step = (r || g || b || gr_palette_gamma); + } + else + { + do_pal_step = 0; + } } //added on 980913 by adb to fix palette problems @@ -598,6 +625,8 @@ void gr_palette_load( ubyte *pal ) gr_palette_faded_out=0; + gr_palette_step_up(0, 0, 0); // make ogl_setbrightness_internal get run so that menus get brightened too. + init_computed_colors(); } diff --git a/arch/ogl/internal.h b/arch/ogl/internal.h index 24e6f95e..02c5ad7e 100644 --- a/arch/ogl/internal.h +++ b/arch/ogl/internal.h @@ -17,6 +17,9 @@ void ogl_init_texture_list_internal(void); void ogl_smash_texture_list_internal(void); void ogl_vivify_texture_list_internal(void); +extern int ogl_brightness_ok; +extern int ogl_brightness_r, ogl_brightness_g, ogl_brightness_b; +int ogl_setbrightness_internal(void); extern int ogl_fullscreen; void ogl_do_fullscreen_internal(void); diff --git a/arch/ogl/sdlgl.c b/arch/ogl/sdlgl.c index 98d651e3..c61b73e5 100644 --- a/arch/ogl/sdlgl.c +++ b/arch/ogl/sdlgl.c @@ -1,4 +1,4 @@ -/* $Id: sdlgl.c,v 1.10 2004-05-16 00:45:25 schaffner Exp $ */ +/* $Id: sdlgl.c,v 1.11 2004-05-20 02:04:28 btb Exp $ */ /* * * Graphics functions for SDL-GL. @@ -27,7 +27,37 @@ void ogl_do_fullscreen_internal(void){ ogl_init_window(curx,cury); } -void ogl_swap_buffers_internal(void){ +static Uint16 gammaramp[512]; + +static void init_gammaramp(void) +{ + int i; + + for (i = 0; i < 256; ++i) + gammaramp[i] = i * 256; + for (i = 256; i < 512; ++i) + gammaramp[i] = 0xffff; +} + +int ogl_setbrightness_internal(void) +{ + return SDL_SetGammaRamp(gammaramp + ogl_brightness_r * 4, + gammaramp + ogl_brightness_g * 4, + gammaramp + ogl_brightness_b * 4 + ); +} + +// maybe we might add a real gamma setting (as opposed to brightness setting) +// however, SDL_SetGamma seems to call SetGammaRamp internally, so we would need +// to modify our own gamma ramp instead. +//int ogl_setgamma_internal(void) +//{ +// float gamma = 1 + gr_palette_realgamma / 8.0; +// return SDL_SetGamma(gamma, gamma, gamma); +//} + +void ogl_swap_buffers_internal(void) +{ SDL_GL_SwapBuffers(); } @@ -103,6 +133,7 @@ void ogl_init(void){ SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,0); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); + init_gammaramp(); } void ogl_close(void){ diff --git a/arch/ogl/wgl.c b/arch/ogl/wgl.c index f6272fb1..5863a666 100644 --- a/arch/ogl/wgl.c +++ b/arch/ogl/wgl.c @@ -1,4 +1,4 @@ -/* $Id: wgl.c,v 1.5 2004-05-19 02:14:17 btb Exp $ */ +/* $Id: wgl.c,v 1.6 2004-05-20 02:04:29 btb Exp $ */ /* * * opengl platform specific functions for WGL - added by Peter Hawkins @@ -157,6 +157,10 @@ long PASCAL DescentWndProc(HWND hWnd,UINT message, } +int ogl_setbrightness_internal(void) +{ + return -1; // TODO: not yet implemented +} void ogl_swap_buffers_internal(void){ SwapBuffers( hDC ); diff --git a/include/ogl_init.h b/include/ogl_init.h index 5467c6e7..16aa268b 100644 --- a/include/ogl_init.h +++ b/include/ogl_init.h @@ -62,6 +62,7 @@ extern ogl_texture* ogl_get_free_texture(); extern int ogl_alttexmerge;//merge textures by just printing the seperate textures? extern int ogl_rgba_format; +extern int ogl_setgammaramp_ok; extern int ogl_intensity4_ok; extern int ogl_luminance4_alpha4_ok; extern int ogl_rgba2_ok; -- 2.39.2