1 /* $Id: sdlgl.c,v 1.12 2004-05-22 22:43:50 btb Exp $ */
4 * Graphics functions for SDL-GL.
15 #include <SDL_image.h>
24 static int curx=-1,cury=-1,curfull=0;
26 void ogl_do_fullscreen_internal(void){
27 ogl_init_window(curx,cury);
30 static Uint16 gammaramp[512];
32 static void init_gammaramp(void)
36 for (i = 0; i < 256; ++i)
37 gammaramp[i] = i * 256;
38 for (i = 256; i < 512; ++i)
39 gammaramp[i] = 0xffff;
42 int ogl_setbrightness_internal(void)
44 return SDL_SetGammaRamp(gammaramp + ogl_brightness_r * 4,
45 gammaramp + ogl_brightness_g * 4,
46 gammaramp + ogl_brightness_b * 4
50 // maybe we might add a real gamma setting (as opposed to brightness setting)
51 // however, SDL_SetGamma seems to call SetGammaRamp internally, so we would need
52 // to modify our own gamma ramp instead.
53 //int ogl_setgamma_internal(void)
55 // float gamma = 1 + gr_palette_realgamma / 8.0;
56 // return SDL_SetGamma(gamma, gamma, gamma);
59 void ogl_swap_buffers_internal(void)
65 int ogl_check_mode(int x, int y)
67 return !SDL_VideoModeOK(x, y, 16, SDL_OPENGL | (ogl_fullscreen?SDL_FULLSCREEN:0));
71 int ogl_init_window(int x, int y)
73 int bpp = FindArg("-gl_16bpp") ? 16 : 32;
76 if (x==curx && y==cury && curfull==ogl_fullscreen)
78 #ifdef __linux__ // Windows, at least, seems to need to reload every time.
79 if (ogl_fullscreen || curfull)
81 ogl_smash_texture_list_internal();//if we are or were fullscreen, changing vid mode will invalidate current textures
83 SDL_WM_SetCaption(DESCENT_VERSION, "Descent II");
87 #include "descent.xpm"
88 SDL_WM_SetIcon(IMG_ReadXPMFromArray(pixmap), NULL);
92 if (!SDL_SetVideoMode(x, y, bpp, SDL_OPENGL | (ogl_fullscreen ? SDL_FULLSCREEN : 0)))
94 Error("Could not set %dx%dx%d opengl video mode\n", x, y, bpp);
98 curx=x;cury=y;curfull=ogl_fullscreen;
104 void ogl_destroy_window(void){
106 ogl_smash_texture_list_internal();
109 //well..SDL doesn't really let you kill the window.. so we just need to wait for sdl_quit
116 if ((t=FindArg("-gl_red")))
117 SDL_GL_SetAttribute( SDL_GL_RED_SIZE, atoi(Args[t+1]) );
118 if ((t=FindArg("-gl_green")))
119 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, atoi(Args[t+1]) );
120 if ((t=FindArg("-gl_blue")))
121 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, atoi(Args[t+1]) );
122 if ((t=FindArg("-gl_alpha")))
123 SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, atoi(Args[t+1]) );
124 if ((t=FindArg("-gl_buffer")))
125 SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, atoi(Args[t+1]) );
126 // SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
127 // SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
128 // SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
129 // SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
132 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,0);
133 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,0);
134 SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,0);
135 SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,0);
136 SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,0);
137 SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,0);
138 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
143 void ogl_close(void){
144 #if 0 // shouldn't really be necessary...
147 ogl_do_fullscreen_internal();
150 ogl_destroy_window();