Finished moving stuff to arch/blah. I know, it's ugly, but It'll be easier to sync...
[btb/d2x.git] / arch / ogl / sdlgl.c
1 /*
2  * $Source: /cvs/cvsroot/d2x/arch/ogl/sdlgl.c,v $
3  * $Revision: 1.1 $
4  * $Author: bradleyb $
5  * $Date: 2001-10-25 08:25:34 $
6  *
7  * Graphics functions for SDL-GL.
8  *
9  * $Log: not supported by cvs2svn $
10  * Revision 1.4  2001/10/09 08:17:07  bradleyb
11  * changed window caption to include version info
12  *
13  * Revision 1.3  2001/10/09 02:58:20  bradleyb
14  * Added window caption, hide mouse cursor
15  *
16  * Revision 1.2  2001/01/29 13:47:52  bradleyb
17  * Fixed build, some minor cleanups.
18  *
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include <conf.h>
23 #endif
24
25 #include <SDL/SDL.h>
26 #include <GL/gl.h>
27 #include <string.h>
28 #include "ogl_init.h"
29 #include "vers_id.h"
30 #include "error.h"
31 #include "event.h"
32 #include "mono.h"
33 #include "u_mem.h"
34
35 static int gl_initialized = 0;
36
37 void ogl_do_fullscreen_internal(void){
38     if (ogl_fullscreen)
39     {
40         SDL_Surface *screen;
41
42         screen = SDL_GetVideoSurface();
43         SDL_WM_ToggleFullScreen(screen);
44     }
45
46 }
47
48 inline void ogl_swap_buffers_internal(void){
49         SDL_GL_SwapBuffers();
50 }
51 int ogl_init_window(int x, int y){
52
53         Uint32 video_flags;
54         int bpp = 16;
55
56
57         if (SDL_Init(SDL_INIT_VIDEO) < 0)
58         {
59                 Error("SDL library video initialisation failed: %s.",SDL_GetError());
60         }
61         video_flags = SDL_OPENGL;
62         
63         if (ogl_fullscreen) video_flags |= SDL_FULLSCREEN;
64
65         SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
66         SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
67         SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
68 //        SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 1 );
69         SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, bpp );
70         SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
71
72         SDL_WM_SetCaption(DESCENT_VERSION, "Descent II");
73
74         if ( SDL_SetVideoMode( x, y, bpp, video_flags ) == NULL ) {
75                 fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
76                 SDL_Quit();
77                 exit(1);
78         }
79
80         SDL_ShowCursor(0);
81
82         printf( "Vendor     : %s\n", glGetString( GL_VENDOR ) );
83         printf( "Renderer   : %s\n", glGetString( GL_RENDERER ) );
84         printf( "Version    : %s\n", glGetString( GL_VERSION ) );
85         printf( "Extensions : %s\n", glGetString( GL_EXTENSIONS ) );
86         printf("\n");
87
88                 
89         return 0;
90 }
91 void ogl_destroy_window(void){
92         return;
93 }
94 void ogl_init(void){
95         gl_initialized=1;
96 }
97 void ogl_close(void){
98         ogl_destroy_window();
99 }