From 8231f168dff69d940acbc3662fb54b8f17a2b958 Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Tue, 5 Jul 2011 12:30:21 +0300 Subject: [PATCH] Build in Maemo/scratchbox Use the SDL_GLES library by Javispedro. --- Makefile | 14 +++++++++++++- share/config.h | 7 +++++++ share/glext.h | 2 ++ share/sync.c | 2 +- share/syswm.c | 2 +- share/video.c | 40 ++++++++++++++++++++++++++++++++++++++-- 6 files changed, 62 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 675a247..f2cda95 100644 --- a/Makefile +++ b/Makefile @@ -16,12 +16,16 @@ $(info Will make a "$(BUILD)" build of Neverball $(VERSION).) #------------------------------------------------------------------------------ # Provide a target system hint for the Makefile. -# Recognized PLATFORM values: darwin, mingw. +# Recognized PLATFORM values: darwin, mingw, maemo. ifeq ($(shell uname), Darwin) PLATFORM := darwin endif +ifdef _SBOX_DIR + PLATFORM := maemo +endif + #------------------------------------------------------------------------------ # Paths (packagers might want to set DATADIR and LOCALEDIR) @@ -86,6 +90,10 @@ ifeq ($(PLATFORM),darwin) ALL_CPPFLAGS += -I/opt/local/include endif +ifeq ($(PLATFORM),maemo) + ALL_CPPFLAGS += -D__MAEMO__ +endif + ALL_CPPFLAGS += $(CPPFLAGS) #------------------------------------------------------------------------------ @@ -135,6 +143,10 @@ ifeq ($(PLATFORM),darwin) OGL_LIBS := -framework OpenGL endif +ifeq ($(PLATFORM),maemo) + OGL_LIBS := -lm -lSDL_gles -lEGL -lGLES_CM +endif + BASE_LIBS := -ljpeg $(PNG_LIBS) $(FS_LIBS) ifeq ($(PLATFORM),darwin) diff --git a/share/config.h b/share/config.h index b975d12..a53a1c2 100644 --- a/share/config.h +++ b/share/config.h @@ -28,6 +28,13 @@ #include "base_config.h" #include "lang.h" +#ifdef __MAEMO__ +#include +#define SDL_GL_SetAttribute(attr, value) SDL_GLES_SetAttribute(attr, value) +#define SDL_GL_GetAttribute(attr, value) SDL_GLES_GetAttribute(attr, value) +#define SDL_GL_SwapBuffers() SDL_GLES_SwapBuffers() +#endif + /*---------------------------------------------------------------------------*/ /* Integer options. */ diff --git a/share/glext.h b/share/glext.h index 63d7419..10dd679 100644 --- a/share/glext.h +++ b/share/glext.h @@ -25,6 +25,8 @@ #ifdef __APPLE__ #include +#elif defined(__MAEMO__) +#include #else #include #endif diff --git a/share/sync.c b/share/sync.c index 0395ba9..88c7e90 100644 --- a/share/sync.c +++ b/share/sync.c @@ -16,7 +16,7 @@ #include "glext.h" /*---------------------------------------------------------------------------*/ -#if defined(_WIN32) +#if defined(_WIN32) || defined(__MAEMO__) void sync_init(void) { diff --git a/share/syswm.c b/share/syswm.c index 864deda..7a2c6ef 100644 --- a/share/syswm.c +++ b/share/syswm.c @@ -42,7 +42,7 @@ void set_SDL_icon(const char *filename) void set_EWMH_icon(const char *filename) { -#if SDL_VIDEO_DRIVER_X11 && !SDL_VIDEO_DRIVER_QUARTZ +#if SDL_VIDEO_DRIVER_X11 && !SDL_VIDEO_DRIVER_QUARTZ && !ENABLE_OPENGLES SDL_SysWMinfo info; Display *dpy; diff --git a/share/video.c b/share/video.c index b305ae1..c2b3147 100644 --- a/share/video.c +++ b/share/video.c @@ -20,6 +20,9 @@ #include "sync.h" /*---------------------------------------------------------------------------*/ +#ifdef __MAEMO__ +static SDL_GLES_Context *context; +#endif int video_init(const char *title, const char *icon) { @@ -35,6 +38,14 @@ int video_init(const char *title, const char *icon) set_SDL_icon(icon); +#ifdef __MAEMO__ + if (SDL_GLES_Init(SDL_GLES_VERSION_1_1) != 0) + { + fprintf(stderr, "SDL_GLES_Init failed\n"); + return 0; + } +#endif + /* Initialize the video. */ if (!video_mode(config_get_d(CONFIG_FULLSCREEN), @@ -72,20 +83,45 @@ int video_mode(int f, int w, int h) /* Require 16-bit double buffer with 16-bit depth buffer. */ +#ifndef __MAEMO__ /* SDL_GLES already takes care of these */ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); +#endif /* Try to set the currently specified mode. */ - - if (SDL_SetVideoMode(w, h, 0, SDL_OPENGL | (f ? SDL_FULLSCREEN : 0))) + if (SDL_SetVideoMode(w, h, 0, +#ifdef __MAEMO__ + SDL_SWSURFACE | +#else + SDL_OPENGL | +#endif + (f ? SDL_FULLSCREEN : 0))) { config_set_d(CONFIG_FULLSCREEN, f); config_set_d(CONFIG_WIDTH, w); config_set_d(CONFIG_HEIGHT, h); +#ifdef __MAEMO__ + SDL_ShowCursor(SDL_DISABLE); + context = SDL_GLES_CreateContext(); + if (context == 0) + { + fprintf(stderr, "SDL_GLES_CreateContext failed\n"); + fprintf(stderr, "%s\n", SDL_GetError()); + return 0; + } + + if (SDL_GLES_MakeCurrent(context) != 0) + { + fprintf(stderr, "SDL_GLES_MakeCurrent failed\n"); + fprintf(stderr, "%s\n", SDL_GetError()); + return 0; + } +#endif + if (!glext_init()) return 0; -- 1.7.9.5