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