From f8758111dcd2aeef12947a12a9770ed83f4aed26 Mon Sep 17 00:00:00 2001 From: kts Date: Thu, 12 Feb 2015 07:40:40 -0800 Subject: [PATCH] Updated android, ios, and osx projects. Hopefully nothing is broken. --- build/android/jni/Application.mk | 4 +++- build/android/jni/src/Android.mk | 21 ++++++++++++++++++- .../Roll them Bones.xcodeproj/project.pbxproj | 14 +++++++++++++ .../Roll them Bones.xcodeproj/project.pbxproj | 12 +++++++++++ src/Log.hpp | 2 +- src/Mesh.cpp | 8 +------ src/RenderView.cpp | 10 +++++++-- src/common.hpp | 19 ++++++++++++++++- src/main.cpp | 3 ++- 9 files changed, 79 insertions(+), 14 deletions(-) diff --git a/build/android/jni/Application.mk b/build/android/jni/Application.mk index e5b5079..dd94321 100755 --- a/build/android/jni/Application.mk +++ b/build/android/jni/Application.mk @@ -1,6 +1,8 @@ # Uncomment this if you're using STL in your project # See CPLUSPLUS-SUPPORT.html in the NDK documentation for more information -# APP_STL := stlport_static +APP_STL := stlport_static APP_ABI := armeabi armeabi-v7a x86 + +APP_CPPFLAGS += -fexceptions diff --git a/build/android/jni/src/Android.mk b/build/android/jni/src/Android.mk index 2e31964..a447523 100755 --- a/build/android/jni/src/Android.mk +++ b/build/android/jni/src/Android.mk @@ -10,7 +10,26 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include # Add your application source files here... LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \ - ../../../../src/*.cpp + ../../../../src/Log.cpp \ + ../../../../src/Log.hpp \ + ../../../../src/Mat4.cpp \ + ../../../../src/Mat4.hpp \ + ../../../../src/Mesh.cpp \ + ../../../../src/Mesh.hpp \ + ../../../../src/RenderCamera.cpp \ + ../../../../src/RenderCamera.hpp \ + ../../../../src/RenderObject.cpp \ + ../../../../src/RenderObject.hpp \ + ../../../../src/RenderScene.cpp \ + ../../../../src/RenderScene.hpp \ + ../../../../src/RenderSet.cpp \ + ../../../../src/RenderSet.hpp \ + ../../../../src/RenderView.cpp \ + ../../../../src/RenderView.hpp \ + ../../../../src/Vec.cpp \ + ../../../../src/Vec.hpp \ + ../../../../src/common.hpp \ + ../../../../src/main.cpp LOCAL_SHARED_LIBRARIES := SDL2 diff --git a/build/ios/Roll them Bones.xcodeproj/project.pbxproj b/build/ios/Roll them Bones.xcodeproj/project.pbxproj index 327fdd9..6d9104e 100755 --- a/build/ios/Roll them Bones.xcodeproj/project.pbxproj +++ b/build/ios/Roll them Bones.xcodeproj/project.pbxproj @@ -17,6 +17,8 @@ 20A7A91E1A89F91300EDC1A0 /* RenderScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20A7A9171A89F91300EDC1A0 /* RenderScene.cpp */; }; 20A7A91F1A89F91300EDC1A0 /* RenderSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20A7A9191A89F91300EDC1A0 /* RenderSet.cpp */; }; 20A7A9201A89F91300EDC1A0 /* RenderView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20A7A91B1A89F91300EDC1A0 /* RenderView.cpp */; }; + 20E3F33B1A8CEC110071FD41 /* Log.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20E3F3371A8CEC110071FD41 /* Log.cpp */; }; + 20E3F33C1A8CEC110071FD41 /* Mesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20E3F3391A8CEC110071FD41 /* Mesh.cpp */; }; 20FD2D3B1A67470A00B32F7B /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20FD2D3A1A67470A00B32F7B /* main.cpp */; }; 28FD15000DC6FC520079059D /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 28FD14FF0DC6FC520079059D /* OpenGLES.framework */; }; 28FD15080DC6FC5B0079059D /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 28FD15070DC6FC5B0079059D /* QuartzCore.framework */; }; @@ -104,6 +106,11 @@ 20A7A91A1A89F91300EDC1A0 /* RenderSet.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = RenderSet.hpp; path = ../../src/RenderSet.hpp; sourceTree = SOURCE_ROOT; }; 20A7A91B1A89F91300EDC1A0 /* RenderView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RenderView.cpp; path = ../../src/RenderView.cpp; sourceTree = SOURCE_ROOT; }; 20A7A91C1A89F91300EDC1A0 /* RenderView.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = RenderView.hpp; path = ../../src/RenderView.hpp; sourceTree = SOURCE_ROOT; }; + 20E3F3371A8CEC110071FD41 /* Log.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Log.cpp; path = ../../src/Log.cpp; sourceTree = SOURCE_ROOT; }; + 20E3F3381A8CEC110071FD41 /* Log.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Log.hpp; path = ../../src/Log.hpp; sourceTree = SOURCE_ROOT; }; + 20E3F3391A8CEC110071FD41 /* Mesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Mesh.cpp; path = ../../src/Mesh.cpp; sourceTree = SOURCE_ROOT; }; + 20E3F33A1A8CEC110071FD41 /* Mesh.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Mesh.hpp; path = ../../src/Mesh.hpp; sourceTree = SOURCE_ROOT; }; + 20E3F36F1A8CED0D0071FD41 /* SDL_opengles2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_opengles2.h; path = "../../../android/SDL2-2.0.3/include/SDL_opengles2.h"; sourceTree = SOURCE_ROOT; }; 20FD2D3A1A67470A00B32F7B /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = ../../src/main.cpp; sourceTree = SOURCE_ROOT; }; 28FD14FF0DC6FC520079059D /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; }; 28FD15070DC6FC5B0079059D /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; @@ -146,6 +153,7 @@ 0097E29912F70C4D00724AC5 /* include */ = { isa = PBXGroup; children = ( + 20E3F36F1A8CED0D0071FD41 /* SDL_opengles2.h */, 0097E29A12F70C4D00724AC5 /* begin_code.h */, 0097E29B12F70C4D00724AC5 /* close_code.h */, 0097E29C12F70C4D00724AC5 /* doxyfile */, @@ -226,6 +234,10 @@ 20A7A9131A89F8F600EDC1A0 /* Classes */ = { isa = PBXGroup; children = ( + 20E3F3371A8CEC110071FD41 /* Log.cpp */, + 20E3F3381A8CEC110071FD41 /* Log.hpp */, + 20E3F3391A8CEC110071FD41 /* Mesh.cpp */, + 20E3F33A1A8CEC110071FD41 /* Mesh.hpp */, 2056AE4F1A8A423E00833760 /* Mat4.cpp */, 2056AE501A8A423E00833760 /* Mat4.hpp */, 2056AE511A8A423E00833760 /* RenderObject.cpp */, @@ -367,6 +379,8 @@ 2056AE551A8A423E00833760 /* Mat4.cpp in Sources */, 2056AE561A8A423E00833760 /* RenderObject.cpp in Sources */, 2056AE571A8A423E00833760 /* Vec.cpp in Sources */, + 20E3F33B1A8CEC110071FD41 /* Log.cpp in Sources */, + 20E3F33C1A8CEC110071FD41 /* Mesh.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/build/osx/Roll them Bones.xcodeproj/project.pbxproj b/build/osx/Roll them Bones.xcodeproj/project.pbxproj index 4489dcd..2cdfba4 100644 --- a/build/osx/Roll them Bones.xcodeproj/project.pbxproj +++ b/build/osx/Roll them Bones.xcodeproj/project.pbxproj @@ -18,6 +18,8 @@ 20A7A8D61A89E11200EDC1A0 /* RenderSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20A7A8D31A89E11200EDC1A0 /* RenderSet.cpp */; }; 20A8CE541A899B72004D2504 /* RenderCamera.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20A8CE501A899B72004D2504 /* RenderCamera.cpp */; }; 20A8CE551A899B72004D2504 /* RenderView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20A8CE521A899B72004D2504 /* RenderView.cpp */; }; + 20E3F2941A8CE8470071FD41 /* Log.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20E3F2901A8CE8470071FD41 /* Log.cpp */; }; + 20E3F2951A8CE8470071FD41 /* Mesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20E3F2921A8CE8470071FD41 /* Mesh.cpp */; }; 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; /* End PBXBuildFile section */ @@ -42,6 +44,10 @@ 20A8CE511A899B72004D2504 /* RenderCamera.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = RenderCamera.hpp; path = ../../src/RenderCamera.hpp; sourceTree = SOURCE_ROOT; }; 20A8CE521A899B72004D2504 /* RenderView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RenderView.cpp; path = ../../src/RenderView.cpp; sourceTree = SOURCE_ROOT; }; 20A8CE531A899B72004D2504 /* RenderView.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = RenderView.hpp; path = ../../src/RenderView.hpp; sourceTree = SOURCE_ROOT; }; + 20E3F2901A8CE8470071FD41 /* Log.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Log.cpp; path = ../../src/Log.cpp; sourceTree = SOURCE_ROOT; }; + 20E3F2911A8CE8470071FD41 /* Log.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Log.hpp; path = ../../src/Log.hpp; sourceTree = SOURCE_ROOT; }; + 20E3F2921A8CE8470071FD41 /* Mesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Mesh.cpp; path = ../../src/Mesh.cpp; sourceTree = SOURCE_ROOT; }; + 20E3F2931A8CE8470071FD41 /* Mesh.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Mesh.hpp; path = ../../src/Mesh.hpp; sourceTree = SOURCE_ROOT; }; 8D1107320486CEB800E47090 /* Roll them Bones.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Roll them Bones.app"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -63,6 +69,10 @@ 080E96DDFE201D6D7F000001 /* Classes */ = { isa = PBXGroup; children = ( + 20E3F2901A8CE8470071FD41 /* Log.cpp */, + 20E3F2911A8CE8470071FD41 /* Log.hpp */, + 20E3F2921A8CE8470071FD41 /* Mesh.cpp */, + 20E3F2931A8CE8470071FD41 /* Mesh.hpp */, 2056AE361A8A421500833760 /* Mat4.cpp */, 2056AE371A8A421500833760 /* Mat4.hpp */, 2056AE381A8A421500833760 /* RenderObject.cpp */, @@ -223,6 +233,8 @@ 2056AE3C1A8A421500833760 /* Mat4.cpp in Sources */, 2056AE3D1A8A421500833760 /* RenderObject.cpp in Sources */, 2056AE3E1A8A421500833760 /* Vec.cpp in Sources */, + 20E3F2941A8CE8470071FD41 /* Log.cpp in Sources */, + 20E3F2951A8CE8470071FD41 /* Mesh.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/Log.hpp b/src/Log.hpp index 49a81a4..dccb295 100644 --- a/src/Log.hpp +++ b/src/Log.hpp @@ -6,7 +6,7 @@ This header file describes the Log class #ifndef LOG_HPP #define LOG_HPP -#include +#include "SDL.h" #include #include #include diff --git a/src/Mesh.cpp b/src/Mesh.cpp index b1ee991..5517b85 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -215,18 +215,12 @@ int Mesh::buildMesh() { glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, vertices.size()*sizeof(Vec3), &vertices[0], mode); - // generate our vertex attribute object - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - glEnableVertexAttribArray(0); - glBindBuffer(GL_ARRAY_BUFFER, vbo); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); flags |= MESH_BUILT; return 0; } int Mesh::destroyMesh() { glDeleteBuffers(1, &vbo); - glDeleteVertexArrays(1, &vao); + //glDeleteVertexArrays(1, &vao); flags &= ~MESH_BUILT; return 0; } \ No newline at end of file diff --git a/src/RenderView.cpp b/src/RenderView.cpp index 2d6296a..3e93034 100644 --- a/src/RenderView.cpp +++ b/src/RenderView.cpp @@ -25,7 +25,11 @@ int RenderView::createView(int width, int height) { // ================ create depth buffer glGenRenderbuffers(1, &fbo_depth); glBindRenderbuffer(GL_RENDERBUFFER, fbo_depth); +#if defined(HAVE_OPENGLES) + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height); +#else glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height); +#endif glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo_depth); // unbind the render buffer glBindRenderbuffer(GL_RENDERBUFFER, 0); @@ -47,8 +51,10 @@ int RenderView::createView(int width, int height) { glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo_tex, 0); // attach depth render buffer glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, fbo_depth); - if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { - LOG(LOG_ERROR) << FUNC_NAME << "Failed to create Framebuffer!"; + GLenum status; + if ((status = glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE) { + GLenum error = glGetError(); + LOG(LOG_ERROR) << FUNC_NAME << " " << status << " " << error << " " << "Failed to create Framebuffer!"; glBindFramebuffer(GL_FRAMEBUFFER, 0); return 1; } diff --git a/src/common.hpp b/src/common.hpp index 9322b6d..52b1621 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -12,9 +12,26 @@ This header provides common includes to SDL2 and OpenGL/OpenGLES #endif #if defined(HAVE_OPENGLES) - #include "SDL_opengles.h" + #include "SDL_opengles2.h" + #if defined(__IPHONEOS__) || defined(__ANDROID__) + #define glGenVertexArrays glGenVertexArraysOES + #define glBindVertexArray glBindVertexArrayOES + #define glDeleteVertexArrays glDeleteVertexArraysOES + #endif #elif defined(USE_GLEW) #include #else + #define GL_GLEXT_PROTOTYPES 1 #include "SDL_opengl.h" +#if defined(TARGET_OS_MAC) + #ifndef glGenVertexArrays + #define glGenVertexArrays glGenVertexArraysAPPLE + #endif + #ifndef glBindVertexArray + #define glBindVertexArray glBindVertexArrayAPPLE + #endif + #ifndef glDeleteVertexArrays + #define glDeleteVertexArrays glDeleteVertexArraysAPPLE + #endif +#endif #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 11313b3..d58bf6a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,7 @@ int main(int argc, char *argv[]) { LOG(LOG_ERROR) << "SDL_CreateWindow: " << SDL_GetError(); return 1; } + SDL_GetWindowSize(v_window, &v_width, &v_height); // get our OpenGL context v_context = SDL_GL_CreateContext(v_window); if (v_context == NULL) { @@ -64,7 +65,7 @@ int main(int argc, char *argv[]) { } scene->renderTo(&v_view); - glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindFramebuffer(GL_FRAMEBUFFER, v_fbo); glViewport(0, 0, v_width, v_height); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);