]> icculus.org git repositories - btb/d2x.git/blob - arch/ogl/sdlgl.c
Hack to keep SDL from screwing up X when it crashes
[btb/d2x.git] / arch / ogl / sdlgl.c
1 /*
2  * $Source: /cvs/cvsroot/d2x/arch/ogl/sdlgl.c,v $
3  * $Revision: 1.3 $
4  * $Author: bradleyb $
5  * $Date: 2001-11-04 09:02:18 $
6  *
7  * Graphics functions for SDL-GL.
8  *
9  * $Log: not supported by cvs2svn $
10  * Revision 1.2  2001/10/31 07:35:48  bradleyb
11  * Sync with d1x
12  *
13  * Revision 1.1  2001/10/25 08:25:34  bradleyb
14  * Finished moving stuff to arch/blah.  I know, it's ugly, but It'll be easier to sync with d1x.
15  *
16  * Revision 1.4  2001/10/09 08:17:07  bradleyb
17  * changed window caption to include version info
18  *
19  * Revision 1.3  2001/10/09 02:58:20  bradleyb
20  * Added window caption, hide mouse cursor
21  *
22  * Revision 1.2  2001/01/29 13:47:52  bradleyb
23  * Fixed build, some minor cleanups.
24  *
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #include <conf.h>
29 #endif
30
31 #include <SDL/SDL.h>
32 #include "ogl_init.h"
33 #include "vers_id.h"
34 #include "error.h"
35 #include "u_mem.h"
36 #include "args.h"
37
38 static int curx=-1,cury=-1,curfull=0;
39
40 void ogl_do_fullscreen_internal(void){
41         ogl_init_window(curx,cury);
42 }
43
44 void ogl_swap_buffers_internal(void){
45         SDL_GL_SwapBuffers();
46 }
47
48 int ogl_init_window(int x, int y){
49         if (gl_initialized){
50                 if (x==curx && y==cury && curfull==ogl_fullscreen)
51                         return 0;
52                 if (ogl_fullscreen || curfull)
53                         ogl_smash_texture_list_internal();//if we are or were fullscreen, changing vid mode will invalidate current textures
54         }
55         SDL_WM_SetCaption(DESCENT_VERSION, "Descent II");
56         if (!SDL_SetVideoMode(x,y, 16, SDL_OPENGL | (ogl_fullscreen?SDL_FULLSCREEN:0))) {
57            Error("Could not set %dx%dx16 opengl video mode\n",x,y);
58         }
59         SDL_ShowCursor(0);
60
61         curx=x;cury=y;curfull=ogl_fullscreen;
62         gl_initialized=1;
63
64         return 0;
65 }
66
67 void ogl_destroy_window(void){
68         if (gl_initialized){
69                 ogl_smash_texture_list_internal();
70                 SDL_ShowCursor(1);
71                 //gl_initialized=0;
72                 //well..SDL doesn't really let you kill the window.. so we just need to wait for sdl_quit
73         }
74         return;
75 }
76
77 void ogl_init(void){
78         int t;
79         if ((t=FindArg("-gl_red")))
80                 SDL_GL_SetAttribute( SDL_GL_RED_SIZE, atoi(Args[t+1]) );
81         if ((t=FindArg("-gl_green")))
82                 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, atoi(Args[t+1]) );
83         if ((t=FindArg("-gl_blue")))
84                 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, atoi(Args[t+1]) );
85         if ((t=FindArg("-gl_alpha")))
86                 SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, atoi(Args[t+1]) );
87         if ((t=FindArg("-gl_buffer")))
88                 SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, atoi(Args[t+1]) );
89 //      SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
90 //      SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
91 //      SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
92 //      SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
93
94
95         SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,0);
96         SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,0);
97         SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,0);
98         SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,0);
99         SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,0);
100         SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,0);
101         SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
102
103 }
104
105 void ogl_close(void){
106 #if 1  // shouldn't really be necessary...
107         if (ogl_fullscreen){
108                 ogl_fullscreen=0;
109                 ogl_do_fullscreen_internal();
110         }
111 #endif
112         ogl_destroy_window();
113 }