1 /* $Id: sdlgl.c,v 1.11 2004-05-20 02:04:28 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 if (x==curx && y==cury && curfull==ogl_fullscreen)
75 #ifdef __linux__ // Windows, at least, seems to need to reload every time.
76 if (ogl_fullscreen || curfull)
78 ogl_smash_texture_list_internal();//if we are or were fullscreen, changing vid mode will invalidate current textures
80 SDL_WM_SetCaption(DESCENT_VERSION, "Descent II");
84 #include "descent.xpm"
85 SDL_WM_SetIcon(IMG_ReadXPMFromArray(pixmap), NULL);
89 if (!SDL_SetVideoMode(x,y, 16, SDL_OPENGL | (ogl_fullscreen?SDL_FULLSCREEN:0))) {
90 Error("Could not set %dx%dx16 opengl video mode\n",x,y);
94 curx=x;cury=y;curfull=ogl_fullscreen;
100 void ogl_destroy_window(void){
102 ogl_smash_texture_list_internal();
105 //well..SDL doesn't really let you kill the window.. so we just need to wait for sdl_quit
112 if ((t=FindArg("-gl_red")))
113 SDL_GL_SetAttribute( SDL_GL_RED_SIZE, atoi(Args[t+1]) );
114 if ((t=FindArg("-gl_green")))
115 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, atoi(Args[t+1]) );
116 if ((t=FindArg("-gl_blue")))
117 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, atoi(Args[t+1]) );
118 if ((t=FindArg("-gl_alpha")))
119 SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, atoi(Args[t+1]) );
120 if ((t=FindArg("-gl_buffer")))
121 SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, atoi(Args[t+1]) );
122 // SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
123 // SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
124 // SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
125 // SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
128 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,0);
129 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,0);
130 SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,0);
131 SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,0);
132 SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,0);
133 SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,0);
134 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
139 void ogl_close(void){
140 #if 0 // shouldn't really be necessary...
143 ogl_do_fullscreen_internal();
146 ogl_destroy_window();