From cec740f429a8105dbf10ebbada2988eef372acd4 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Sun, 9 Mar 2014 17:54:17 +0000 Subject: [PATCH 1/8] Remove search for Boost We don't use Boost anywhere any more so don't try to search for it. --- CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cadcdb15..1b025392 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,12 +55,6 @@ else() set_package_properties(Qt4 PROPERTIES TYPE OPTIONAL PURPOSE "Building the tests") endif() -if(MSVC AND (MSVC_VERSION LESS 1600)) - # Require boost for older (pre-vc2010) Visual Studio compilers - # See library/include/polyvoxcore/impl/TypeDef.h - find_package(Boost REQUIRED) - include_directories(${Boost_INCLUDE_DIRS}) -endif() IF(CMAKE_COMPILER_IS_GNUCXX) #Maybe "OR MINGW" ADD_DEFINITIONS(-std=c++0x) #Enable C++0x mode From 00d1b8e10c6bd43486e76cafbcf245593d5a3a94 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Sun, 9 Mar 2014 17:55:14 +0000 Subject: [PATCH 2/8] Update required CMake version to 2.8.6 --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b025392..6691be4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ # 3. This notice may not be removed or altered from any source # distribution. -CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.6) PROJECT(PolyVox) @@ -83,7 +83,6 @@ INCLUDE(Packaging.cmake) OPTION(ENABLE_TESTS "Should the tests be built" ON) IF(ENABLE_TESTS AND QT_QTTEST_FOUND) INCLUDE(CTest) - MARK_AS_ADVANCED(FORCE DART_TESTING_TIMEOUT) #This is only needed to hide the variable in the GUI (CMake bug) until 2.8.5 MARK_AS_ADVANCED(FORCE BUILD_TESTING) ADD_SUBDIRECTORY(tests) SET(BUILD_TESTS ON) From 868fbb84a0aad702a964580a5d44304f9abbfcf4 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Sun, 9 Mar 2014 18:02:24 +0000 Subject: [PATCH 3/8] Update to use Qt5 The examples and tests now use Qt5. This allows some nice tidying of the CMake files, some of which will come in future. Closes issue #41 --- CMakeLists.txt | 22 +++++++--------- examples/Basic/CMakeLists.txt | 4 +-- examples/OpenGL/CMakeLists.txt | 2 +- examples/Paging/CMakeLists.txt | 4 +-- examples/SmoothLOD/CMakeLists.txt | 4 +-- tests/CMakeLists.txt | 43 ++++++++++++++----------------- 6 files changed, 33 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6691be4a..ef7af1f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,18 +43,14 @@ IF(WIN32) ENDIF() # Qt is required for building the tests, the example and optionally for bundling the documentation -FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtOpenGL QtTest) -INCLUDE(${QT_USE_FILE}) -if(CMAKE_VERSION VERSION_LESS "2.8.6") - set_package_info(Doxygen "API documentation generator" http://www.doxygen.org "Building the API documentation") - set_package_info(Qt4 "C++ framework" http://qt-project.org "Building the examples and tests") -else() - set_package_properties(Doxygen PROPERTIES URL http://www.doxygen.org DESCRIPTION "API documentation generator" TYPE OPTIONAL PURPOSE "Building the API documentation") - set_package_properties(Qt4 PROPERTIES DESCRIPTION "C++ framework" URL http://qt-project.org) - set_package_properties(Qt4 PROPERTIES TYPE RECOMMENDED PURPOSE "Building the examples") - set_package_properties(Qt4 PROPERTIES TYPE OPTIONAL PURPOSE "Building the tests") -endif() +find_package(Qt5Test 5.2 REQUIRED) +find_package(Qt5OpenGL 5.2 REQUIRED) +set_package_properties(Doxygen PROPERTIES URL http://www.doxygen.org DESCRIPTION "API documentation generator" TYPE OPTIONAL PURPOSE "Building the API documentation") +set_package_properties(Qt5Test PROPERTIES DESCRIPTION "C++ framework" URL http://qt-project.org) +set_package_properties(Qt5Test PROPERTIES TYPE OPTIONAL PURPOSE "Building the tests") +set_package_properties(Qt5OpenGL PROPERTIES DESCRIPTION "C++ framework" URL http://qt-project.org) +set_package_properties(Qt5OpenGL PROPERTIES TYPE RECOMMENDED PURPOSE "Building the examples") IF(CMAKE_COMPILER_IS_GNUCXX) #Maybe "OR MINGW" ADD_DEFINITIONS(-std=c++0x) #Enable C++0x mode @@ -66,7 +62,7 @@ endif() ADD_SUBDIRECTORY(library) OPTION(ENABLE_EXAMPLES "Should the examples be built" ON) -IF(ENABLE_EXAMPLES AND QT_QTOPENGL_FOUND) +IF(ENABLE_EXAMPLES AND Qt5OpenGL_FOUND) ADD_SUBDIRECTORY(examples/common) ADD_SUBDIRECTORY(examples/Basic) ADD_SUBDIRECTORY(examples/Paging) @@ -81,7 +77,7 @@ ENDIF() INCLUDE(Packaging.cmake) OPTION(ENABLE_TESTS "Should the tests be built" ON) -IF(ENABLE_TESTS AND QT_QTTEST_FOUND) +IF(ENABLE_TESTS AND Qt5Test_FOUND) INCLUDE(CTest) MARK_AS_ADVANCED(FORCE BUILD_TESTING) ADD_SUBDIRECTORY(tests) diff --git a/examples/Basic/CMakeLists.txt b/examples/Basic/CMakeLists.txt index 02e203d2..e0328805 100644 --- a/examples/Basic/CMakeLists.txt +++ b/examples/Basic/CMakeLists.txt @@ -19,8 +19,6 @@ # 3. This notice may not be removed or altered from any source # distribution. -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) - PROJECT(BasicExample) #Projects source files @@ -52,7 +50,7 @@ ADD_EXECUTABLE(BasicExample ${SRC_FILES}) IF(MSVC) SET_TARGET_PROPERTIES(BasicExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") ENDIF(MSVC) -TARGET_LINK_LIBRARIES(BasicExample glew ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) +TARGET_LINK_LIBRARIES(BasicExample glew Qt5::OpenGL ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) SET_PROPERTY(TARGET BasicExample PROPERTY FOLDER "Examples") #Install - Only install the example in Windows diff --git a/examples/OpenGL/CMakeLists.txt b/examples/OpenGL/CMakeLists.txt index 5cd1ed55..32709e81 100644 --- a/examples/OpenGL/CMakeLists.txt +++ b/examples/OpenGL/CMakeLists.txt @@ -60,7 +60,7 @@ ADD_EXECUTABLE(OpenGLExample ${SRC_FILES}) IF(MSVC) SET_TARGET_PROPERTIES(OpenGLExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") ENDIF(MSVC) -TARGET_LINK_LIBRARIES(OpenGLExample glew ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) +TARGET_LINK_LIBRARIES(OpenGLExample glew Qt5::OpenGL ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) SET_PROPERTY(TARGET OpenGLExample PROPERTY FOLDER "Examples") #Install - Only install the example in Windows diff --git a/examples/Paging/CMakeLists.txt b/examples/Paging/CMakeLists.txt index e8020b2d..97cec53a 100644 --- a/examples/Paging/CMakeLists.txt +++ b/examples/Paging/CMakeLists.txt @@ -19,8 +19,6 @@ # 3. This notice may not be removed or altered from any source # distribution. -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) - PROJECT(PagingExample) #Projects source files @@ -54,7 +52,7 @@ ADD_EXECUTABLE(PagingExample ${SRC_FILES}) IF(MSVC) SET_TARGET_PROPERTIES(PagingExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") ENDIF(MSVC) -TARGET_LINK_LIBRARIES(PagingExample glew ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) +TARGET_LINK_LIBRARIES(PagingExample glew Qt5::OpenGL ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) SET_PROPERTY(TARGET PagingExample PROPERTY FOLDER "Examples") #Install - Only install the example in Windows diff --git a/examples/SmoothLOD/CMakeLists.txt b/examples/SmoothLOD/CMakeLists.txt index 570cda55..9c5649fc 100644 --- a/examples/SmoothLOD/CMakeLists.txt +++ b/examples/SmoothLOD/CMakeLists.txt @@ -19,8 +19,6 @@ # 3. This notice may not be removed or altered from any source # distribution. -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) - PROJECT(SmoothLODExample) #Projects source files @@ -52,7 +50,7 @@ ADD_EXECUTABLE(SmoothLODExample ${SRC_FILES}) IF(MSVC) SET_TARGET_PROPERTIES(SmoothLODExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") #All warnings ENDIF(MSVC) -TARGET_LINK_LIBRARIES(SmoothLODExample glew ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) +TARGET_LINK_LIBRARIES(SmoothLODExample glew Qt5::OpenGL ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) SET_PROPERTY(TARGET SmoothLODExample PROPERTY FOLDER "Examples") #Install - Only install the example in Windows diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fbffe9d9..6b06437b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,12 +24,14 @@ # # Also sets LATEST_TEST to point to the output executable of the test for easy # ADD_TEST()ing -MACRO(CREATE_TEST headerfile sourcefile executablename) + +set(CMAKE_AUTOMOC TRUE) + +MACRO(CREATE_TEST sourcefile executablename) UNSET(test_moc_SRCS) #clear out the MOCs from previous tests - QT4_WRAP_CPP(test_moc_SRCS ${headerfile}) LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR} ${PolyVoxUtil_BINARY_DIR}) ADD_EXECUTABLE(${executablename} ${sourcefile} ${test_moc_SRCS}) - TARGET_LINK_LIBRARIES(${executablename} PolyVoxCore PolyVoxUtil ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY}) + TARGET_LINK_LIBRARIES(${executablename} PolyVoxCore PolyVoxUtil Qt5::Test) #HACK. This is needed since everything is built in the base dir in Windows. As of 2.8 we should change this. IF(WIN32) SET(LATEST_TEST ${EXECUTABLE_OUTPUT_PATH}/${executablename}) @@ -46,22 +48,17 @@ MACRO(CREATE_TEST headerfile sourcefile executablename) ENDMACRO(CREATE_TEST) INCLUDE_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/include ${PolyVox_SOURCE_DIR}/PolyVoxCore/include ${CMAKE_CURRENT_BINARY_DIR}) -REMOVE_DEFINITIONS(-DQT_GUI_LIB) #Make sure the tests don't link to the QtGui # Test Template. Copy and paste this template for consistant naming. # # ClassName tests -# CREATE_TEST(TestClassName.h TestClassName.cpp TestClassName) +# CREATE_TEST(TestClassName.cpp TestClassName) # ADD_TEST(ClassNameFeature1Test ${LATEST_TEST} testFeature1) # ADD_TEST(ClassNameFeature2Test ${LATEST_TEST} testFeature2) # Python tests IF(BUILD_BINDINGS) FIND_PACKAGE(PythonInterp 3) - IF(CMAKE_VERSION VERSION_LESS "2.8.6") - set_package_info(PythonInterp "Python Interpereter" http://www.python.org "Running the Python tests") - ELSE() - set_package_properties(PythonInterp PROPERTIES URL http://www.python.org DESCRIPTION "Python Interpereter" TYPE OPTIONAL PURPOSE "Running the Python tests") - ENDIF() + set_package_properties(PythonInterp PROPERTIES URL http://www.python.org DESCRIPTION "Python Interpereter" TYPE OPTIONAL PURPOSE "Running the Python tests") IF(PYTHONINTERP_FOUND) ADD_TEST(PythonSurfaceExtractorTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/TestSurfaceExtractor.py) ADD_TEST(PythonRaycastTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/TestRaycast.py) @@ -69,38 +66,38 @@ IF(BUILD_BINDINGS) ENDIF() # AmbientOcclusionGenerator tests -CREATE_TEST(TestAmbientOcclusionGenerator.h TestAmbientOcclusionGenerator.cpp TestAmbientOcclusionGenerator) +CREATE_TEST(TestAmbientOcclusionGenerator.cpp TestAmbientOcclusionGenerator) # Array tests -CREATE_TEST(TestArray.h TestArray.cpp TestArray) +CREATE_TEST(TestArray.cpp TestArray) # AStarPathfinder tests -CREATE_TEST(TestAStarPathfinder.h TestAStarPathfinder.cpp TestAStarPathfinder) +CREATE_TEST(TestAStarPathfinder.cpp TestAStarPathfinder) -CREATE_TEST(TestCubicSurfaceExtractor.h TestCubicSurfaceExtractor.cpp TestCubicSurfaceExtractor) +CREATE_TEST(TestCubicSurfaceExtractor.cpp TestCubicSurfaceExtractor) # Low pass filter tests -CREATE_TEST(TestLowPassFilter.h TestLowPassFilter.cpp TestLowPassFilter) +CREATE_TEST(TestLowPassFilter.cpp TestLowPassFilter) # Material tests -CREATE_TEST(testmaterial.h testmaterial.cpp testmaterial) +CREATE_TEST(testmaterial.cpp testmaterial) # Raycast tests -CREATE_TEST(TestRaycast.h TestRaycast.cpp TestRaycast) +CREATE_TEST(TestRaycast.cpp TestRaycast) # Picking tests -CREATE_TEST(TestPicking.h TestPicking.cpp TestPicking) +CREATE_TEST(TestPicking.cpp TestPicking) # Region tests -CREATE_TEST(TestRegion.h TestRegion.cpp TestRegion) +CREATE_TEST(TestRegion.cpp TestRegion) -CREATE_TEST(TestSurfaceExtractor.h TestSurfaceExtractor.cpp TestSurfaceExtractor) +CREATE_TEST(TestSurfaceExtractor.cpp TestSurfaceExtractor) #Vector tests -CREATE_TEST(testvector.h testvector.cpp testvector) +CREATE_TEST(testvector.cpp testvector) # Volume tests -CREATE_TEST(testvolume.h testvolume.cpp testvolume) +CREATE_TEST(testvolume.cpp testvolume) # Volume subclass tests -CREATE_TEST(TestVolumeSubclass.h TestVolumeSubclass.cpp TestVolumeSubclass) +CREATE_TEST(TestVolumeSubclass.cpp TestVolumeSubclass) From ac16dfd325bf48f80161422b32e9470ea0346f19 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Wed, 19 Mar 2014 21:26:04 +0000 Subject: [PATCH 4/8] Update the BasicExample to use OpenGL 3 The example now uses OpenGL 3 features like Vertex Array Objects and uses no immediate mode stuff. Qt5 is used for some features like matrices and shaders. There is now no dependency on GLEW either. --- examples/Basic/CMakeLists.txt | 8 +- examples/Basic/OpenGLWidget.cpp | 231 ++++++++++++++++++++------------ examples/Basic/OpenGLWidget.h | 15 ++- examples/Basic/main.cpp | 6 +- 4 files changed, 158 insertions(+), 102 deletions(-) diff --git a/examples/Basic/CMakeLists.txt b/examples/Basic/CMakeLists.txt index e0328805..66515549 100644 --- a/examples/Basic/CMakeLists.txt +++ b/examples/Basic/CMakeLists.txt @@ -32,17 +32,13 @@ SET(INC_FILES OpenGLWidget.h ) -add_definitions(-DGLEW_STATIC) - #"Sources" and "Headers" are the group names in Visual Studio. #They may have other uses too... SOURCE_GROUP("Sources" FILES ${SRC_FILES}) SOURCE_GROUP("Headers" FILES ${INC_FILES}) -FIND_PACKAGE(OpenGL REQUIRED) - #Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) -INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include) LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}) #Build @@ -50,7 +46,7 @@ ADD_EXECUTABLE(BasicExample ${SRC_FILES}) IF(MSVC) SET_TARGET_PROPERTIES(BasicExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") ENDIF(MSVC) -TARGET_LINK_LIBRARIES(BasicExample glew Qt5::OpenGL ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) +TARGET_LINK_LIBRARIES(BasicExample Qt5::OpenGL PolyVoxCore) SET_PROPERTY(TARGET BasicExample PROPERTY FOLDER "Examples") #Install - Only install the example in Windows diff --git a/examples/Basic/OpenGLWidget.cpp b/examples/Basic/OpenGLWidget.cpp index f33a8c7c..37f972af 100644 --- a/examples/Basic/OpenGLWidget.cpp +++ b/examples/Basic/OpenGLWidget.cpp @@ -1,6 +1,8 @@ #include "OpenGLWidget.h" #include +#include +#include using namespace PolyVox; using namespace std; @@ -9,126 +11,179 @@ OpenGLWidget::OpenGLWidget(QWidget *parent) :QGLWidget(parent) ,m_xRotation(0) ,m_yRotation(0) + ,gl(nullptr) { } -void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh& surfaceMesh) +void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh& surfaceMesh) { //Convienient access to the vertices and indices - const vector& vecIndices = surfaceMesh.getIndices(); - const vector& vecVertices = surfaceMesh.getVertices(); - - //Build an OpenGL index buffer - glGenBuffers(1, &indexBuffer); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); - const GLvoid* pIndices = static_cast(&(vecIndices[0])); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, vecIndices.size() * sizeof(uint32_t), pIndices, GL_STATIC_DRAW); - - //Build an OpenGL vertex buffer - glGenBuffers(1, &vertexBuffer); - glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); - const GLvoid* pVertices = static_cast(&(vecVertices[0])); - glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterialNormal), pVertices, GL_STATIC_DRAW); - - m_uBeginIndex = 0; - m_uEndIndex = vecIndices.size(); + const auto& vecIndices = surfaceMesh.getIndices(); + const auto& vecVertices = surfaceMesh.getVertices(); + + //Create the VAO for the mesh + gl->glGenVertexArrays(1, &vertexArrayObject); + gl->glBindVertexArray(vertexArrayObject); + + //The GL_ARRAY_BUFFER will contain the list of vertex positions + gl->glGenBuffers(1, &vertexBuffer); + gl->glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); + gl->glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterial), vecVertices.data(), GL_STATIC_DRAW); + + //and GL_ELEMENT_ARRAY_BUFFER will contain the indices + gl->glGenBuffers(1, &indexBuffer); + gl->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); + gl->glBufferData(GL_ELEMENT_ARRAY_BUFFER, vecIndices.size() * sizeof(uint32_t), vecIndices.data(), GL_STATIC_DRAW); + + //We need to tell OpenGL how to understand the format of the vertex data + gl->glEnableVertexAttribArray(0); //We're talking about shader attribute '0' + gl->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(PositionMaterial), 0); //take the first 3 floats from every sizeof(decltype(vecVertices)::value_type) + + gl->glBindVertexArray(0); + + noOfIndices = vecIndices.size(); //Save this for the call to glDrawElements later } void OpenGLWidget::initializeGL() { - //We need GLEW to access recent OpenGL functionality - std::cout << "Initialising GLEW..."; - GLenum result = glewInit(); - if (result == GLEW_OK) + //'gl' will give us access to all the OpenGL functions + gl = context()->contextHandle()->versionFunctions(); + if(!gl) { - std::cout << "success" << std::endl; + std::cerr << "Could not obtain required OpenGL context version" << std::endl; + exit(EXIT_FAILURE); } - else + if(!gl->initializeOpenGLFunctions()) { - /* Problem: glewInit failed, something is seriously wrong. */ - std::cout << "failed" << std::endl; - std::cout << "Initialising GLEW failed with the following error: " << glewGetErrorString(result) << std::endl; + std::cerr << "Could not initialise OpenGL functions" << std::endl; exit(EXIT_FAILURE); } //Print out some information about the OpenGL implementation. std::cout << "OpenGL Implementation Details:" << std::endl; - if(glGetString(GL_VENDOR)) - std::cout << "\tGL_VENDOR: " << glGetString(GL_VENDOR) << std::endl; - if(glGetString(GL_RENDERER)) - std::cout << "\tGL_RENDERER: " << glGetString(GL_RENDERER) << std::endl; - if(glGetString(GL_VERSION)) - std::cout << "\tGL_VERSION: " << glGetString(GL_VERSION) << std::endl; - if(glGetString(GL_SHADING_LANGUAGE_VERSION)) - std::cout << "\tGL_SHADING_LANGUAGE_VERSION: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; - - //Check our version of OpenGL is recent enough. - //We need at least 1.5 for vertex buffer objects, - if (!GLEW_VERSION_1_5) - { - std::cout << "Error: You need OpenGL version 1.5 to run this example." << std::endl; - exit(EXIT_FAILURE); - } + if(gl->glGetString(GL_VENDOR)) + std::cout << "\tGL_VENDOR: " << gl->glGetString(GL_VENDOR) << std::endl; + if(gl->glGetString(GL_RENDERER)) + std::cout << "\tGL_RENDERER: " << gl->glGetString(GL_RENDERER) << std::endl; + if(gl->glGetString(GL_VERSION)) + std::cout << "\tGL_VERSION: " << gl->glGetString(GL_VERSION) << std::endl; + if(gl->glGetString(GL_SHADING_LANGUAGE_VERSION)) + std::cout << "\tGL_SHADING_LANGUAGE_VERSION: " << gl->glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; //Set up the clear colour - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - glClearDepth(1.0f); - - //Enable the depth buffer - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LEQUAL); - - //Anable smooth lighting - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glShadeModel(GL_SMOOTH); - - //We'll be rendering with index/vertex arrays - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); + gl->glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + gl->glClearDepth(1.0f); + + gl->glEnable(GL_CULL_FACE); + gl->glEnable(GL_DEPTH_TEST); + gl->glDepthMask(GL_TRUE); + gl->glDepthFunc(GL_LEQUAL); + gl->glDepthRange(0.0, 1.0); + + if(!shader.addShaderFromSourceCode(QOpenGLShader::Vertex, R"( + #version 140 + + in vec4 position; //This will be the position of the vertex in model-space + + uniform mat4 cameraToClipMatrix; + uniform mat4 worldToCameraMatrix; + uniform mat4 modelToWorldMatrix; + + out vec4 worldPosition; //This is being passed to the fragment shader to calculate the normals + + void main() + { + worldPosition = modelToWorldMatrix * position; + vec4 cameraPosition = worldToCameraMatrix * worldPosition; + gl_Position = cameraToClipMatrix * cameraPosition; + } + )")) + { + std::cerr << shader.log().toStdString() << std::endl; + exit(EXIT_FAILURE); + } + + if(!shader.addShaderFromSourceCode(QOpenGLShader::Fragment, R"( + #version 130 + + in vec4 worldPosition; //Passed in from the vertex shader + + out vec4 outputColor; + + void main() + { + vec3 normal = normalize(cross(dFdy(worldPosition.xyz), dFdx(worldPosition.xyz))); + + float color = clamp(abs(dot(normalize(normal.xyz), vec3(0.9,0.1,0.5))), 0, 1); + outputColor = vec4(1.0, 0.5, color, 1.0); + } + )")) + { + std::cerr << shader.log().toStdString() << std::endl; + exit(EXIT_FAILURE); + } + + shader.bindAttributeLocation("position", 0); + + if(!shader.link()) + { + std::cerr << shader.log().toStdString() << std::endl; + exit(EXIT_FAILURE); + } + + shader.bind(); + + QMatrix4x4 worldToCameraMatrix{}; + worldToCameraMatrix.translate(0, 0, -50); //Move the camera back by 50 units + + shader.setUniformValue("worldToCameraMatrix", worldToCameraMatrix); + + shader.release(); } void OpenGLWidget::resizeGL(int w, int h) { //Setup the viewport - glViewport(0, 0, w, h); - - //Set up the projection matrix - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - float frustumSize = 32.0f; //Half the volume size - float aspect = static_cast(width()) / static_cast(height()); - glOrtho(frustumSize*aspect, -frustumSize*aspect, frustumSize, -frustumSize, 1.0, 1000); + gl->glViewport(0, 0, w, h); + + auto aspectRatio = w / (float)h; + float zNear = 1.0; + float zFar = 1000.0; + + QMatrix4x4 cameraToClipMatrix{}; + cameraToClipMatrix.frustum(-aspectRatio, aspectRatio, -1, 1, zNear, zFar); + + shader.bind(); + shader.setUniformValue("cameraToClipMatrix", cameraToClipMatrix); + shader.release(); } void OpenGLWidget::paintGL() { //Clear the screen - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - //Set up the viewing transformation - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0f,0.0f,-100.0f); //Centre volume and move back - glRotatef(-m_xRotation, 0.0f, 1.0f, 0.0f); - glRotatef(-m_yRotation, 1.0f, 0.0f, 0.0f); - glTranslatef(-32.0f,-32.0f,-32.0f); //Centre volume and move back - - //Bind the index buffer - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); - - //Bind the vertex buffer - glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); - glVertexPointer(3, GL_FLOAT, sizeof(PositionMaterialNormal), 0); - glNormalPointer(GL_FLOAT, sizeof(PositionMaterialNormal), (GLvoid*)12); - - glDrawRangeElements(GL_TRIANGLES, m_uBeginIndex, m_uEndIndex-1, m_uEndIndex - m_uBeginIndex, GL_UNSIGNED_INT, 0); + gl->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - GLenum errCode = glGetError(); + QMatrix4x4 modelToWorldMatrix{}; + modelToWorldMatrix.rotate(m_xRotation, 0, 1, 0); //rotate around y-axis + modelToWorldMatrix.rotate(m_yRotation, 1, 0, 0); //rotate around x-axis + modelToWorldMatrix.translate(-32, -32, -32); //centre the model on the origin + + shader.bind(); + + shader.setUniformValue("modelToWorldMatrix", modelToWorldMatrix); //Update to the latest camera matrix + + gl->glBindVertexArray(vertexArrayObject); + + gl->glDrawElements(GL_TRIANGLES, noOfIndices, GL_UNSIGNED_INT, 0); + + gl->glBindVertexArray(0); + + shader.release(); + + GLenum errCode = gl->glGetError(); if(errCode != GL_NO_ERROR) { - //What has replaced getErrorString() in the latest OpenGL? - std::cout << "OpenGL Error: " << errCode << std::endl; + std::cerr << "OpenGL Error: " << errCode << std::endl; } } diff --git a/examples/Basic/OpenGLWidget.h b/examples/Basic/OpenGLWidget.h index 011b9734..08ff3cc7 100644 --- a/examples/Basic/OpenGLWidget.h +++ b/examples/Basic/OpenGLWidget.h @@ -26,9 +26,12 @@ distribution. #include "PolyVoxCore/SurfaceMesh.h" -#include "glew/glew.h" +#include #include +#include +#include +#include class OpenGLWidget : public QGLWidget { @@ -40,8 +43,8 @@ public: void mouseMoveEvent(QMouseEvent* event); void mousePressEvent(QMouseEvent* event); - //Convert a SrfaceMesh to OpenGL index/vertex buffers - void setSurfaceMeshToRender(const PolyVox::SurfaceMesh& surfaceMesh); + //Convert a SurfaceMesh to OpenGL index/vertex buffers + void setSurfaceMeshToRender(const PolyVox::SurfaceMesh& surfaceMesh); protected: //Qt OpenGL functions @@ -51,11 +54,13 @@ protected: private: //Index/vertex buffer data - GLuint m_uBeginIndex; - GLuint m_uEndIndex; GLuint noOfIndices; GLuint indexBuffer; GLuint vertexBuffer; + GLuint vertexArrayObject; + + QOpenGLShaderProgram shader; + QOpenGLFunctions_3_1* gl; //Mouse data QPoint m_LastFrameMousePos; diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 64097731..9a3dac94 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -23,7 +23,7 @@ freely, subject to the following restrictions: #include "OpenGLWidget.h" -#include "PolyVoxCore/CubicSurfaceExtractorWithNormals.h" +#include "PolyVoxCore/CubicSurfaceExtractor.h" #include "PolyVoxCore/MarchingCubesSurfaceExtractor.h" #include "PolyVoxCore/SurfaceMesh.h" #include "PolyVoxCore/SimpleVolume.h" @@ -78,10 +78,10 @@ int main(int argc, char *argv[]) createSphereInVolume(volData, 30); //A mesh object to hold the result of surface extraction - SurfaceMesh mesh; + SurfaceMesh mesh; //Create a surface extractor. Comment out one of the following two lines to decide which type gets created. - CubicSurfaceExtractorWithNormals< SimpleVolume > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); + CubicSurfaceExtractor< SimpleVolume > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); //MarchingCubesSurfaceExtractor< SimpleVolume > surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); //Execute the surface extractor. From 464d713c2affcf7d8acb3403c9bd33bca673fb56 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Sun, 23 Mar 2014 12:16:02 +0000 Subject: [PATCH 5/8] Remove usage of QOpenGLFunctions and use GLEW instead. Qt's OpenGL interface was causing problems on Windows since it doesn't mix well with ANGLE. Relates to issue #50. --- examples/Basic/CMakeLists.txt | 8 +++- examples/Basic/OpenGLWidget.cpp | 79 +++++++++++++++------------------ examples/Basic/OpenGLWidget.h | 5 +-- 3 files changed, 43 insertions(+), 49 deletions(-) diff --git a/examples/Basic/CMakeLists.txt b/examples/Basic/CMakeLists.txt index 66515549..a7b81ff5 100644 --- a/examples/Basic/CMakeLists.txt +++ b/examples/Basic/CMakeLists.txt @@ -32,13 +32,17 @@ SET(INC_FILES OpenGLWidget.h ) +add_definitions(-DGLEW_STATIC) + #"Sources" and "Headers" are the group names in Visual Studio. #They may have other uses too... SOURCE_GROUP("Sources" FILES ${SRC_FILES}) SOURCE_GROUP("Headers" FILES ${INC_FILES}) +FIND_PACKAGE(OpenGL REQUIRED) + #Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) -INCLUDE_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR}) LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}) #Build @@ -46,7 +50,7 @@ ADD_EXECUTABLE(BasicExample ${SRC_FILES}) IF(MSVC) SET_TARGET_PROPERTIES(BasicExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") ENDIF(MSVC) -TARGET_LINK_LIBRARIES(BasicExample Qt5::OpenGL PolyVoxCore) +TARGET_LINK_LIBRARIES(BasicExample glew Qt5::OpenGL ${OPENGL_gl_LIBRARY} PolyVoxCore) SET_PROPERTY(TARGET BasicExample PROPERTY FOLDER "Examples") #Install - Only install the example in Windows diff --git a/examples/Basic/OpenGLWidget.cpp b/examples/Basic/OpenGLWidget.cpp index 37f972af..5b93b08e 100644 --- a/examples/Basic/OpenGLWidget.cpp +++ b/examples/Basic/OpenGLWidget.cpp @@ -11,7 +11,6 @@ OpenGLWidget::OpenGLWidget(QWidget *parent) :QGLWidget(parent) ,m_xRotation(0) ,m_yRotation(0) - ,gl(nullptr) { } @@ -22,63 +21,57 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMeshglGenVertexArrays(1, &vertexArrayObject); - gl->glBindVertexArray(vertexArrayObject); + glGenVertexArrays(1, &vertexArrayObject); + glBindVertexArray(vertexArrayObject); //The GL_ARRAY_BUFFER will contain the list of vertex positions - gl->glGenBuffers(1, &vertexBuffer); - gl->glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); - gl->glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterial), vecVertices.data(), GL_STATIC_DRAW); + glGenBuffers(1, &vertexBuffer); + glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); + glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(PositionMaterial), vecVertices.data(), GL_STATIC_DRAW); //and GL_ELEMENT_ARRAY_BUFFER will contain the indices - gl->glGenBuffers(1, &indexBuffer); - gl->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); - gl->glBufferData(GL_ELEMENT_ARRAY_BUFFER, vecIndices.size() * sizeof(uint32_t), vecIndices.data(), GL_STATIC_DRAW); + glGenBuffers(1, &indexBuffer); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, vecIndices.size() * sizeof(uint32_t), vecIndices.data(), GL_STATIC_DRAW); //We need to tell OpenGL how to understand the format of the vertex data - gl->glEnableVertexAttribArray(0); //We're talking about shader attribute '0' - gl->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(PositionMaterial), 0); //take the first 3 floats from every sizeof(decltype(vecVertices)::value_type) + glEnableVertexAttribArray(0); //We're talking about shader attribute '0' + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(PositionMaterial), 0); //take the first 3 floats from every sizeof(decltype(vecVertices)::value_type) - gl->glBindVertexArray(0); + glBindVertexArray(0); noOfIndices = vecIndices.size(); //Save this for the call to glDrawElements later } void OpenGLWidget::initializeGL() { - //'gl' will give us access to all the OpenGL functions - gl = context()->contextHandle()->versionFunctions(); - if(!gl) + GLenum err = glewInit(); + if (GLEW_OK != err) { - std::cerr << "Could not obtain required OpenGL context version" << std::endl; - exit(EXIT_FAILURE); - } - if(!gl->initializeOpenGLFunctions()) - { - std::cerr << "Could not initialise OpenGL functions" << std::endl; - exit(EXIT_FAILURE); + /* Problem: glewInit failed, something is seriously wrong. */ + std::cout << "GLEW Error: " << glewGetErrorString(err) << std::endl; } //Print out some information about the OpenGL implementation. std::cout << "OpenGL Implementation Details:" << std::endl; - if(gl->glGetString(GL_VENDOR)) - std::cout << "\tGL_VENDOR: " << gl->glGetString(GL_VENDOR) << std::endl; - if(gl->glGetString(GL_RENDERER)) - std::cout << "\tGL_RENDERER: " << gl->glGetString(GL_RENDERER) << std::endl; - if(gl->glGetString(GL_VERSION)) - std::cout << "\tGL_VERSION: " << gl->glGetString(GL_VERSION) << std::endl; - if(gl->glGetString(GL_SHADING_LANGUAGE_VERSION)) - std::cout << "\tGL_SHADING_LANGUAGE_VERSION: " << gl->glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; + if(glGetString(GL_VENDOR)) + std::cout << "\tGL_VENDOR: " << glGetString(GL_VENDOR) << std::endl; + if(glGetString(GL_RENDERER)) + std::cout << "\tGL_RENDERER: " << glGetString(GL_RENDERER) << std::endl; + if(glGetString(GL_VERSION)) + std::cout << "\tGL_VERSION: " << glGetString(GL_VERSION) << std::endl; + if(glGetString(GL_SHADING_LANGUAGE_VERSION)) + std::cout << "\tGL_SHADING_LANGUAGE_VERSION: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl; //Set up the clear colour - gl->glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - gl->glClearDepth(1.0f); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glClearDepth(1.0f); - gl->glEnable(GL_CULL_FACE); - gl->glEnable(GL_DEPTH_TEST); - gl->glDepthMask(GL_TRUE); - gl->glDepthFunc(GL_LEQUAL); - gl->glDepthRange(0.0, 1.0); + glEnable(GL_CULL_FACE); + glEnable(GL_DEPTH_TEST); + glDepthMask(GL_TRUE); + glDepthFunc(GL_LEQUAL); + glDepthRange(0.0, 1.0); if(!shader.addShaderFromSourceCode(QOpenGLShader::Vertex, R"( #version 140 @@ -144,7 +137,7 @@ void OpenGLWidget::initializeGL() void OpenGLWidget::resizeGL(int w, int h) { //Setup the viewport - gl->glViewport(0, 0, w, h); + glViewport(0, 0, w, h); auto aspectRatio = w / (float)h; float zNear = 1.0; @@ -161,7 +154,7 @@ void OpenGLWidget::resizeGL(int w, int h) void OpenGLWidget::paintGL() { //Clear the screen - gl->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); QMatrix4x4 modelToWorldMatrix{}; modelToWorldMatrix.rotate(m_xRotation, 0, 1, 0); //rotate around y-axis @@ -172,15 +165,15 @@ void OpenGLWidget::paintGL() shader.setUniformValue("modelToWorldMatrix", modelToWorldMatrix); //Update to the latest camera matrix - gl->glBindVertexArray(vertexArrayObject); + glBindVertexArray(vertexArrayObject); - gl->glDrawElements(GL_TRIANGLES, noOfIndices, GL_UNSIGNED_INT, 0); + glDrawElements(GL_TRIANGLES, noOfIndices, GL_UNSIGNED_INT, 0); - gl->glBindVertexArray(0); + glBindVertexArray(0); shader.release(); - GLenum errCode = gl->glGetError(); + GLenum errCode = glGetError(); if(errCode != GL_NO_ERROR) { std::cerr << "OpenGL Error: " << errCode << std::endl; diff --git a/examples/Basic/OpenGLWidget.h b/examples/Basic/OpenGLWidget.h index 08ff3cc7..1b201803 100644 --- a/examples/Basic/OpenGLWidget.h +++ b/examples/Basic/OpenGLWidget.h @@ -26,12 +26,10 @@ distribution. #include "PolyVoxCore/SurfaceMesh.h" -#include +#include "glew/glew.h" #include #include -#include -#include class OpenGLWidget : public QGLWidget { @@ -60,7 +58,6 @@ private: GLuint vertexArrayObject; QOpenGLShaderProgram shader; - QOpenGLFunctions_3_1* gl; //Mouse data QPoint m_LastFrameMousePos; From 45302fde0260d1169a9fa827e050d2cb94fbf811 Mon Sep 17 00:00:00 2001 From: Matt Williams Date: Thu, 27 Mar 2014 10:24:29 +0000 Subject: [PATCH 6/8] Qt is not REQUIERD. This was causing errors. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef7af1f9..0a994624 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,8 +43,8 @@ IF(WIN32) ENDIF() # Qt is required for building the tests, the example and optionally for bundling the documentation -find_package(Qt5Test 5.2 REQUIRED) -find_package(Qt5OpenGL 5.2 REQUIRED) +find_package(Qt5Test 5.2) +find_package(Qt5OpenGL 5.2) set_package_properties(Doxygen PROPERTIES URL http://www.doxygen.org DESCRIPTION "API documentation generator" TYPE OPTIONAL PURPOSE "Building the API documentation") set_package_properties(Qt5Test PROPERTIES DESCRIPTION "C++ framework" URL http://qt-project.org) From fe3f2d589ed71fb26a4cfd19777d39cf7ae369cf Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 14 Apr 2014 21:08:05 +0200 Subject: [PATCH 7/8] Fixed uninitialized variables (was causing crash on OS X). --- examples/SmoothLOD/OpenGLWidget.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/SmoothLOD/OpenGLWidget.cpp b/examples/SmoothLOD/OpenGLWidget.cpp index 7c706648..9b016303 100644 --- a/examples/SmoothLOD/OpenGLWidget.cpp +++ b/examples/SmoothLOD/OpenGLWidget.cpp @@ -7,6 +7,15 @@ using namespace std; OpenGLWidget::OpenGLWidget(QWidget *parent) :QGLWidget(parent) + ,m_uBeginIndex(0) + ,m_uEndIndex(0) + ,indexBuffer(0) + ,vertexBuffer(0) + + ,m_uBeginIndexLow(0) + ,m_uEndIndexLow(0) + ,indexBufferLow(0) + ,vertexBufferLow(0) ,m_xRotation(0) ,m_yRotation(0) { From 2da902d5f95f959cfe9aa863040d3fa26d0aafa8 Mon Sep 17 00:00:00 2001 From: David Williams Date: Mon, 5 May 2014 20:29:52 +0200 Subject: [PATCH 8/8] This change reverts PolyVox back to using Qt 4.8. This is expected to be a temporary change, required because moving to Qt 5 caused various complications on Windows which we are not yet ready to address. For more details see here: https://bitbucket.org/volumesoffun/polyvox/issue/41/upgrade-to-qt-5 --- CMakeLists.txt | 22 +++++++++------- examples/Basic/CMakeLists.txt | 6 +++-- examples/Basic/OpenGLWidget.cpp | 6 ++--- examples/Basic/OpenGLWidget.h | 4 +-- examples/OpenGL/CMakeLists.txt | 2 +- examples/Paging/CMakeLists.txt | 4 ++- examples/SmoothLOD/CMakeLists.txt | 4 ++- tests/CMakeLists.txt | 43 +++++++++++++++++-------------- 8 files changed, 52 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a994624..6691be4a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,14 +43,18 @@ IF(WIN32) ENDIF() # Qt is required for building the tests, the example and optionally for bundling the documentation -find_package(Qt5Test 5.2) -find_package(Qt5OpenGL 5.2) +FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtOpenGL QtTest) +INCLUDE(${QT_USE_FILE}) +if(CMAKE_VERSION VERSION_LESS "2.8.6") + set_package_info(Doxygen "API documentation generator" http://www.doxygen.org "Building the API documentation") + set_package_info(Qt4 "C++ framework" http://qt-project.org "Building the examples and tests") +else() + set_package_properties(Doxygen PROPERTIES URL http://www.doxygen.org DESCRIPTION "API documentation generator" TYPE OPTIONAL PURPOSE "Building the API documentation") + set_package_properties(Qt4 PROPERTIES DESCRIPTION "C++ framework" URL http://qt-project.org) + set_package_properties(Qt4 PROPERTIES TYPE RECOMMENDED PURPOSE "Building the examples") + set_package_properties(Qt4 PROPERTIES TYPE OPTIONAL PURPOSE "Building the tests") +endif() -set_package_properties(Doxygen PROPERTIES URL http://www.doxygen.org DESCRIPTION "API documentation generator" TYPE OPTIONAL PURPOSE "Building the API documentation") -set_package_properties(Qt5Test PROPERTIES DESCRIPTION "C++ framework" URL http://qt-project.org) -set_package_properties(Qt5Test PROPERTIES TYPE OPTIONAL PURPOSE "Building the tests") -set_package_properties(Qt5OpenGL PROPERTIES DESCRIPTION "C++ framework" URL http://qt-project.org) -set_package_properties(Qt5OpenGL PROPERTIES TYPE RECOMMENDED PURPOSE "Building the examples") IF(CMAKE_COMPILER_IS_GNUCXX) #Maybe "OR MINGW" ADD_DEFINITIONS(-std=c++0x) #Enable C++0x mode @@ -62,7 +66,7 @@ endif() ADD_SUBDIRECTORY(library) OPTION(ENABLE_EXAMPLES "Should the examples be built" ON) -IF(ENABLE_EXAMPLES AND Qt5OpenGL_FOUND) +IF(ENABLE_EXAMPLES AND QT_QTOPENGL_FOUND) ADD_SUBDIRECTORY(examples/common) ADD_SUBDIRECTORY(examples/Basic) ADD_SUBDIRECTORY(examples/Paging) @@ -77,7 +81,7 @@ ENDIF() INCLUDE(Packaging.cmake) OPTION(ENABLE_TESTS "Should the tests be built" ON) -IF(ENABLE_TESTS AND Qt5Test_FOUND) +IF(ENABLE_TESTS AND QT_QTTEST_FOUND) INCLUDE(CTest) MARK_AS_ADVANCED(FORCE BUILD_TESTING) ADD_SUBDIRECTORY(tests) diff --git a/examples/Basic/CMakeLists.txt b/examples/Basic/CMakeLists.txt index a7b81ff5..02e203d2 100644 --- a/examples/Basic/CMakeLists.txt +++ b/examples/Basic/CMakeLists.txt @@ -19,6 +19,8 @@ # 3. This notice may not be removed or altered from any source # distribution. +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + PROJECT(BasicExample) #Projects source files @@ -42,7 +44,7 @@ SOURCE_GROUP("Headers" FILES ${INC_FILES}) FIND_PACKAGE(OpenGL REQUIRED) #Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) -INCLUDE_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR}) +INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxCore_BINARY_DIR}/include ${PolyVoxCore_SOURCE_DIR}/include ${GLEW_SOURCE_DIR}) LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR}) #Build @@ -50,7 +52,7 @@ ADD_EXECUTABLE(BasicExample ${SRC_FILES}) IF(MSVC) SET_TARGET_PROPERTIES(BasicExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") ENDIF(MSVC) -TARGET_LINK_LIBRARIES(BasicExample glew Qt5::OpenGL ${OPENGL_gl_LIBRARY} PolyVoxCore) +TARGET_LINK_LIBRARIES(BasicExample glew ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) SET_PROPERTY(TARGET BasicExample PROPERTY FOLDER "Examples") #Install - Only install the example in Windows diff --git a/examples/Basic/OpenGLWidget.cpp b/examples/Basic/OpenGLWidget.cpp index 5b93b08e..9b662fb2 100644 --- a/examples/Basic/OpenGLWidget.cpp +++ b/examples/Basic/OpenGLWidget.cpp @@ -2,7 +2,7 @@ #include #include -#include +//#include using namespace PolyVox; using namespace std; @@ -73,7 +73,7 @@ void OpenGLWidget::initializeGL() glDepthFunc(GL_LEQUAL); glDepthRange(0.0, 1.0); - if(!shader.addShaderFromSourceCode(QOpenGLShader::Vertex, R"( + if (!shader.addShaderFromSourceCode(QGLShader::Vertex, R"( #version 140 in vec4 position; //This will be the position of the vertex in model-space @@ -96,7 +96,7 @@ void OpenGLWidget::initializeGL() exit(EXIT_FAILURE); } - if(!shader.addShaderFromSourceCode(QOpenGLShader::Fragment, R"( + if (!shader.addShaderFromSourceCode(QGLShader::Fragment, R"( #version 130 in vec4 worldPosition; //Passed in from the vertex shader diff --git a/examples/Basic/OpenGLWidget.h b/examples/Basic/OpenGLWidget.h index 1b201803..1126aba3 100644 --- a/examples/Basic/OpenGLWidget.h +++ b/examples/Basic/OpenGLWidget.h @@ -29,7 +29,7 @@ distribution. #include "glew/glew.h" #include -#include +#include class OpenGLWidget : public QGLWidget { @@ -57,7 +57,7 @@ private: GLuint vertexBuffer; GLuint vertexArrayObject; - QOpenGLShaderProgram shader; + QGLShaderProgram shader; //Mouse data QPoint m_LastFrameMousePos; diff --git a/examples/OpenGL/CMakeLists.txt b/examples/OpenGL/CMakeLists.txt index 32709e81..5cd1ed55 100644 --- a/examples/OpenGL/CMakeLists.txt +++ b/examples/OpenGL/CMakeLists.txt @@ -60,7 +60,7 @@ ADD_EXECUTABLE(OpenGLExample ${SRC_FILES}) IF(MSVC) SET_TARGET_PROPERTIES(OpenGLExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") ENDIF(MSVC) -TARGET_LINK_LIBRARIES(OpenGLExample glew Qt5::OpenGL ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) +TARGET_LINK_LIBRARIES(OpenGLExample glew ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) SET_PROPERTY(TARGET OpenGLExample PROPERTY FOLDER "Examples") #Install - Only install the example in Windows diff --git a/examples/Paging/CMakeLists.txt b/examples/Paging/CMakeLists.txt index 97cec53a..e8020b2d 100644 --- a/examples/Paging/CMakeLists.txt +++ b/examples/Paging/CMakeLists.txt @@ -19,6 +19,8 @@ # 3. This notice may not be removed or altered from any source # distribution. +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + PROJECT(PagingExample) #Projects source files @@ -52,7 +54,7 @@ ADD_EXECUTABLE(PagingExample ${SRC_FILES}) IF(MSVC) SET_TARGET_PROPERTIES(PagingExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") ENDIF(MSVC) -TARGET_LINK_LIBRARIES(PagingExample glew Qt5::OpenGL ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) +TARGET_LINK_LIBRARIES(PagingExample glew ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) SET_PROPERTY(TARGET PagingExample PROPERTY FOLDER "Examples") #Install - Only install the example in Windows diff --git a/examples/SmoothLOD/CMakeLists.txt b/examples/SmoothLOD/CMakeLists.txt index 9c5649fc..570cda55 100644 --- a/examples/SmoothLOD/CMakeLists.txt +++ b/examples/SmoothLOD/CMakeLists.txt @@ -19,6 +19,8 @@ # 3. This notice may not be removed or altered from any source # distribution. +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + PROJECT(SmoothLODExample) #Projects source files @@ -50,7 +52,7 @@ ADD_EXECUTABLE(SmoothLODExample ${SRC_FILES}) IF(MSVC) SET_TARGET_PROPERTIES(SmoothLODExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") #All warnings ENDIF(MSVC) -TARGET_LINK_LIBRARIES(SmoothLODExample glew Qt5::OpenGL ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) +TARGET_LINK_LIBRARIES(SmoothLODExample glew ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) SET_PROPERTY(TARGET SmoothLODExample PROPERTY FOLDER "Examples") #Install - Only install the example in Windows diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6b06437b..fbffe9d9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,14 +24,12 @@ # # Also sets LATEST_TEST to point to the output executable of the test for easy # ADD_TEST()ing - -set(CMAKE_AUTOMOC TRUE) - -MACRO(CREATE_TEST sourcefile executablename) +MACRO(CREATE_TEST headerfile sourcefile executablename) UNSET(test_moc_SRCS) #clear out the MOCs from previous tests + QT4_WRAP_CPP(test_moc_SRCS ${headerfile}) LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR} ${PolyVoxUtil_BINARY_DIR}) ADD_EXECUTABLE(${executablename} ${sourcefile} ${test_moc_SRCS}) - TARGET_LINK_LIBRARIES(${executablename} PolyVoxCore PolyVoxUtil Qt5::Test) + TARGET_LINK_LIBRARIES(${executablename} PolyVoxCore PolyVoxUtil ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY}) #HACK. This is needed since everything is built in the base dir in Windows. As of 2.8 we should change this. IF(WIN32) SET(LATEST_TEST ${EXECUTABLE_OUTPUT_PATH}/${executablename}) @@ -48,17 +46,22 @@ MACRO(CREATE_TEST sourcefile executablename) ENDMACRO(CREATE_TEST) INCLUDE_DIRECTORIES(${PolyVoxCore_BINARY_DIR}/include ${PolyVox_SOURCE_DIR}/PolyVoxCore/include ${CMAKE_CURRENT_BINARY_DIR}) +REMOVE_DEFINITIONS(-DQT_GUI_LIB) #Make sure the tests don't link to the QtGui # Test Template. Copy and paste this template for consistant naming. # # ClassName tests -# CREATE_TEST(TestClassName.cpp TestClassName) +# CREATE_TEST(TestClassName.h TestClassName.cpp TestClassName) # ADD_TEST(ClassNameFeature1Test ${LATEST_TEST} testFeature1) # ADD_TEST(ClassNameFeature2Test ${LATEST_TEST} testFeature2) # Python tests IF(BUILD_BINDINGS) FIND_PACKAGE(PythonInterp 3) - set_package_properties(PythonInterp PROPERTIES URL http://www.python.org DESCRIPTION "Python Interpereter" TYPE OPTIONAL PURPOSE "Running the Python tests") + IF(CMAKE_VERSION VERSION_LESS "2.8.6") + set_package_info(PythonInterp "Python Interpereter" http://www.python.org "Running the Python tests") + ELSE() + set_package_properties(PythonInterp PROPERTIES URL http://www.python.org DESCRIPTION "Python Interpereter" TYPE OPTIONAL PURPOSE "Running the Python tests") + ENDIF() IF(PYTHONINTERP_FOUND) ADD_TEST(PythonSurfaceExtractorTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/TestSurfaceExtractor.py) ADD_TEST(PythonRaycastTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/TestRaycast.py) @@ -66,38 +69,38 @@ IF(BUILD_BINDINGS) ENDIF() # AmbientOcclusionGenerator tests -CREATE_TEST(TestAmbientOcclusionGenerator.cpp TestAmbientOcclusionGenerator) +CREATE_TEST(TestAmbientOcclusionGenerator.h TestAmbientOcclusionGenerator.cpp TestAmbientOcclusionGenerator) # Array tests -CREATE_TEST(TestArray.cpp TestArray) +CREATE_TEST(TestArray.h TestArray.cpp TestArray) # AStarPathfinder tests -CREATE_TEST(TestAStarPathfinder.cpp TestAStarPathfinder) +CREATE_TEST(TestAStarPathfinder.h TestAStarPathfinder.cpp TestAStarPathfinder) -CREATE_TEST(TestCubicSurfaceExtractor.cpp TestCubicSurfaceExtractor) +CREATE_TEST(TestCubicSurfaceExtractor.h TestCubicSurfaceExtractor.cpp TestCubicSurfaceExtractor) # Low pass filter tests -CREATE_TEST(TestLowPassFilter.cpp TestLowPassFilter) +CREATE_TEST(TestLowPassFilter.h TestLowPassFilter.cpp TestLowPassFilter) # Material tests -CREATE_TEST(testmaterial.cpp testmaterial) +CREATE_TEST(testmaterial.h testmaterial.cpp testmaterial) # Raycast tests -CREATE_TEST(TestRaycast.cpp TestRaycast) +CREATE_TEST(TestRaycast.h TestRaycast.cpp TestRaycast) # Picking tests -CREATE_TEST(TestPicking.cpp TestPicking) +CREATE_TEST(TestPicking.h TestPicking.cpp TestPicking) # Region tests -CREATE_TEST(TestRegion.cpp TestRegion) +CREATE_TEST(TestRegion.h TestRegion.cpp TestRegion) -CREATE_TEST(TestSurfaceExtractor.cpp TestSurfaceExtractor) +CREATE_TEST(TestSurfaceExtractor.h TestSurfaceExtractor.cpp TestSurfaceExtractor) #Vector tests -CREATE_TEST(testvector.cpp testvector) +CREATE_TEST(testvector.h testvector.cpp testvector) # Volume tests -CREATE_TEST(testvolume.cpp testvolume) +CREATE_TEST(testvolume.h testvolume.cpp testvolume) # Volume subclass tests -CREATE_TEST(TestVolumeSubclass.cpp TestVolumeSubclass) +CREATE_TEST(TestVolumeSubclass.h TestVolumeSubclass.cpp TestVolumeSubclass)