about summary refs log tree commit diff
path: root/src/engine/client/ec_gfx.c
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-10-20 17:47:42 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-10-20 17:47:42 +0000
commit8404143afe48c04e0c84a9bbde08ebf400b7f7fb (patch)
tree555522478fb9ea05bbd4a9dd65c5124874252f13 /src/engine/client/ec_gfx.c
parent2b9688f3c3085e4fb07906a71bbedb8a6b916a59 (diff)
downloadzcatch-8404143afe48c04e0c84a9bbde08ebf400b7f7fb.tar.gz
zcatch-8404143afe48c04e0c84a9bbde08ebf400b7f7fb.zip
added SDL support
Diffstat (limited to 'src/engine/client/ec_gfx.c')
-rw-r--r--src/engine/client/ec_gfx.c144
1 files changed, 142 insertions, 2 deletions
diff --git a/src/engine/client/ec_gfx.c b/src/engine/client/ec_gfx.c
index 9a1e70bf..6a760be7 100644
--- a/src/engine/client/ec_gfx.c
+++ b/src/engine/client/ec_gfx.c
@@ -1,5 +1,13 @@
 /* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
-#include <GL/glfw.h>
+
+#ifdef CONFIG_NO_SDL
+	#include <GL/glfw.h>
+#else
+	#include <SDL/SDL.h>
+	#include <GL/gl.h>
+	#include <GL/glu.h>
+#endif
+
 #include <engine/external/pnglite/pnglite.h>
 
 #include <base/system.h>
@@ -77,6 +85,11 @@ static TEXTURE textures[MAX_TEXTURES];
 static int first_free_texture;
 static int memory_usage = 0;
 
+#ifdef CONFIG_NO_SDL
+#else
+	SDL_Surface *screen_surface;
+#endif
+
 
 #if 0
 typedef struct { unsigned char r, g, b, a; } PIXEL;
@@ -289,12 +302,14 @@ static void draw_quad()
 		flush();
 }
 
+#ifdef CONFIG_NO_SDL
 static void screen_resize(int width, int height)
 {
 	screen_width = width;
 	screen_height = height;
 	glViewport(0, 0, screen_width, screen_height);
 }
+#endif
 
 int gfx_init()
 {
@@ -303,7 +318,6 @@ int gfx_init()
 	screen_width = config.gfx_screen_width;
 	screen_height = config.gfx_screen_height;
 
-	glfwInit();
 
 	if(config.dbg_stress)
 	{
@@ -311,6 +325,10 @@ int gfx_init()
 		screen_height = 240;
 	}
 
+
+#ifdef CONFIG_NO_SDL
+	glfwInit();
+
 	/* set antialiasing	*/
 	if(config.gfx_fsaa_samples)
 		glfwOpenWindowHint(GLFW_FSAA_SAMPLES, config.gfx_fsaa_samples);
@@ -357,6 +375,62 @@ int gfx_init()
 	/* We don't want to see the window when we run the stress testing */
 	if(config.dbg_stress)
 		glfwIconifyWindow();
+#else
+	if(SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0)
+	{
+        dbg_msg("gfx", "Unable to init SDL: %s\n", SDL_GetError());
+        return -1;
+    }
+	
+    atexit(SDL_Quit);
+
+	{
+		const SDL_VideoInfo *info;
+		int flags = SDL_OPENGL;
+		
+		info = SDL_GetVideoInfo();
+
+		/* set flags */
+		flags  = SDL_OPENGL;
+		flags |= SDL_GL_DOUBLEBUFFER;
+		flags |= SDL_HWPALETTE;
+		flags |= SDL_RESIZABLE;
+
+		if(info->hw_available)
+			flags |= SDL_HWSURFACE;
+		else
+			flags |= SDL_SWSURFACE;
+
+		if(info->blit_hw)
+			flags |= SDL_HWACCEL;
+
+		if(config.gfx_fullscreen)
+			flags |= SDL_FULLSCREEN;
+
+		/* set gl attributes */
+		if(config.gfx_fsaa_samples)
+		{
+			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
+			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, config.gfx_fsaa_samples);
+		}
+
+		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+
+		/* set caption */
+		SDL_WM_SetCaption("Teeworlds", "Teeworlds");
+		
+		/* create window */
+		screen_surface = SDL_SetVideoMode(screen_width, screen_height, 0, flags);
+		if(screen_surface == NULL)
+		{
+	        dbg_msg("gfx", "Unable to set video mode: %s\n", SDL_GetError());
+    	    return -1;
+		}
+	}
+	
+	SDL_ShowCursor(0);
+
+#endif
 	
 	/* Init vertices */
 	if (vertices)
