diff --git a/build3/premake4.lua b/build3/premake4.lua index c2742cd63..5fbdbd2b4 100644 --- a/build3/premake4.lua +++ b/build3/premake4.lua @@ -238,6 +238,9 @@ end targetdir( _OPTIONS["targetdir"] or "../bin" ) location("./" .. act .. postfix) + projectRootDir = os.getcwd() .. "/../" + print("Project root directory: " .. projectRootDir); + if not _OPTIONS["python_include_dir"] then _OPTIONS["python_include_dir"] = default_python_include_dir end @@ -246,21 +249,74 @@ end _OPTIONS["python_lib_dir"] = default_python_lib_dir end + newoption + { + trigger = "glfw_include_dir", + value = default_glfw_include_dir, + description = "GLFW 3.x include directory" + } + + newoption + { + trigger = "glfw_lib_dir", + value = default_glfw_lib_dir, + description = "(optional) GLFW 3.x library directory " + } + + newoption + { + trigger = "enable_glfw", + value = false, + description = "(optional) use GLFW 3.x library" + } + + if _OPTIONS["enable_glfw"] then + defines {"B3_USE_GLFW"} + + + + function initOpenGL() + includedirs { + projectRootDir .. "examples/ThirdPartyLibs/glad" + } + + includedirs { + _OPTIONS["glfw_include_dir"], + } + + libdirs { + _OPTIONS["glfw_lib_dir"] + } + links {"glfw3"} + files { projectRootDir .. "examples/ThirdPartyLibs/glad/glad.c" } + end + function findOpenGL3() + return true + end + function initGlew() + end + + else + dofile ("findOpenGLGlewGlut.lua") + if (not findOpenGL3()) then + defines {"NO_OPENGL3"} + end + end - projectRootDir = os.getcwd() .. "/../" - print("Project root directory: " .. projectRootDir); + dofile ("findOpenCL.lua") dofile ("findDirectX11.lua") - dofile ("findOpenGLGlewGlut.lua") - - if (not findOpenGL3()) then - defines {"NO_OPENGL3"} - end - + + + language "C++" + + + + if _OPTIONS["audio"] then include "../examples/TinyAudio" end diff --git a/examples/OpenGLWindow/GLInstancingRenderer.cpp b/examples/OpenGLWindow/GLInstancingRenderer.cpp index c00f41be4..b89309aab 100644 --- a/examples/OpenGLWindow/GLInstancingRenderer.cpp +++ b/examples/OpenGLWindow/GLInstancingRenderer.cpp @@ -28,7 +28,9 @@ float shadowMapWorldSize=10; #include "OpenGLInclude.h" #include "../CommonInterfaces/CommonWindowInterface.h" //#include "Bullet3Common/b3MinMax.h" +#ifdef B3_USE_GLFW +#else #ifndef __APPLE__ #ifndef glVertexAttribDivisor #ifndef NO_GLEW @@ -44,6 +46,7 @@ float shadowMapWorldSize=10; #endif //NO_GLEW #endif #endif //__APPLE__ +#endif//B3_USE_GLFW #include "GLInstancingRenderer.h" #include diff --git a/examples/OpenGLWindow/OpenGL2Include.h b/examples/OpenGLWindow/OpenGL2Include.h index 0d3f4701b..d9eb2302a 100644 --- a/examples/OpenGLWindow/OpenGL2Include.h +++ b/examples/OpenGLWindow/OpenGL2Include.h @@ -17,7 +17,10 @@ subject to the following restrictions: #ifndef __OPENGL_INCLUDE_H #define __OPENGL_INCLUDE_H - +#ifdef B3_USE_GLFW +#include "glad/glad.h" +#include +#else //think different #if defined(__APPLE__) && !defined (VMDMESA) #include @@ -45,7 +48,7 @@ subject to the following restrictions: //#include #endif //_WINDOWS #endif //APPLE - +#endif //B3_USE_GLFW //disable glGetError //#undef glGetError //#define glGetError MyGetError diff --git a/examples/OpenGLWindow/OpenGLInclude.h b/examples/OpenGLWindow/OpenGLInclude.h index c9c1503d6..061d96e3e 100644 --- a/examples/OpenGLWindow/OpenGLInclude.h +++ b/examples/OpenGLWindow/OpenGLInclude.h @@ -17,7 +17,10 @@ subject to the following restrictions: #ifndef __OPENGL_INCLUDE_H #define __OPENGL_INCLUDE_H - +#ifdef B3_USE_GLFW +#include +#include +#else //think different #if defined(__APPLE__) && !defined (VMDMESA) #include @@ -31,6 +34,7 @@ subject to the following restrictions: #endif #else + #ifdef GLEW_STATIC #include "CustomGL/glew.h" #else @@ -52,7 +56,7 @@ subject to the following restrictions: //#include #endif //_WINDOWS #endif //APPLE - +#endif //disable glGetError //#undef glGetError //#define glGetError MyGetError diff --git a/examples/OpenGLWindow/SimpleOpenGL2App.cpp b/examples/OpenGLWindow/SimpleOpenGL2App.cpp index 43b8058f2..e25f76b8d 100644 --- a/examples/OpenGLWindow/SimpleOpenGL2App.cpp +++ b/examples/OpenGLWindow/SimpleOpenGL2App.cpp @@ -13,6 +13,11 @@ #include "stdlib.h" #include "TwFonts.h" #include "SimpleOpenGL2Renderer.h" + +#ifdef B3_USE_GLFW +#include "GLFWOpenGLWindow.h" +#else + #ifdef __APPLE__ #include "MacOpenGLWindow.h" #else @@ -30,6 +35,8 @@ #endif //BT_USE_EGL #endif //_WIN32 #endif//__APPLE__ +#endif //#ifdef B3_USE_GLFW + #include #include "../CommonInterfaces/CommonRenderInterface.h" @@ -129,7 +136,7 @@ SimpleOpenGL2App::SimpleOpenGL2App(const char* title, int width, int height) glewExperimental = GL_TRUE; #endif //_WIN32 - +#ifndef B3_USE_GLFW if (glewInit() != GLEW_OK) { b3Error("glewInit failed"); @@ -140,7 +147,7 @@ SimpleOpenGL2App::SimpleOpenGL2App(const char* title, int width, int height) b3Error("GLEW_VERSION_2_1 needs to support 2_1"); exit(1); // or handle the error in a nicer way } - +#endif //B3_USE_GLFW #endif //__APPLE__ #endif //NO_GLEW @@ -580,4 +587,4 @@ int SimpleOpenGL2App::registerCubeShape(float halfExtentsX,float halfExtentsY, f int shapeId = m_renderer->registerShape(&verts[0].xyzw[0],numVertices,cube_indices,numIndices,B3_GL_TRIANGLES,textureIndex); return shapeId; -} \ No newline at end of file +} diff --git a/examples/OpenGLWindow/SimpleOpenGL3App.cpp b/examples/OpenGLWindow/SimpleOpenGL3App.cpp index c37e10db6..d5814b92b 100644 --- a/examples/OpenGLWindow/SimpleOpenGL3App.cpp +++ b/examples/OpenGLWindow/SimpleOpenGL3App.cpp @@ -2,6 +2,11 @@ #include "SimpleOpenGL3App.h" #include "ShapeData.h" + + +#ifdef B3_USE_GLFW +#include "GLFWOpenGLWindow.h" +#else #ifdef __APPLE__ #include "MacOpenGLWindow.h" #else @@ -19,6 +24,8 @@ #endif //BT_USE_EGL #endif //_WIN32 #endif//__APPLE__ +#endif //B3_USE_GLFW + #include #include "GLPrimitiveRenderer.h" @@ -321,12 +328,12 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height, boo glewExperimental = GL_TRUE; #endif //_WIN32 - +#ifndef B3_USE_GLFW if (glewInit() != GLEW_OK) exit(1); // or handle the error in a nicer way if (!GLEW_VERSION_2_1) // check that the machine supports the 2.1 API. exit(1); // or handle the error in a nicer way - +#endif //B3_USE_GLFW #endif //__APPLE__ #endif //NO_GLEW glGetError();//don't remove this call, it is needed for Ubuntu diff --git a/examples/OpenGLWindow/Win32OpenGLWindow.cpp b/examples/OpenGLWindow/Win32OpenGLWindow.cpp index 0e076b92c..43ae05105 100644 --- a/examples/OpenGLWindow/Win32OpenGLWindow.cpp +++ b/examples/OpenGLWindow/Win32OpenGLWindow.cpp @@ -1,3 +1,4 @@ +#ifndef B3_USE_GLFW #ifdef _WIN32 /* Copyright (c) 2012 Advanced Micro Devices, Inc. @@ -196,5 +197,5 @@ int Win32OpenGLWindow::getHeight() const #endif - +#endif //B3_USE_GLFW \ No newline at end of file diff --git a/examples/StandaloneMain/hellovr_opengl_main.cpp b/examples/StandaloneMain/hellovr_opengl_main.cpp index cad0eeb35..90831dc8b 100644 --- a/examples/StandaloneMain/hellovr_opengl_main.cpp +++ b/examples/StandaloneMain/hellovr_opengl_main.cpp @@ -1281,9 +1281,13 @@ bool CMainApplication::SetupTexturemaps() #ifdef WIN32 GLfloat fLargest; - +#ifdef B3_USE_GLFW + glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &fLargest); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, fLargest); +#else glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest); +#endif #endif glBindTexture( GL_TEXTURE_2D, 0 ); @@ -2295,9 +2299,14 @@ bool CGLRenderModel::BInit( const vr::RenderModel_t & vrModel, const vr::RenderM glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); #ifdef _WIN32 GLfloat fLargest; +#ifdef B3_USE_GLFW + glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY, &fLargest ); + glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, fLargest ); +#else glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest ); -#endif +#endif //B3_USE_GLFW +#endif//_WIN32 glBindTexture( GL_TEXTURE_2D, 0 ); m_unVertexCount = vrModel.unTriangleCount * 3; @@ -2388,6 +2397,7 @@ int main(int argc, char *argv[]) if (gVideoFileName) pMainApplication->getApp()->dumpFramesToVideo(gVideoFileName); +#ifndef B3_USE_GLFW #ifdef _WIN32 //request disable VSYNC typedef bool (APIENTRY *PFNWGLSWAPINTERVALFARPROC)(int); @@ -2397,7 +2407,7 @@ int main(int argc, char *argv[]) if (wglSwapIntervalEXT) wglSwapIntervalEXT(0); #endif - +#endif #ifdef __APPLE__ GLint sync = 0; CGLContextObj ctx = CGLGetCurrentContext(); diff --git a/examples/ThirdPartyLibs/Gwen/Renderers/OpenGL_DebugFont.cpp b/examples/ThirdPartyLibs/Gwen/Renderers/OpenGL_DebugFont.cpp index 83012951e..71f223b6e 100644 --- a/examples/ThirdPartyLibs/Gwen/Renderers/OpenGL_DebugFont.cpp +++ b/examples/ThirdPartyLibs/Gwen/Renderers/OpenGL_DebugFont.cpp @@ -5,6 +5,10 @@ #include "Gwen/Texture.h" #include +#ifdef B3_USE_GLFW +#include "glad/glad.h" +#include +#else #if defined(__APPLE__) && !defined (VMDMESA) #include @@ -22,6 +26,7 @@ #endif //NO_GLEW #endif //GLEW_STATIC #endif//(__APPLE__) +#endif #include "FontData.h" diff --git a/test/GwenOpenGLTest/OpenGLSample.cpp b/test/GwenOpenGLTest/OpenGLSample.cpp index af7781fdf..442af7574 100644 --- a/test/GwenOpenGLTest/OpenGLSample.cpp +++ b/test/GwenOpenGLTest/OpenGLSample.cpp @@ -9,6 +9,10 @@ extern unsigned char OpenSansData[]; #include "Gwen/Renderers/OpenGL_DebugFont.h" + +#ifdef B3_USE_GLFW +#include "OpenGLWindow/GLFWOpenGLWindow.h" +#else #ifdef __APPLE__ #include "OpenGLWindow/MacOpenGLWindow.h" #else @@ -21,7 +25,7 @@ extern unsigned char OpenSansData[]; #include "OpenGLWindow/X11OpenGLWindow.h" #endif //_WIN32 #endif//__APPLE__ - +#endif //B3_USE_GLFW #include "OpenGLWindow/opengl_fontstashcallbacks.h" #ifndef NO_OPENGL3 #include "OpenGLWindow/GwenOpenGL3CoreRenderer.h" @@ -345,7 +349,7 @@ int main() if (majorGlVersion>=3 && wci.m_openglVersion>=3) { float retinaScale = 1.f; - +#ifndef B3_USE_GLFW #ifndef __APPLE__ #ifndef _WIN32 //we need glewExperimental on Linux @@ -353,7 +357,7 @@ int main() #endif // _WIN32 glewInit(); #endif - +#endif //B3_USE_GLFW //we ned to call glGetError twice, because of some Ubuntu/Intel/OpenGL issue GLuint err = glGetError(); diff --git a/test/GwenOpenGLTest/premake4.lua b/test/GwenOpenGLTest/premake4.lua index a14f78e49..df71f70e6 100644 --- a/test/GwenOpenGLTest/premake4.lua +++ b/test/GwenOpenGLTest/premake4.lua @@ -44,6 +44,9 @@ "**.cpp", "**.h", } + files { + "../../examples/OpenGLWindow/GLFWOpenGLWindow.cpp", + } if os.is("Windows") then files { "../../examples/OpenGLWindow/Win32OpenGLWindow.cpp", @@ -62,7 +65,6 @@ end if os.is("MacOSX") then links{"Cocoa.framework"} -print("hello!") files{ "../../examples/OpenGLWindow/MacOpenGLWindow.cpp", "../../examples/OpenGLWindow/MacOpenGLWindow.h",