]> icculus.org git repositories - btb/d2x.git/blob - arch/ogl/sdlgl.c
smash textures, for non-linux, for real
[btb/d2x.git] / arch / ogl / sdlgl.c
1 /* $Id: sdlgl.c,v 1.8 2003-11-06 23:28:47 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 #ifdef SDL_IMAGE
15 #include <SDL_image.h>
16 #endif
17
18 #include "ogl_init.h"
19 #include "vers_id.h"
20 #include "error.h"
21 #include "u_mem.h"
22 #include "args.h"
23
24 static int curx=-1,cury=-1,curfull=0;
25
26 void ogl_do_fullscreen_internal(void){
27         ogl_init_window(curx,cury);
28 }
29
30 void ogl_swap_buffers_internal(void){
31         SDL_GL_SwapBuffers();
32 }
33
34 int ogl_init_window(int x, int y){
35         if (gl_initialized){
36                 if (x==curx && y==cury && curfull==ogl_fullscreen)
37                         return 0;
38 #ifdef __linux__ // Windows, at least, seems to need to reload every time.
39                 if (ogl_fullscreen || curfull)
40 #endif
41                         ogl_smash_texture_list_internal();//if we are or were fullscreen, changing vid mode will invalidate current textures
42         }
43         SDL_WM_SetCaption(DESCENT_VERSION, "Descent II");
44
45 #ifdef SDL_IMAGE
46         {
47 #include "descent.xpm"
48                 SDL_WM_SetIcon(IMG_ReadXPMFromArray(pixmap), NULL);
49         }
50 #endif
51
52         if (!SDL_SetVideoMode(x,y, 16, SDL_OPENGL | (ogl_fullscreen?SDL_FULLSCREEN:0))) {
53            Error("Could not set %dx%dx16 opengl video mode\n",x,y);
54         }
55         SDL_ShowCursor(0);
56
57         curx=x;cury=y;curfull=ogl_fullscreen;
58         gl_initialized=1;
59
60         return 0;
61 }
62
63 void ogl_destroy_window(void){
64         if (gl_initialized){
65                 ogl_smash_texture_list_internal();
66                 SDL_ShowCursor(1);
67                 //gl_initialized=0;
68                 //well..SDL doesn't really let you kill the window.. so we just need to wait for sdl_quit
69         }
70         return;
71 }
72
73 void ogl_init(void){
74         int t;
75         if ((t=FindArg("-gl_red")))
76                 SDL_GL_SetAttribute( SDL_GL_RED_SIZE, atoi(Args[t+1]) );
77         if ((t=FindArg("-gl_green")))
78                 SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, atoi(Args[t+1]) );
79         if ((t=FindArg("-gl_blue")))
80                 SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, atoi(Args[t+1]) );
81         if ((t=FindArg("-gl_alpha")))
82                 SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, atoi(Args[t+1]) );
83         if ((t=FindArg("-gl_buffer")))
84                 SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, atoi(Args[t+1]) );
85 //      SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
86 //      SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
87 //      SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
88 //      SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );
89
90
91         SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,0);
92         SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,0);
93         SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,0);
94         SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,0);
95         SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,0);
96         SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,0);
97         SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
98
99 }
100
101 void ogl_close(void){
102 #if 0  // shouldn't really be necessary...
103         if (ogl_fullscreen){
104                 ogl_fullscreen=0;
105                 ogl_do_fullscreen_internal();
106         }
107 #endif
108         ogl_destroy_window();
109 }