]> icculus.org git repositories - divverent/darkplaces.git/blob - vid_sdl.c
cleaned up rtlight handling, merging most code between world rtlights and dlights...
[divverent/darkplaces.git] / vid_sdl.c
1 /*
2 Copyright (C) 2003  T. Joseph Carter
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19
20 #include <SDL.h>
21 #include <stdio.h>
22
23 #include "quakedef.h"
24
25 // Tell startup code that we have a client
26 int cl_available = true;
27
28 static SDL_Surface *screen;
29
30 void *GL_GetProcAddress(const char *name)
31 {
32         void *p = NULL;
33         p = SDL_GL_GetProcAddress(name);
34         return p;
35 }
36
37 void VID_Init (void)
38 {
39         if (SDL_Init(SDL_INIT_VIDEO) < 0)
40                 printf ("Failed to init video: %s\n", SDL_GetError());
41 }
42
43 int VID_InitMode(int fullscreen, int width, int height, int bpp)
44 {
45         int i;
46         int flags = SDL_OPENGL;
47         char *drivername;
48
49 #ifdef WIN32
50         drivername = "opengl32.dll";
51 #elif defined(__APPLE__) && defined(__MACH__)
52         drivername = "OpenGL.framework";
53 #else
54         drivername = "libGL.so.1";
55 #endif
56
57         i = COM_CheckParm("-gl_driver");
58         if (i && i < com_argc - 1)
59                 drivername = com_argv[i + 1];
60         if (!SDL_GL_LoadLibrary(drivername))
61         {   
62                 Con_Printf("Unable to load GL driver \"%s\"\n: ", drivername, SDL_GetError());
63                 return false;
64         }
65
66         qglGetString = GL_GetProcAddress("glGetString");
67         
68         // Knghtbrd: should do platform-specific extension string function here
69
70         if (qglGetString == NULL)
71         {
72                 VID_Shutdown();
73                 Con_Printf("Required OpenGL function glGetString not found\n");
74                 return false;
75         }
76
77 //      if (fullscreen)
78 //              flags |= SDL_FULLSCREEN;
79
80         SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 1);
81         SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 1);
82         SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 1);
83         SDL_GL_SetAttribute (SDL_GL_DEPTH_SIZE, 16);
84         SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
85
86         screen = SDL_SetVideoMode(width, height, bpp, flags);
87         if (screen == NULL)
88         {
89                 Con_Printf("Failed to set video mode to %ix%i: %s\n", width, height, SDL_GetError);
90                 VID_Shutdown();
91                 return false;
92         }
93         
94         gl_renderer = qglGetString(GL_RENDERER);
95         gl_vendor = qglGetString(GL_VENDOR);
96         gl_version = qglGetString(GL_VERSION);
97         gl_extensions = qglGetString(GL_EXTENSIONS);
98         gl_platform = "SDL";
99         // Knghtbrd: should assign platform-specific extensions here
100         gl_platformextensions = "";
101         
102         GL_Init();
103
104         vid_hidden = false;
105         return true;
106 }
107
108 void VID_Shutdown (void)
109 {
110 //      SDL_Quit();
111 }
112
113 int VID_SetGamma (unsigned short *ramps)
114 {
115         return false;
116 }
117
118 int VID_GetGamma (unsigned short *ramps)
119 {
120         return false;
121 }
122
123 void VID_GetWindowSize (int *x, int *y, int *width, int *height)
124 {
125         *x = *y = 0;
126         *width = screen->w;
127         *height = screen->h;
128 }
129
130 void VID_Finish (void)
131 {
132         qglFinish();
133         SDL_GL_SwapBuffers();
134 }
135
136 void IN_Commands (void)
137 {
138 }
139
140 void IN_Move (usercmd_t *cmd)
141 {
142 }
143
144 void Sys_SendKeyEvents (void)
145 {
146 }
147