Commits

Bart van Strien committed fa9a0b1

Initial version of love.graphics.sdl

  • Participants
  • Parent commits 77d1546

Comments (0)

Files changed (8)

platform/unix/configure.in

 AC_C_BIGENDIAN
 AC_SEARCH_LIBS([sqrt], [m], [], AC_MSG_ERROR([Can't LÖVE without C math library]))
 AC_SEARCH_LIBS([SDL_Init], [SDL], [], AC_MSG_ERROR([Can't LÖVE without SDL]))
-AC_SEARCH_LIBS([glLoadIdentity], [GL], [], AC_MSG_ERROR([Can't LÖVE without OpenGL]))
+#AC_SEARCH_LIBS([glLoadIdentity], [GL], [], AC_MSG_ERROR([Can't LÖVE without OpenGL]))
 #AC_SEARCH_LIBS([gluOrtho2D], [GLU], [], AC_MSG_ERROR([Can't LÖVE without OpenGL Utility Library]))
+AC_SEARCH_LIBS([SDL_gfxSetAlpha], [SDL_gfx], [], AC_MSG_ERROR([Can't nLÖVE without SDL Gfx]))
 AC_SEARCH_LIBS([alSourcePlay], [openal], [], AC_MSG_ERROR([Can't LÖVE without OpenAL]))
 lua=lua
 AC_ARG_WITH([luajit],

platform/unix/exclude

 ./modules/thread/win32/*
 ./modules/thread/posix/*
 ./launcher.cpp
+./modules/graphics/opengl/*

src/modules/graphics/sdl/Graphics.cpp

+/**
+* Copyright (c) 2006-2012 LOVE Development Team
+*
+* This software is provided 'as-is', without any express or implied
+* warranty.  In no event will the authors be held liable for any damages
+* arising from the use of this software.
+*
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not
+*    claim that you wrote the original software. If you use this software
+*    in a product, an acknowledgment in the product documentation would be
+*    appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+*    misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+**/
+
+// LOVE
+#include "Graphics.h"
+
+#include <window/sdl/Window.h>
+
+namespace love
+{
+namespace graphics
+{
+namespace sdl
+{
+	Graphics::Graphics()
+	{
+		currentWindow = love::window::sdl::Window::getSingleton();
+	}
+
+	Graphics::~Graphics()
+	{
+		currentWindow->release();
+	}
+
+	const char *Graphics::getName() const
+	{
+		return "love.graphics.sdl";
+	}
+
+	bool Graphics::setMode(int width, int height, bool fullscreen, bool vsync, int fsaa)
+	{
+		return currentWindow->setWindow(width, height, fullscreen, vsync, fsaa);
+	}
+
+	void Graphics::getMode(int &width, int &height, bool &fullscreen, bool &vsync, int &fsaa)
+	{
+		currentWindow->getWindow(width, height, fullscreen, vsync, fsaa);
+	}
+
+	bool Graphics::toggleFullscreen()
+	{
+		int width, height, fsaa;
+		bool fullscreen, vsync;
+		currentWindow->getWindow(width, height, fullscreen, vsync, fsaa);
+		return setMode(width, height, !fullscreen, vsync, fsaa);
+	}
+
+	bool Graphics::checkMode(int width, int height, bool fullscreen)
+	{
+		return currentWindow->checkWindowSize(width, height, fullscreen);
+	}
+
+	bool Graphics::isCreated()
+	{
+		return currentWindow->isCreated();
+	}
+
+	int Graphics::getWidth()
+	{
+		return currentWindow->getWidth();
+	}
+
+	int Graphics::getHeight()
+	{
+		return currentWindow->getHeight();
+	}
+} // sdl
+} // graphics
+} // love

src/modules/graphics/sdl/Graphics.h

+/**
+* Copyright (c) 2006-2012 LOVE Development Team
+*
+* This software is provided 'as-is', without any express or implied
+* warranty.  In no event will the authors be held liable for any damages
+* arising from the use of this software.
+*
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not
+*    claim that you wrote the original software. If you use this software
+*    in a product, an acknowledgment in the product documentation would be
+*    appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+*    misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+**/
+
+#ifndef LOVE_GRAPHICS_SDL_GRAPHICS_H
+#define LOVE_GRAPHICS_SDL_GRAPHICS_H
+
+// LOVE
+#include <graphics/Graphics.h>
+#include <graphics/Color.h>
+
+#include <image/Image.h>
+#include <image/ImageData.h>
+
+#include <window/Window.h>
+
+#include "Image.h"
+
+namespace love
+{
+namespace graphics
+{
+namespace sdl
+{
+	class Graphics : public love::graphics::Graphics
+	{
+	private:
+		love::window::Window *currentWindow;
+
+	public:
+		Graphics();
+		virtual ~Graphics();
+
+		const char *getName() const;
+
+		bool setMode(int width, int height, bool fullscreen, bool vsync, int fsaa);
+		void getMode(int &width, int &height, bool &fullscreen, bool &vsync, int &fsaa);
+		bool toggleFullscreen();
+		bool checkMode(int width, int height, bool fullscreen);
+		bool isCreated();
+		int getWidth();
+		int getHeight();
+
+/*		void reset();
+		void clear();
+		void present();
+
+		void setCaption(const char *caption);
+		const char *getCaption();
+
+		Image *newImage(love::filesystem::File *file);
+		Image *newImage(love::image::ImageData *data);
+		Quad *newQuad(float x, float y, float w, float h, float sw, float sh);
+
+		void setColor(const Color &c);
+		Color getColor();
+		void setBackgroundColor(const Color &c);
+		Color getBackgroundColor();
+
+		void point(float x, float y);
+		void triangle(DrawMode mode, float x1, float y1, float x2, float y2, float x3, float y3);
+		void rectangle(DrawMode mode, float x, float y, float w, float h);
+		void quad(DrawMode mode, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
+		void circle(DrawMode mode, float x, float y, float radius, int points = 10);*/
+	}; // Graphics
+} // sdl
+} // graphics
+} // love
+
+#endif // LOVE_GRAPHICS_SDL_GRAPHICS_H

src/modules/graphics/sdl/Image.h

+/**
+* Copyright (c) 2006-2012 LOVE Development Team
+*
+* This software is provided 'as-is', without any express or implied
+* warranty.  In no event will the authors be held liable for any damages
+* arising from the use of this software.
+*
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not
+*    claim that you wrote the original software. If you use this software
+*    in a product, an acknowledgment in the product documentation would be
+*    appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+*    misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+**/
+
+#ifndef LOVE_GRAPHICS_SDL_IMAGE_H
+#define LOVE_GRAPHICS_SDL_IMAGE_H
+
+// LOVE
+#include <common/Matrix.h>
+#include <common/math.h>
+#include <common/config.h>
+#include <image/ImageData.h>
+#include <graphics/Image.h>
+
+namespace love
+{
+namespace graphics
+{
+namespace sdl
+{
+	class Image : public love::graphics::Image
+	{
+		Image(love::image::ImageData *data);
+		virtual ~Image();
+
+		float getWidth() const;
+		float getHeight() const;
+
+		love::image::ImageData *getData() const;
+
+		void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky);
+		void drawq(love::graphics::Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky);
+
+		bool loadVolatile();
+		void unloadVolatile();
+	}; // Image
+} // sdl
+} // graphics
+} // love
+
+#endif // LOVE_GRAPHICS_SDL_IMAGE_H

src/modules/graphics/sdl/wrap_Graphics.cpp

+/**
+* Copyright (c) 2006-2012 LOVE Development Team
+*
+* This software is provided 'as-is', without any express or implied
+* warranty.  In no event will the authors be held liable for any damages
+* arising from the use of this software.
+*
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not
+*    claim that you wrote the original software. If you use this software
+*    in a product, an acknowledgment in the product documentation would be
+*    appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+*    misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+**/
+
+#include "wrap_Graphics.h"
+
+namespace love
+{
+namespace graphics
+{
+namespace sdl
+{
+	static Graphics *instance = 0;
+
+	int w_setMode(lua_State *L)
+	{
+		int w = luaL_checkint(L, 1);
+		int h = luaL_checkint(L, 2);
+		bool fs = luax_optboolean(L, 3, false);
+		bool vsync = luax_optboolean(L, 4, true);
+		int fsaa = luaL_optint(L, 5, 0);
+		luax_pushboolean(L, instance->setMode(w, h, fs, vsync, fsaa));
+		return 1;
+	}
+
+	int w_getMode(lua_State *L)
+	{
+		int w, h, fsaa;
+		bool fs, vsync;
+		instance->getMode(w, h, fs, vsync, fsaa);
+		lua_pushinteger(L, w);
+		lua_pushinteger(L, h);
+		luax_pushboolean(L, fs);
+		luax_pushboolean(L, vsync);
+		lua_pushinteger(L, fsaa);
+		return 5;
+	}
+
+	int w_toggleFullscreen(lua_State *L)
+	{
+		luax_pushboolean(L, instance->toggleFullscreen());
+		return 1;
+	}
+
+	int w_checkMode(lua_State *L)
+	{
+		int w = luaL_checkint(L, 1);
+		int h = luaL_checkint(L, 2);
+		bool fs = luax_optboolean(L, 3, false);
+		luax_pushboolean(L, instance->checkMode(w, h, fs));
+		return 1;
+	}
+
+	int w_isCreated(lua_State *L)
+	{
+		luax_pushboolean(L, instance->isCreated());
+		return 1;
+	}
+
+	int w_getWidth(lua_State *L)
+	{
+		lua_pushinteger(L, instance->getWidth());
+		return 1;
+	}
+
+	int w_getHeight(lua_State *L)
+	{
+		lua_pushinteger(L, instance->getHeight());
+		return 1;
+	}
+
+	// List of functions to wrap.
+	static const luaL_Reg functions[] = {
+		{ "setMode", w_setMode },
+		{ "getMode", w_getMode },
+		{ "toggleFullscreen", w_toggleFullscreen },
+		{ "checkMode", w_checkMode },
+		{ "isCreated", w_isCreated },
+		{ "getWidth", w_getWidth },
+		{ "getHeight", w_getHeight },
+		{ 0, 0 }
+	};
+
+	static const lua_CFunction types[] = {
+		0
+	};
+
+	extern "C" int luaopen_love_graphics(lua_State *L)
+	{
+		if (instance == 0)
+		{
+			try
+			{
+				instance = new Graphics();
+			}
+			catch (Exception & e)
+			{
+				return luaL_error(L, e.what());
+			}
+		}
+		else
+			instance->retain();
+
+		WrappedModule w;
+		w.module = instance;
+		w.name = "graphics";
+		w.flags = MODULE_T;
+		w.functions = functions;
+		w.types = types;
+
+		return luax_register_module(L, w);
+	}
+} // sdl
+} // graphics
+} // love

src/modules/graphics/sdl/wrap_Graphics.h

+/**
+* Copyright (c) 2006-2012 LOVE Development Team
+*
+* This software is provided 'as-is', without any express or implied
+* warranty.  In no event will the authors be held liable for any damages
+* arising from the use of this software.
+*
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+*
+* 1. The origin of this software must not be misrepresented; you must not
+*    claim that you wrote the original software. If you use this software
+*    in a product, an acknowledgment in the product documentation would be
+*    appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+*    misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+**/
+
+#ifndef LOVE_GRAPHICS_SDL_WRAP_GRAPHICS_H
+#define LOVE_GRAPHICS_SDL_WRAP_GRAPHICS_H
+
+#include "Graphics.h"
+
+namespace love
+{
+namespace graphics
+{
+namespace sdl
+{
+	int w_setMode(lua_State *L);
+	int w_getMode(lua_State *L);
+	int w_toggleFullscreen(lua_State *L);
+	int w_checkMode(lua_State *L);
+	int w_isCreated(lua_State *L);
+	int w_getWidth(lua_State *L);
+	int w_getHeight(lua_State *L);
+/*	int w_reset(lua_State *L);
+	int w_clear(lua_State *L);
+	int w_present(lua_State *L);
+	int w_setCaption(lua_State *L);
+	int w_getCaption(lua_State *L);
+	int w_newImage(lua_State *L);
+	int w_newQuad(lua_State *L);
+	int w_setColor(lua_State *L);
+	int w_getColor(lua_State *L);
+	int w_setBackgroundColor(lua_State *L);
+	int w_getBackgroundColor(lua_State *L);
+	int w_point(lua_State *L);
+	int w_triangle(lua_State *L);
+	int w_rectangle(lua_State *L);
+	int w_quad(lua_State *L);
+	int w_circle(lua_State *L);*/
+	extern "C" LOVE_EXPORT int luaopen_love_graphics(lua_State *L);
+} // sdl
+} // graphics
+} // love
+
+#endif // LOVE_GRAPHICS_SDL_WRAP_GRAPHICS_H

src/modules/window/sdl/Window.cpp

 #include <SDL.h>
 
 // OpenGL
-#include <SDL/SDL_opengl.h>
+//#include <SDL/SDL_opengl.h>
 
 // LOVE
 #include <common/config.h>
 		setWindowTitle(windowTitle);
 		setMouseVisible(mouseVisible);
 
-		// Set GL attributes
+/*		// Set GL attributes
 		SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
 		SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
 		SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
 		{
 			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
 			SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa);
-		}
+		}*/
 
 		// Fullscreen?
-		Uint32 sdlflags = fullscreen ? (SDL_OPENGL | SDL_FULLSCREEN) : SDL_OPENGL;
+		//Uint32 sdlflags = fullscreen ? (SDL_OPENGL | SDL_FULLSCREEN) : SDL_OPENGL;
+		Uint32 sdlflags = fullscreen ? SDL_FULLSCREEN : 0;
 
 		// Have SDL set the video mode.
 		if (SDL_SetVideoMode(width, height, 32, sdlflags) == 0)
 			if (fsaa > 0)
 			{
 				// FSAA might have failed, disable it and try again
-				SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
+				//SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
 				failed = SDL_SetVideoMode(width, height, 32, sdlflags) == 0;
 				if (failed)
 				{
 					// There might be no FSAA at all
-					SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
+					//SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
 					failed = SDL_SetVideoMode(width, height, 32, sdlflags) == 0;
 				}
 			}
 			height = videoinfo->current_h;
 		}
 
-		if (fsaa > 0)
+		/*if (fsaa > 0)
 			glEnable(GL_MULTISAMPLE);
 
 		GLint buffers;
 
 		// Get the actual vsync status
 		int real_vsync;
-		SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &real_vsync);
+		SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &real_vsync);*/
 
 		// Set the new display mode as the current display mode.
 		currentMode.width = width;
 		currentMode.height = height;
 		currentMode.fsaa = fsaa;
 		currentMode.fullscreen = fullscreen;
-		currentMode.vsync = (real_vsync != 0);
+		currentMode.vsync = vsync;
 
 		return true;
 	}
 
 	bool Window::checkWindowSize(int width, int height, bool fullscreen)
 	{
-		Uint32 sdlflags = fullscreen ? (SDL_OPENGL | SDL_FULLSCREEN) : SDL_OPENGL;
+		//Uint32 sdlflags = fullscreen ? (SDL_OPENGL | SDL_FULLSCREEN) : SDL_OPENGL;
+		Uint32 sdlflags = fullscreen ? SDL_FULLSCREEN : 0;
 
 		// Check if mode is supported
 		int bpp = SDL_VideoModeOK(width, height, 32, sdlflags);
 
 	WindowSize **Window::getFullscreenSizes(int &n)
 	{
-		SDL_Rect ** modes = SDL_ListModes(0, SDL_OPENGL | SDL_FULLSCREEN);
+		SDL_Rect ** modes = SDL_ListModes(0, /*SDL_OPENGL | */SDL_FULLSCREEN);
 
 		if (modes == (SDL_Rect **)0 || modes == (SDL_Rect **)-1)
 		{
 
 	void Window::swapBuffers()
 	{
-		SDL_GL_SwapBuffers();
+		//SDL_GL_SwapBuffers();
 	}
 
 	bool Window::hasFocus()