diff --git a/CMakeLists.txt b/CMakeLists.txt index 1960a4aed..582a4af0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -195,6 +195,10 @@ ELSE(WIN32) TARGET_LINK_LIBRARIES(commandergenius stlportstlg) ENDIF (STLPORT) + IF (OPENGL) + TARGET_LINK_LIBRARIES(commandergenius GL) + ENDIF (OPENGL) + SET_TARGET_PROPERTIES(commandergenius PROPERTIES OUTPUT_NAME bin/commandergenius) ENDIF(WIN32) diff --git a/build/Android/project/jni/sdl/src/video/android/SDL_androidvideo.c b/build/Android/project/jni/sdl/src/video/android/SDL_androidvideo.c index a47546701..d043dbf9c 100644 --- a/build/Android/project/jni/sdl/src/video/android/SDL_androidvideo.c +++ b/build/Android/project/jni/sdl/src/video/android/SDL_androidvideo.c @@ -79,11 +79,14 @@ static void ANDROID_UpdateRects(_THIS, int numrects, SDL_Rect *rects); static int sWindowWidth = 320; static int sWindowHeight = 480; static SDL_sem * WaitForNativeRender = NULL; +static SDL_sem * WaitForNativeRender1 = NULL; // Pointer to in-memory video surface static int memX = 0; static int memY = 0; static void * memBuffer = NULL; static SDL_Thread * mainThread = NULL; +static enum { GL_State_Init, GL_State_Ready, GL_State_Uninit, GL_State_Uninit2 } openglInitialized = GL_State_Uninit2; +static GLuint texture = 0; static SDLKey keymap[KEYCODE_LAST+1]; @@ -183,6 +186,7 @@ int ANDROID_VideoInit(_THIS, SDL_PixelFormat *vformat) SDL_modelist[3] = NULL; WaitForNativeRender = SDL_CreateSemaphore(0); + WaitForNativeRender1 = SDL_CreateSemaphore(0); /* We're done! */ return(0); } @@ -201,18 +205,37 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, SDL_free( this->hidden->buffer ); } - this->hidden->buffer = SDL_malloc(width * height * (bpp / 8)); + memX = width; + memY = height; + + /* + // Texture sizes should be 2^n + if( memX <= 256 ) + memX = 256; + else if( memX <= 512 ) + memX = 512; + else + memX = 1024; + + if( memY <= 256 ) + memY = 256; + else if( memY <= 512 ) + memY = 512; + else + memY = 1024; + */ + + this->hidden->buffer = SDL_malloc(memX * memY * (bpp / 8)); if ( ! this->hidden->buffer ) { SDL_SetError("Couldn't allocate buffer for requested mode"); return(NULL); } - memX = width; - memY = height; memBuffer = this->hidden->buffer; + openglInitialized = GL_State_Init; /* printf("Setting mode %dx%d\n", width, height); */ - SDL_memset(this->hidden->buffer, 0, width * height * (bpp / 8)); + SDL_memset(this->hidden->buffer, 0, memX * memY * (bpp / 8)); /* Allocate the new pixel format for the screen */ if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { @@ -226,7 +249,7 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, current->flags = flags & SDL_FULLSCREEN; this->hidden->w = current->w = width; this->hidden->h = current->h = height; - current->pitch = current->w * (bpp / 8); + current->pitch = memX * (bpp / 8); current->pixels = this->hidden->buffer; /* We're done */ @@ -234,6 +257,7 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, } /* We don't actually allow hardware surfaces other than the main one */ +// TODO: use OpenGL textures here static int ANDROID_AllocHWSurface(_THIS, SDL_Surface *surface) { return(-1); @@ -256,12 +280,16 @@ static void ANDROID_UnlockHWSurface(_THIS, SDL_Surface *surface) static void ANDROID_UpdateRects(_THIS, int numrects, SDL_Rect *rects) { - /* do nothing. */ + //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Frame is ready to render"); + SDL_SemPost(WaitForNativeRender); + if( SDL_SemWaitTimeout( WaitForNativeRender1, 400 ) == 0 ) + { + //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Frame rendering done"); + } } int ANDROID_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) { - /* do nothing of note. */ return(1); } @@ -270,9 +298,18 @@ int ANDROID_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) */ void ANDROID_VideoQuit(_THIS) { + openglInitialized = GL_State_Uninit; + while( openglInitialized != GL_State_Uninit2 ) + SDL_Delay(50); + memX = 0; memY = 0; memBuffer = NULL; + SDL_DestroySemaphore( WaitForNativeRender ); + WaitForNativeRender = NULL; + SDL_DestroySemaphore( WaitForNativeRender1 ); + WaitForNativeRender1 = NULL; + int i; if (this->screen->pixels != NULL) @@ -287,14 +324,10 @@ void ANDROID_VideoQuit(_THIS) SDL_modelist[i] = NULL; } } - SDL_DestroySemaphore( WaitForNativeRender ); - WaitForNativeRender = NULL; } void ANDROID_PumpEvents(_THIS) { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Frame is ready to render"); - SDL_SemPost(WaitForNativeRender); } /* JNI-C++ wrapper stuff */ @@ -303,7 +336,7 @@ extern int main( int argc, char ** argv ); static int SDLCALL MainThreadWrapper(void * dummy) { int argc = 1; - char * argv[] = { "demo" }; + char * argv[] = { "sdl" }; return main( argc, argv ); }; @@ -382,154 +415,158 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeKey) ( JNIEnv* env, jobject thiz, jin SDL_PrivateKeyboard( action ? SDL_PRESSED : SDL_RELEASED, TranslateKey(key, &keysym) ); } -gluPerspectivef(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar) -{ - GLfloat xmin, xmax, ymin, ymax; - - ymax = zNear * tan(fovy * M_PI / 360.0f); - ymin = -ymax; - xmin = ymin * aspect; - xmax = ymax * aspect; - glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar); -}; - /* Call to render the next GL frame */ extern void JAVA_EXPORT_NAME(DemoRenderer_nativeRender) ( JNIEnv* env, jobject thiz ) { - //__android_log_print(ANDROID_LOG_INFO, "libSDL", "rendering frame..."); - - static float bounceColor = 0.0f; - static float bounceDir = 1.0f; - - static GLfloat vertexData [] = { - -0.5f, -0.5f, 0.5f, - 0.5f, -0.5f, 0.5f, - -0.5f, 0.5f, 0.5f, - 0.5f, 0.5f, 0.5f - }; - static GLfloat textureData [] = { - 0.0f, 0.0f, - 1.0f, 0.0f, - 0.0f, 1.0f, - 1.0f, 1.0f, - }; - - char tmp[512]; - - GLuint texture[1]; - - /* - // Show that we're doing something (just flash the screen) - bounceColor += 0.005f * bounceDir; - if( bounceColor >= 1.0f ) - bounceDir = -1.0f; - if( bounceColor <= 0.0f ) - bounceDir = 1.0f; - //glClearColor(0.0f, 0.0f, 0.0f, 0.5f); - glClearColor(bounceColor, bounceColor, bounceColor, 0.5f); - - glClear(GL_COLOR_BUFFER_BIT); // Clear Screen Buffer (TODO: comment this out when whole thing start working) - */ - - if( WaitForNativeRender && memBuffer ) + // Set up an array of values to use as the sprite vertices. + static GLfloat vertices[] = { - if( SDL_SemWaitTimeout( WaitForNativeRender, 200 ) == 0 ) + 0, 0, + 1, 0, + 0, 1, + 1, 1, + }; + + // Set up an array of values for the texture coordinates. + static GLfloat texcoords[] = + { + 0, 0, + 1, 0, + 0, 1, + 1, 1, + }; + + static float clearColor = 0.0f; + static int clearColorDir = 1; + int textX, textY; + + if( WaitForNativeRender && memBuffer && openglInitialized != GL_State_Uninit2 ) + { + if( openglInitialized == GL_State_Init ) + { + openglInitialized = GL_State_Ready; + + // Texture sizes should be 2^n + textX = memX; + textY = memY; + + if( textX <= 256 ) + textX = 256; + else if( textX <= 512 ) + textX = 512; + else + textX = 1024; + + if( textY <= 256 ) + textY = 256; + else if( textY <= 512 ) + textY = 512; + else + textY = 1024; + + glViewport(0, 0, textX, textY); + + glClearColor(0,0,0,0); + // Set projection + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + #if defined(GL_VERSION_ES_CM_1_0) + #define glOrtho glOrthof + #endif + glOrtho( 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f ); + + // Now Initialize modelview matrix + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + + glDisable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + glDisable(GL_DITHER); + glDisable(GL_MULTISAMPLE); + + glEnable(GL_TEXTURE_2D); + + glGenTextures(1, &texture); + + glBindTexture(GL_TEXTURE_2D, texture); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + void * textBuffer = SDL_malloc( textX*textY*2 ); + SDL_memset( textBuffer, 0, textX*textY*2 ); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, textX, textY, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, textBuffer); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + glVertexPointer(2, GL_FLOAT, 0, vertices); + glTexCoordPointer(2, GL_FLOAT, 0, texcoords); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + glFinish(); //glFlush(); + + SDL_free( textBuffer ); + } + else if( openglInitialized == GL_State_Uninit ) + { + openglInitialized = GL_State_Uninit2; + + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); + + glDeleteTextures(1, &texture); + + return; + } + + if( SDL_SemWaitTimeout( WaitForNativeRender, 400 ) == 0 ) { //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Rendering frame"); } else { //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Frame skipped"); + SDL_Delay(100); } - // ----- Fail code starts here ----- - glDisable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); - glDisable(GL_DITHER); - glDisable(GL_MULTISAMPLE); - - glEnable(GL_TEXTURE_2D); - - if( glGetError() != GL_NO_ERROR ) - __android_log_print(ANDROID_LOG_INFO, "libSDL", "glGenTextures() error"); - - glGenTextures(1, texture); - if( glGetError() != GL_NO_ERROR ) - __android_log_print(ANDROID_LOG_INFO, "libSDL", "glGenTextures() error"); - - glBindTexture(GL_TEXTURE_2D, texture[0]); - if( glGetError() != GL_NO_ERROR ) - __android_log_print(ANDROID_LOG_INFO, "libSDL", "glBindTexture() error"); - - /* - glActiveTexture(texture[0]); - if( glGetError() != GL_NO_ERROR ) - __android_log_print(ANDROID_LOG_INFO, "libSDL", "glActiveTexture() error"); - - glClientActiveTexture(texture[0]); - if( glGetError() != GL_NO_ERROR ) - __android_log_print(ANDROID_LOG_INFO, "libSDL", "glClientActiveTexture() error"); - */ - - //glTexImage2D(GL_TEXTURE_2D, 0, 3, memX, memY, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, memBuffer); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, memBuffer); - - int errorNum = glGetError(); - if( errorNum != GL_NO_ERROR ) - { - sprintf(tmp, "glTexImage2D() error: %i", errorNum); - __android_log_print(ANDROID_LOG_INFO, "libSDL", tmp); - } - - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); - - if( glGetError() != GL_NO_ERROR ) - __android_log_print(ANDROID_LOG_INFO, "libSDL", "glTexParameteri() error"); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - - if( glGetError() != GL_NO_ERROR ) - __android_log_print(ANDROID_LOG_INFO, "libSDL", "glEnableClientState() error"); - - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspectivef( 90.0f, (float)memX / (float)memY, 0.1f, 100.0f); - - glMatrixMode( GL_MODELVIEW ); - glLoadIdentity(); - glTranslatef( 0.0f, 0.0f, -1.0f ); - - glVertexPointer(3, GL_FLOAT, 0, vertexData); - - if( glGetError() != GL_NO_ERROR ) - __android_log_print(ANDROID_LOG_INFO, "libSDL", "glVertexPointer() error"); - - glTexCoordPointer(2, GL_FLOAT, 0, textureData); - - if( glGetError() != GL_NO_ERROR ) - __android_log_print(ANDROID_LOG_INFO, "libSDL", "glTexCoordPointer() error"); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, memX, memY, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, memBuffer); + //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, memX, memY, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, memBuffer); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + glFinish(); //glFlush(); - if( glGetError() != GL_NO_ERROR ) - __android_log_print(ANDROID_LOG_INFO, "libSDL", "glDrawArrays() error"); - - //glDisableClientState(GL_TEXTURE_COORD_ARRAY); - //glDisableClientState(GL_VERTEX_ARRAY); - - glDeleteTextures(1, texture); - if( glGetError() != GL_NO_ERROR ) - __android_log_print(ANDROID_LOG_INFO, "libSDL", "glDeleteTextures() error"); - - // ----- Fail code ends here - it just doesn't output anything ----- - + SDL_SemPost(WaitForNativeRender1); + } + else + { + /* + // Flash the screen + if( clearColor >= 1.0f ) + clearColorDir = -1; + else if( clearColor <= 0.0f ) + clearColorDir = 1; + + clearColor += (float)clearColorDir * 0.01f; + glClearColor(clearColor,clearColor,clearColor,0); + glClear(GL_COLOR_BUFFER_BIT); + SDL_Delay(50); + */ } - } void ANDROID_InitOSKeymap(_THIS) @@ -540,12 +577,16 @@ void ANDROID_InitOSKeymap(_THIS) for (i=0; i +#ifdef USE_OPENGL + #if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) #include #include @@ -49,3 +51,5 @@ private: }; #endif + +#endif diff --git a/src/sdl/CVideoDriver.cpp b/src/sdl/CVideoDriver.cpp index a3e111284..c2d705310 100644 --- a/src/sdl/CVideoDriver.cpp +++ b/src/sdl/CVideoDriver.cpp @@ -314,7 +314,7 @@ bool CVideoDriver::applyMode(void) m_Resolution = *m_Resolution_pos; -#ifndef WIZ +#if ! defined(WIZ) && ! defined(ANDROID) // Support for doublebuffering Mode |= SDL_DOUBLEBUF; #endif diff --git a/start.sh b/start.sh old mode 100644 new mode 100755 index 4d45e11c7..b24c56325 --- a/start.sh +++ b/start.sh @@ -18,25 +18,15 @@ get_backtrace() { echo "HINT: Please send the above output to openlierox@az2000.de." } -cd share/gamedir +cd data ulimit -c unlimited # activate core-files rm core* 2>/dev/null # remove old core-files bin="/dev/null" -[ -x ../../$bin ] || bin="build/Xcode/build/Debug/Commander Genius.app/Contents/MacOS/Commander Genius" -[ -x ../../$bin ] || bin=build/Xcode/build/Release/Commander Genius.app/Contents/MacOS/Commander Genius -[ -x ../../$bin ] || bin=bin/commandergenius -../../$bin "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" +[ -x ../$bin ] || bin="build/Xcode/build/Debug/Commander Genius.app/Contents/MacOS/Commander Genius" +[ -x ../$bin ] || bin=build/Xcode/build/Release/Commander Genius.app/Contents/MacOS/Commander Genius +[ -x ../$bin ] || bin=bin/commandergenius +../$bin "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" -# game was exited, check for core-files (if crashed) -[ -e core* ] && get_backtrace ../../bin/commandergenius core* -mv core* ../.. 2>/dev/null +mv core* .. 2>/dev/null -if [ -e /proc/sys/kernel/core_pattern ] && [ "$(cat /proc/sys/kernel/core_pattern)" != "" ]; then - corefile="$(sh -c "echo $(cat /proc/sys/kernel/core_pattern | sed -e "s/%e/commandergenius/g" -e "s/%p/*/g" -e "s/%u/$(id -u)/g" -e "s/%t/*/g")")" - if [ -e "$corefile" ]; then - echo "found corefile $corefile" - get_backtrace ../../bin/commandergenius "$corefile" - mv "$corefile" ../.. - fi -fi