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