Build in Maemo/scratchbox
authorAlberto Mardegan <mardy@users.sourceforge.net>
Tue, 5 Jul 2011 09:30:21 +0000 (12:30 +0300)
committerAlberto Mardegan <mardy@users.sourceforge.net>
Tue, 5 Jul 2011 14:16:47 +0000 (17:16 +0300)
Use the SDL_GLES library by Javispedro.

Makefile
share/config.h
share/glext.h
share/sync.c
share/syswm.c
share/video.c

index 675a247..f2cda95 100644 (file)
--- 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)
index b975d12..a53a1c2 100644 (file)
 #include "base_config.h"
 #include "lang.h"
 
+#ifdef __MAEMO__
+#include <SDL_gles.h>
+#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. */
index 63d7419..10dd679 100644 (file)
@@ -25,6 +25,8 @@
 
 #ifdef __APPLE__
 #include <OpenGL/gl.h>
+#elif defined(__MAEMO__)
+#include <GLES/gl.h>
 #else
 #include <GL/gl.h>
 #endif
index 0395ba9..88c7e90 100644 (file)
@@ -16,7 +16,7 @@
 #include "glext.h"
 
 /*---------------------------------------------------------------------------*/
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__MAEMO__)
 
 void sync_init(void)
 {
index 864deda..7a2c6ef 100644 (file)
@@ -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;
index b305ae1..c2b3147 100644 (file)
@@ -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;