@@ -447,12 +521,20 @@ void gfx_mask_op(int mask, int write)
 
 int gfx_window_active()
 {
+#ifdef CONFIG_NO_SDL
 	return glfwGetWindowParam(GLFW_ACTIVE) == GL_TRUE ? 1 : 0;
+#else
+	return 1; /* TODO: SDL*/
+#endif
 }
 
 int gfx_window_open()
 {
+#ifdef CONFIG_NO_SDL
 	return glfwGetWindowParam(GLFW_OPENED) == GL_TRUE ? 1 : 0;
+#else
+	return 1; /* TODO: SDL*/
+#endif
 }
 
 VIDEO_MODE fakemodes[] = {
@@ -490,12 +572,52 @@ int gfx_get_video_modes(VIDEO_MODE *list, int maxcount)
 		return count;
 	}
 	
+#ifdef CONFIG_NO_SDL
 	return glfwGetVideoModes((GLFWvidmode *)list, maxcount);
+#else
+	{
+		/* TODO: fix this code on osx or windows */
+		int num_modes = 0;
+		SDL_Rect **modes;
+			
+		modes = SDL_ListModes(NULL, SDL_OPENGL|SDL_GL_DOUBLEBUFFER|SDL_FULLSCREEN);
+		if(modes == NULL)
+		{
+			/* no modes */
+		}
+		else if(modes == (SDL_Rect**)-1)
+		{
+			/* all modes */
+		}
+		else
+		{
+			int i;
+			for(i = 0; modes[i]; ++i)
+			{
+				if(num_modes == maxcount)
+					break;
+				list[num_modes].width = modes[i]->w;
+				list[num_modes].height = modes[i]->h;
+				list[num_modes].red = 8;
+				list[num_modes].green = 8;
+				list[num_modes].blue = 8;
+				num_modes++;
+			}
+		}
+	}
+	
+
+	return 1; /* TODO: SDL*/
+#endif	
 }
 
 void gfx_set_vsync(int val)
 {
+#ifdef CONFIG_NO_SDL
 	glfwSwapInterval(val);
+#else
+	/* TODO: SDL*/
+#endif	
 }
 
 int gfx_unload_texture(int index)
@@ -697,8 +819,13 @@ void gfx_shutdown()
 {
 	if (vertices)
 		mem_free(vertices);
+#ifdef CONFIG_NO_SDL
 	glfwCloseWindow();
 	glfwTerminate();
+#else
+	/* TODO: SDL, is this correct? */
+	SDL_Quit();
+#endif	
 }
 
 void gfx_screenshot()
@@ -783,19 +910,26 @@ void gfx_swap()
 	{
 		static PERFORMACE_INFO pscope = {"glfwSwapBuffers", 0};
 		perf_start(&pscope);
+#ifdef CONFIG_NO_SDL
 		glfwSwapBuffers();
+#else
+		SDL_GL_SwapBuffers();
+#endif
 		perf_end();
 	}
 	
 	if(render_enable && config.gfx_finish)
 		glFinish();
 
+#ifdef CONFIG_NO_SDL
 	{
 		static PERFORMACE_INFO pscope = {"glfwPollEvents", 0};
 		perf_start(&pscope);
 		glfwPollEvents();
 		perf_end();
 	}
+#else
+#endif
 }
 
 void gfx_screenshot_direct(const char *filename)
@@ -1350,10 +1484,16 @@ void gfx_clip_disable()
 
 void gfx_minimize()
 {
+#ifdef CONFIG_NO_SDL
 	glfwIconifyWindow();
+#else
+#endif
 }
 
 void gfx_maximize()
 {
+#ifdef CONFIG_NO_SDL
 	glfwRestoreWindow();
+#else
+#endif
 }