]> icculus.org git repositories - btb/d2x.git/blob - arch/ogl/sdlgl.c
Fixed many opengl glitches
[btb/d2x.git] / arch / ogl / sdlgl.c
1 /* $Id: sdlgl.c,v 1.5 2003-01-15 02:42:41 btb Exp $ */
2 /*
3  *
4  * Graphics functions for SDL-GL.
5  *
6  *
7  */
8
9 #ifdef HAVE_CONFIG_H
10 #include <conf.h>
11 #endif
12
13 #include <SDL.h>
14
15 #include "ogl_init.h"
16 #include "vers_id.h"
17 #include "error.h"
18 #include "u_mem.h"
19 #include "args.h"
20
21 static int curx=-1,cury=-1,curfull=0;
22
23 void ogl_do_fullscreen_internal(void){
24         ogl_init_window(curx,cury);
25 }
26
27 void ogl_swap_buffers_internal(void){
28         SDL_GL_SwapBuffers();
29 }
30
31 int ogl_init_window(int x, int y){
32         if (gl_initialized){
33                 if (x==curx && y==cury && curfull==ogl_fullscreen)
34                         return 0;
35                 if (ogl_fullscreen || curfull)
36                         ogl_smash_texture_list_internal();//if we are or were fullscreen, changing vid mode will invalidate current textures
37         }
38         SDL_WM_SetCaption(DESCENT_VERSION, "Descent II");
39         if (!SDL_SetVideoMode(x,y, 16, SDL_OPENGL | (ogl_fullscreen?SDL_FULLSCREEN:0))) {
40            Error("Could not set %dx%dx16 opengl video mode\n",x,y);
41         }
42         SDL_ShowCursor(0);
43
44         curx=x;cury=y;curfull=ogl_fullscreen;
45         gl_initialized=1;
46
47         return 0;
48 }
49
50 void ogl_destroy_window(void){
51         if (gl_initialized){
52                 ogl_smash_texture_list_internal();
53                 SDL_ShowCursor(1);
54                 //gl_initialized=0;
55                 //well..SDL doesn't really let you kill the window.. so we just need to wait for sdl_quit
56         }
57         return;
58 }
59
60 void ogl_init(void){
61         int t;
62         if ((t=FindArg("-gl_red")))
63                 SDL_GL_SetAttribute( SDL_GL_RED_SIZE, atoi(Args[t+1]) );
64         if ((t=FindArg("-gl_green")))
65                 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, atoi(Args[t+1]) );
66         if ((t=FindArg("-gl_blue")))
67                 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, atoi(Args[t+1]) );
68         if ((t=FindArg("-gl_alpha")))
69                 SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, atoi(Args[t+1]) );
70         if ((t=FindArg("-gl_buffer")))
71                 SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, atoi(Args[t+1]) );
72 //      SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
73 //      SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
74 //      SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
75 //      SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
76
77
78         SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,0);
79         SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,0);
80         SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,0);
81         SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,0);
82         SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,0);
83         SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,0);
84         SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
85
86 }
87
88 void ogl_close(void){
89 #if 0  // shouldn't really be necessary...
90         if (ogl_fullscreen){
91                 ogl_fullscreen=0;
92                 ogl_do_fullscreen_internal();
93         }
94 #endif
95         ogl_destroy_window();
96 }