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