3 * Graphics functions for SDL-GL.
14 #include <SDL_image.h>
23 static int curx=-1,cury=-1,curfull=0;
25 void ogl_do_fullscreen_internal(void){
26 ogl_init_window(curx,cury);
29 static Uint16 gammaramp[512];
31 static void init_gammaramp(void)
35 for (i = 0; i < 256; ++i)
36 gammaramp[i] = i * 256;
37 for (i = 256; i < 512; ++i)
38 gammaramp[i] = 0xffff;
41 int ogl_setbrightness_internal(void)
43 return SDL_SetGammaRamp(gammaramp + ogl_brightness_r * 4,
44 gammaramp + ogl_brightness_g * 4,
45 gammaramp + ogl_brightness_b * 4
49 // maybe we might add a real gamma setting (as opposed to brightness setting)
50 // however, SDL_SetGamma seems to call SetGammaRamp internally, so we would need
51 // to modify our own gamma ramp instead.
52 //int ogl_setgamma_internal(void)
54 // float gamma = 1 + gr_palette_realgamma / 8.0;
55 // return SDL_SetGamma(gamma, gamma, gamma);
58 void ogl_swap_buffers_internal(void)
64 int ogl_check_mode(int x, int y)
66 return !SDL_VideoModeOK(x, y, 16, SDL_OPENGL | (ogl_fullscreen?SDL_FULLSCREEN:0));
70 int ogl_init_window(int x, int y)
72 int bpp = FindArg("-gl_16bpp") ? 16 : 32;
75 if (x==curx && y==cury && curfull==ogl_fullscreen)
77 #ifdef __linux__ // Windows, at least, seems to need to reload every time.
78 if (ogl_fullscreen || curfull)
80 ogl_smash_texture_list_internal();//if we are or were fullscreen, changing vid mode will invalidate current textures
82 SDL_WM_SetCaption(DESCENT_VERSION, "Descent II");
86 #include "descent.xpm"
87 SDL_WM_SetIcon(IMG_ReadXPMFromArray(pixmap), NULL);
91 if (!SDL_SetVideoMode(x, y, bpp, SDL_OPENGL | (ogl_fullscreen ? SDL_FULLSCREEN : 0)))
93 Error("Could not set %dx%dx%d opengl video mode\n", x, y, bpp);
96 curx=x;cury=y;curfull=ogl_fullscreen;
102 void ogl_destroy_window(void){
104 ogl_smash_texture_list_internal();
106 //well..SDL doesn't really let you kill the window.. so we just need to wait for sdl_quit
113 if ((t=FindArg("-gl_red")))
114 SDL_GL_SetAttribute( SDL_GL_RED_SIZE, atoi(Args[t+1]) );
115 if ((t=FindArg("-gl_green")))
116 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, atoi(Args[t+1]) );
117 if ((t=FindArg("-gl_blue")))
118 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, atoi(Args[t+1]) );
119 if ((t=FindArg("-gl_alpha")))
120 SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, atoi(Args[t+1]) );
121 if ((t=FindArg("-gl_buffer")))
122 SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, atoi(Args[t+1]) );
123 // SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
124 // SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
125 // SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
126 // SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
129 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,0);
130 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,0);
131 SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,0);
132 SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,0);
133 SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,0);
134 SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,0);
135 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
140 void ogl_close(void){
141 #if 0 // shouldn't really be necessary...
144 ogl_do_fullscreen_internal();
147 ogl_destroy_window();