Work on getting the OpenGL/Qt5 support working with new header-only library.

This commit is contained in:
David Williams 2015-02-09 22:11:06 +01:00
parent d9da93b6c0
commit c62bde0066
9 changed files with 400 additions and 85 deletions

View File

@ -1,5 +1,5 @@
# Copyright (c) 2007-2014 Matt Williams # Copyright (c) 2007-2012 Matt Williams
# Copyright (c) 2007-2014 David Williams # Copyright (c) 2007-2012 David Williams
# #
# This software is provided 'as-is', without any express or implied # This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages # warranty. In no event will the authors be held liable for any damages
@ -24,63 +24,68 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.6)
PROJECT(PolyVox) PROJECT(PolyVox)
include(FeatureSummary)
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
#Set up for building the library itself
SET(POLYVOX_VERSION_MAJOR "0") SET(POLYVOX_VERSION_MAJOR "0")
SET(POLYVOX_VERSION_MINOR "2") SET(POLYVOX_VERSION_MINOR "2")
SET(POLYVOX_VERSION_PATCH "1") SET(POLYVOX_VERSION_PATCH "1")
SET(POLYVOX_VERSION "${POLYVOX_VERSION_MAJOR}.${POLYVOX_VERSION_MINOR}.${POLYVOX_VERSION_PATCH}" CACHE STRING "PolyVox version") SET(POLYVOX_VERSION "${POLYVOX_VERSION_MAJOR}.${POLYVOX_VERSION_MINOR}.${POLYVOX_VERSION_PATCH}" CACHE STRING "PolyVox version")
MARK_AS_ADVANCED(FORCE POLYVOX_VERSION) MARK_AS_ADVANCED(FORCE POLYVOX_VERSION)
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
include(FeatureSummary)
FIND_PACKAGE(Doxygen)
OPTION(ENABLE_EXAMPLES "Should the examples be built" ON)
SET(LIBRARY_TYPE "DYNAMIC" CACHE STRING "Should the library be STATIC or DYNAMIC") SET(LIBRARY_TYPE "DYNAMIC" CACHE STRING "Should the library be STATIC or DYNAMIC")
SET_PROPERTY(CACHE LIBRARY_TYPE PROPERTY STRINGS DYNAMIC STATIC) SET_PROPERTY(CACHE LIBRARY_TYPE PROPERTY STRINGS DYNAMIC STATIC)
IF(WIN32) IF(WIN32)
SET(LIBRARY_TYPE "STATIC") SET(LIBRARY_TYPE "STATIC")
ENDIF() ENDIF()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") # 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)
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
ENDIF()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
ADD_DEFINITIONS(-std=c++0x) #Enable C++0x mode ADD_DEFINITIONS(-std=c++0x) #Enable C++0x mode
endif() endif()
#We need to find doxygen before building the library
FIND_PACKAGE(Doxygen)
ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(include)
# 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})
#Examples
OPTION(ENABLE_EXAMPLES "Should the examples be built" ON) 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)
ADD_SUBDIRECTORY(examples/OpenGL)
ADD_SUBDIRECTORY(examples/SmoothLOD)
ADD_SUBDIRECTORY(examples/Python)
SET(BUILD_EXAMPLES ON) SET(BUILD_EXAMPLES ON)
add_subdirectory(examples)
ELSE() ELSE()
SET(BUILD_EXAMPLES OFF) SET(BUILD_EXAMPLES OFF)
ENDIF() ENDIF()
INCLUDE(Packaging.cmake) INCLUDE(Packaging.cmake)
#Tests
OPTION(ENABLE_TESTS "Should the tests be built" ON) OPTION(ENABLE_TESTS "Should the tests be built" ON)
IF(ENABLE_TESTS AND QT_QTTEST_FOUND) IF(ENABLE_TESTS AND Qt5Test_FOUND)
SET(BUILD_TESTS ON)
INCLUDE(CTest) INCLUDE(CTest)
MARK_AS_ADVANCED(FORCE BUILD_TESTING) MARK_AS_ADVANCED(FORCE BUILD_TESTING)
ADD_SUBDIRECTORY(tests) ADD_SUBDIRECTORY(tests)
SET(BUILD_TESTS ON)
ELSE() ELSE()
SET(BUILD_TESTS OFF) SET(BUILD_TESTS OFF)
ENDIF() ENDIF()
#Manual
#Check if we will building _and_ bundling the docs #Check if we will building _and_ bundling the docs
IF(DOXYGEN_FOUND AND QT_QCOLLECTIONGENERATOR_EXECUTABLE) IF(DOXYGEN_FOUND AND QT_QCOLLECTIONGENERATOR_EXECUTABLE)
SET(BUILD_AND_BUNDLE_DOCS ON) SET(BUILD_AND_BUNDLE_DOCS ON)
@ -92,11 +97,6 @@ ADD_SUBDIRECTORY(documentation)
ADD_SUBDIRECTORY(bindings) ADD_SUBDIRECTORY(bindings)
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")
add_feature_info("Examples" BUILD_EXAMPLES "Examples of PolyVox usage") add_feature_info("Examples" BUILD_EXAMPLES "Examples of PolyVox usage")
add_feature_info("Tests" BUILD_TESTS "Unit tests") add_feature_info("Tests" BUILD_TESTS "Unit tests")
add_feature_info("Bindings" BUILD_BINDINGS "SWIG bindings") add_feature_info("Bindings" BUILD_BINDINGS "SWIG bindings")

View File

@ -24,29 +24,38 @@ PROJECT(BasicExample)
#Projects source files #Projects source files
SET(SRC_FILES SET(SRC_FILES
main.cpp main.cpp
OpenGLWidget.cpp ../common/OpenGLWidget.cpp
) )
#Projects headers files #Projects headers files
SET(INC_FILES SET(INC_FILES
OpenGLWidget.h ../common/OpenGLWidget.h
) )
add_definitions(-DGLEW_STATIC)
#"Sources" and "Headers" are the group names in Visual Studio. #"Sources" and "Headers" are the group names in Visual Studio.
#They may have other uses too... #They may have other uses too...
SOURCE_GROUP("Sources" FILES ${SRC_FILES}) SOURCE_GROUP("Sources" FILES ${SRC_FILES})
SOURCE_GROUP("Headers" FILES ${INC_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) #Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
INCLUDE_DIRECTORIES(${PolyVoxHeaders_SOURCE_DIR}) INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxHeaders_SOURCE_DIR} ${GLEW_SOURCE_DIR})
LINK_DIRECTORIES(${PolyVoxCore_BINARY_DIR})
#This will include the shader files inside the compiled binary
QT5_ADD_RESOURCES(COMMON_RESOURCES_RCC ../common/example.qrc)
# Put the resources in a seperate folder in Visual Studio
SOURCE_GROUP("Resource Files" FILES ../common/example.qrc ${COMMON_RESOURCES_RCC})
#Build #Build
ADD_EXECUTABLE(BasicExample ${SRC_FILES}) ADD_EXECUTABLE(BasicExample ${SRC_FILES} ${COMMON_RESOURCES_RCC})
IF(MSVC) IF(MSVC)
SET_TARGET_PROPERTIES(BasicExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") SET_TARGET_PROPERTIES(BasicExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") #All warnings
ENDIF(MSVC) ENDIF(MSVC)
TARGET_LINK_LIBRARIES(BasicExample Qt5::OpenGL ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} PolyVoxCore) TARGET_LINK_LIBRARIES(BasicExample glew Qt5::OpenGL ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY})
SET_PROPERTY(TARGET BasicExample PROPERTY FOLDER "Examples") SET_PROPERTY(TARGET BasicExample PROPERTY FOLDER "Examples")
#Install - Only install the example in Windows #Install - Only install the example in Windows

View File

@ -1,3 +1,4 @@
<<<<<<< HEAD
#include "OpenGLWidget.h" #include "OpenGLWidget.h"
#include <QMouseEvent> #include <QMouseEvent>
@ -193,3 +194,205 @@ void OpenGLWidget::mouseMoveEvent(QMouseEvent* event)
update(); update();
} }
=======
#include "OpenGLWidget.h"
#include <QMouseEvent>
#include <QMatrix4x4>
#include <QtMath>
using namespace PolyVox;
using namespace std;
OpenGLWidget::OpenGLWidget(QWidget *parent)
:QGLWidget(parent)
,m_xRotation(0)
,m_yRotation(0)
{
}
void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PositionMaterial>& surfaceMesh)
{
//Convienient access to the vertices and indices
const auto& vecIndices = surfaceMesh.getIndices();
const auto& vecVertices = surfaceMesh.getVertices();
//Create the VAO for the mesh
glGenVertexArrays(1, &vertexArrayObject);
glBindVertexArray(vertexArrayObject);
//The GL_ARRAY_BUFFER will contain the list of vertex positions
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
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
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)
glBindVertexArray(0);
noOfIndices = vecIndices.size(); //Save this for the call to glDrawElements later
}
void OpenGLWidget::initializeGL()
{
GLenum err = glewInit();
if (GLEW_OK != err)
{
/* 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(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
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
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
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);
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);
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
glBindVertexArray(vertexArrayObject);
glDrawElements(GL_TRIANGLES, noOfIndices, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
shader.release();
GLenum errCode = glGetError();
if(errCode != GL_NO_ERROR)
{
std::cerr << "OpenGL Error: " << errCode << std::endl;
}
}
void OpenGLWidget::mousePressEvent(QMouseEvent* event)
{
m_CurrentMousePos = event->pos();
m_LastFrameMousePos = m_CurrentMousePos;
update();
}
void OpenGLWidget::mouseMoveEvent(QMouseEvent* event)
{
m_CurrentMousePos = event->pos();
QPoint diff = m_CurrentMousePos - m_LastFrameMousePos;
m_xRotation += diff.x();
m_yRotation += diff.y();
m_LastFrameMousePos = m_CurrentMousePos;
update();
}
>>>>>>> parent of 2da902d... 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.

View File

@ -1,3 +1,4 @@
<<<<<<< HEAD
/******************************************************************************* /*******************************************************************************
Copyright (c) 2005-2009 David Williams Copyright (c) 2005-2009 David Williams
@ -69,3 +70,74 @@ private:
}; };
#endif //__BasicExample_OpenGLWidget_H__ #endif //__BasicExample_OpenGLWidget_H__
=======
/*******************************************************************************
Copyright (c) 2005-2009 David Williams
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*******************************************************************************/
#ifndef __BasicExample_OpenGLWidget_H__
#define __BasicExample_OpenGLWidget_H__
#include "PolyVoxCore/SurfaceMesh.h"
#include "glew/glew.h"
#include <QGLWidget>
#include <QOpenGLShaderProgram>
class OpenGLWidget : public QGLWidget
{
public:
//Constructor
OpenGLWidget(QWidget *parent);
//Mouse handling
void mouseMoveEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
//Convert a SurfaceMesh to OpenGL index/vertex buffers
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::PositionMaterial>& surfaceMesh);
protected:
//Qt OpenGL functions
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
private:
//Index/vertex buffer data
GLuint noOfIndices;
GLuint indexBuffer;
GLuint vertexBuffer;
GLuint vertexArrayObject;
QOpenGLShaderProgram shader;
//Mouse data
QPoint m_LastFrameMousePos;
QPoint m_CurrentMousePos;
int m_xRotation;
int m_yRotation;
};
#endif //__BasicExample_OpenGLWidget_H__
>>>>>>> parent of 2da902d... 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.

View File

@ -26,36 +26,47 @@ PROJECT(OpenGLExample)
#Projects source files #Projects source files
SET(SRC_FILES SET(SRC_FILES
main.cpp main.cpp
#OpenGLImmediateModeSupport.cpp
#OpenGLSupport.cpp
#OpenGLVertexBufferObjectSupport.cpp
../common/OpenGLWidget.cpp ../common/OpenGLWidget.cpp
Shapes.cpp Shapes.cpp
) )
#Projects headers files #Projects headers files
SET(INC_FILES SET(INC_FILES
OpenGLWidget.h #OpenGLImmediateModeSupport.h
#OpenGLSupport.h
#OpenGLVertexBufferObjectSupport.h
../common/OpenGLWidget.h
Shapes.h Shapes.h
) )
add_definitions(-DGLEW_STATIC) 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) FIND_PACKAGE(OpenGL REQUIRED)
#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) #Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxHeaders_SOURCE_DIR} ${GLEW_SOURCE_DIR}) INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxHeaders_SOURCE_DIR} ${GLEW_SOURCE_DIR})
#This will include the shader files inside the compiled binary #This will include the shader files inside the compiled binary
QT4_ADD_RESOURCES(COMMON_RESOURCES_RCC ../common/example.qrc) QT5_ADD_RESOURCES(COMMON_RESOURCES_RCC ../common/example.qrc)
QT4_ADD_RESOURCES(OPENGLEXAMPLE_RESOURCES_RCC openglexample.qrc) QT5_ADD_RESOURCES(OPENGL_EXAMPLE_RESOURCES_RCC openglexample.qrc)
# Put the resources in a seperate folder in Visual Studio # Put the resources in a seperate folder in Visual Studio
SOURCE_GROUP("Resource Files" FILES ../common/example.qrc ${COMMON_RESOURCES_RCC} openglexample.qrc ${OPENGLEXAMPLE_RESOURCES_RCC}) SOURCE_GROUP("Resource Files" FILES ../common/example.qrc ${COMMON_RESOURCES_RCC})
#Build #Build
ADD_EXECUTABLE(OpenGLExample ${SRC_FILES} ${COMMON_RESOURCES_RCC} ${OPENGLEXAMPLE_RESOURCES_RCC}) ADD_EXECUTABLE(OpenGLExample ${SRC_FILES} ${COMMON_RESOURCES_RCC} ${OPENGL_EXAMPLE_RESOURCES_RCC})
IF(MSVC) IF(MSVC)
SET_TARGET_PROPERTIES(OpenGLExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") SET_TARGET_PROPERTIES(OpenGLExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127")
ENDIF(MSVC) ENDIF(MSVC)
TARGET_LINK_LIBRARIES(OpenGLExample glew ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}) TARGET_LINK_LIBRARIES(OpenGLExample glew Qt5::OpenGL ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY})
SET_PROPERTY(TARGET OpenGLExample PROPERTY FOLDER "Examples") SET_PROPERTY(TARGET OpenGLExample PROPERTY FOLDER "Examples")
#Install - Only install the example in Windows #Install - Only install the example in Windows
@ -66,4 +77,11 @@ IF(WIN32)
ARCHIVE DESTINATION Examples/OpenGL/lib ARCHIVE DESTINATION Examples/OpenGL/lib
COMPONENT example COMPONENT example
) )
#.dlls should be installed in shared builds.
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../release/PolyVoxCore.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Release)
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../release/PolyVoxUtil.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Release)
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../debug/PolyVoxCore.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Debug)
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../debug/PolyVoxUtil.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Debug)
ENDIF(WIN32) ENDIF(WIN32)

View File

@ -19,8 +19,6 @@
# 3. This notice may not be removed or altered from any source # 3. This notice may not be removed or altered from any source
# distribution. # distribution.
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(PagingExample) PROJECT(PagingExample)
#Projects source files #Projects source files
@ -32,19 +30,24 @@ SET(SRC_FILES
#Projects headers files #Projects headers files
SET(INC_FILES SET(INC_FILES
OpenGLWidget.h ../common/OpenGLWidget.h
Perlin.h Perlin.h
) )
add_definitions(-DGLEW_STATIC) 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) FIND_PACKAGE(OpenGL REQUIRED)
#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) #Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxHeaders_SOURCE_DIR} ${GLEW_SOURCE_DIR}) INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxHeaders_SOURCE_DIR} ${GLEW_SOURCE_DIR})
#This will include the shader files inside the compiled binary #This will include the shader files inside the compiled binary
QT4_ADD_RESOURCES(COMMON_RESOURCES_RCC ../common/example.qrc) QT5_ADD_RESOURCES(COMMON_RESOURCES_RCC ../common/example.qrc)
# Put the resources in a seperate folder in Visual Studio # Put the resources in a seperate folder in Visual Studio
SOURCE_GROUP("Resource Files" FILES ../common/example.qrc ${COMMON_RESOURCES_RCC}) SOURCE_GROUP("Resource Files" FILES ../common/example.qrc ${COMMON_RESOURCES_RCC})
@ -54,12 +57,9 @@ ADD_EXECUTABLE(PagingExample ${SRC_FILES} ${COMMON_RESOURCES_RCC})
IF(MSVC) IF(MSVC)
SET_TARGET_PROPERTIES(PagingExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") SET_TARGET_PROPERTIES(PagingExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127")
ENDIF(MSVC) ENDIF(MSVC)
TARGET_LINK_LIBRARIES(PagingExample glew ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}) TARGET_LINK_LIBRARIES(PagingExample glew Qt5::OpenGL ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY})
SET_PROPERTY(TARGET PagingExample PROPERTY FOLDER "Examples") SET_PROPERTY(TARGET PagingExample PROPERTY FOLDER "Examples")
configure_file(../common/example.vert example.vert COPYONLY)
configure_file(../common/example.frag example.frag COPYONLY)
#Install - Only install the example in Windows #Install - Only install the example in Windows
IF(WIN32) IF(WIN32)
INSTALL(TARGETS PagingExample INSTALL(TARGETS PagingExample
@ -68,4 +68,11 @@ IF(WIN32)
ARCHIVE DESTINATION Examples/OpenGL/lib ARCHIVE DESTINATION Examples/OpenGL/lib
COMPONENT example COMPONENT example
) )
#.dlls should be installed in shared builds.
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../release/PolyVoxCore.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Release)
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../release/PolyVoxUtil.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Release)
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../debug/PolyVoxCore.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Debug)
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../debug/PolyVoxUtil.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Debug)
ENDIF(WIN32) ENDIF(WIN32)

View File

@ -19,8 +19,6 @@
# 3. This notice may not be removed or altered from any source # 3. This notice may not be removed or altered from any source
# distribution. # distribution.
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(SmoothLODExample) PROJECT(SmoothLODExample)
#Projects source files #Projects source files
@ -31,33 +29,35 @@ SET(SRC_FILES
#Projects headers files #Projects headers files
SET(INC_FILES SET(INC_FILES
OpenGLWidget.h ../common/OpenGLWidget.h
) )
add_definitions(-DGLEW_STATIC) 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) FIND_PACKAGE(OpenGL REQUIRED)
#Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location) #Tell CMake the paths for OpenGL and for PolyVox (which is just relative to our current location)
INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxHeaders_SOURCE_DIR} ${GLEW_SOURCE_DIR}) INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR} ${PolyVoxHeaders_SOURCE_DIR} ${GLEW_SOURCE_DIR})
#This will include the shader files inside the compiled binary #This will include the shader files inside the compiled binary
QT4_ADD_RESOURCES(COMMON_RESOURCES_RCC ../common/example.qrc) QT5_ADD_RESOURCES(COMMON_RESOURCES_RCC ../common/example.qrc)
# Put the resources in a seperate folder in Visual Studio # Put the resources in a seperate folder in Visual Studio
SOURCE_GROUP("Resource Files" FILES ../common/example.qrc ${COMMON_RESOURCES_RCC}) SOURCE_GROUP("Resource Files" FILES ../common/example.qrc ${COMMON_RESOURCES_RCC})
#Build #Build
ADD_EXECUTABLE(SmoothLODExample ${SRC_FILES} ${COMMON_RESOURCES_RCC}) ADD_EXECUTABLE(SmoothLODExample ${SRC_FILES})
IF(MSVC) IF(MSVC)
SET_TARGET_PROPERTIES(SmoothLODExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") #All warnings SET_TARGET_PROPERTIES(SmoothLODExample PROPERTIES COMPILE_FLAGS "/W4 /wd4127") #All warnings
ENDIF(MSVC) ENDIF(MSVC)
TARGET_LINK_LIBRARIES(SmoothLODExample glew ${QT_LIBRARIES} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}) TARGET_LINK_LIBRARIES(SmoothLODExample glew Qt5::OpenGL ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY})
SET_PROPERTY(TARGET SmoothLODExample PROPERTY FOLDER "Examples") SET_PROPERTY(TARGET SmoothLODExample PROPERTY FOLDER "Examples")
configure_file(../common/example.vert example.vert COPYONLY)
configure_file(../common/example.frag example.frag COPYONLY)
#Install - Only install the example in Windows #Install - Only install the example in Windows
IF(WIN32) IF(WIN32)
INSTALL(TARGETS SmoothLODExample INSTALL(TARGETS SmoothLODExample
@ -66,4 +66,11 @@ IF(WIN32)
ARCHIVE DESTINATION Examples/OpenGL/lib ARCHIVE DESTINATION Examples/OpenGL/lib
COMPONENT example COMPONENT example
) )
#.dlls should be installed in shared builds.
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../release/PolyVoxCore.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Release)
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../release/PolyVoxUtil.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Release)
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../debug/PolyVoxCore.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Debug)
#INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/../../debug/PolyVoxUtil.dll DESTINATION Examples/OpenGL/bin CONFIGURATIONS Debug)
ENDIF(WIN32) ENDIF(WIN32)

View File

@ -109,7 +109,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_D
#Build #Build
# Although we don't build anything for PolyVox, we still add this custom target (which # Although we don't build anything for PolyVox, we still add this custom target (which
# doesn't do anything) so that we can browse the source code from within Visual Studio. # doesn't do anything) so that we can browse the source code from within Visual Studio.
ADD_CUSTOM_TARGET(PolyVoxCore SOURCES ${CORE_INC_FILES}) ADD_CUSTOM_TARGET(PolyVoxHeaders SOURCES ${CORE_INC_FILES})
#Install the core header files, including the ones in the Impl subfolder. #Install the core header files, including the ones in the Impl subfolder.
INSTALL(DIRECTORY PolyVox/ DESTINATION include/PolyVox COMPONENT development PATTERN "*.git*" EXCLUDE) INSTALL(DIRECTORY PolyVox/ DESTINATION include/PolyVox COMPONENT development PATTERN "*.git*" EXCLUDE)

View File

@ -24,11 +24,14 @@
# #
# Also sets LATEST_TEST to point to the output executable of the test for easy # Also sets LATEST_TEST to point to the output executable of the test for easy
# ADD_TEST()ing # 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 UNSET(test_moc_SRCS) #clear out the MOCs from previous tests
QT4_WRAP_CPP(test_moc_SRCS ${headerfile})
ADD_EXECUTABLE(${executablename} ${sourcefile} ${test_moc_SRCS}) ADD_EXECUTABLE(${executablename} ${sourcefile} ${test_moc_SRCS})
TARGET_LINK_LIBRARIES(${executablename} ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY}) TARGET_LINK_LIBRARIES(${executablename} Qt5::Test)
#HACK. This is needed since everything is built in the base dir in Windows. As of 2.8 we should change this. #HACK. This is needed since everything is built in the base dir in Windows. As of 2.8 we should change this.
IF(WIN32) IF(WIN32)
SET(LATEST_TEST ${EXECUTABLE_OUTPUT_PATH}/${executablename}) SET(LATEST_TEST ${EXECUTABLE_OUTPUT_PATH}/${executablename})
@ -45,22 +48,18 @@ MACRO(CREATE_TEST headerfile sourcefile executablename)
ENDMACRO(CREATE_TEST) ENDMACRO(CREATE_TEST)
INCLUDE_DIRECTORIES(${PolyVoxHeaders_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) INCLUDE_DIRECTORIES(${PolyVoxHeaders_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
REMOVE_DEFINITIONS(-DQT_GUI_LIB) #Make sure the tests don't link to the QtGui #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. # Test Template. Copy and paste this template for consistant naming.
# # ClassName tests # # ClassName tests
# CREATE_TEST(TestClassName.h TestClassName.cpp TestClassName) # CREATE_TEST(TestClassName.cpp TestClassName)
# ADD_TEST(ClassNameFeature1Test ${LATEST_TEST} testFeature1) # ADD_TEST(ClassNameFeature1Test ${LATEST_TEST} testFeature1)
# ADD_TEST(ClassNameFeature2Test ${LATEST_TEST} testFeature2) # ADD_TEST(ClassNameFeature2Test ${LATEST_TEST} testFeature2)
# Python tests # Python tests
IF(BUILD_BINDINGS) IF(BUILD_BINDINGS)
FIND_PACKAGE(PythonInterp 3) FIND_PACKAGE(PythonInterp 3)
IF(CMAKE_VERSION VERSION_LESS "2.8.6") set_package_properties(PythonInterp PROPERTIES URL http://www.python.org DESCRIPTION "Python Interpereter" TYPE OPTIONAL PURPOSE "Running the Python tests")
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) IF(PYTHONINTERP_FOUND)
ADD_TEST(PythonSurfaceExtractorTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/TestSurfaceExtractor.py) ADD_TEST(PythonSurfaceExtractorTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/TestSurfaceExtractor.py)
ADD_TEST(PythonRaycastTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/TestRaycast.py) ADD_TEST(PythonRaycastTest ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/TestRaycast.py)
@ -68,38 +67,38 @@ IF(BUILD_BINDINGS)
ENDIF() ENDIF()
# AmbientOcclusionGenerator tests # AmbientOcclusionGenerator tests
CREATE_TEST(TestAmbientOcclusionGenerator.h TestAmbientOcclusionGenerator.cpp TestAmbientOcclusionGenerator) CREATE_TEST(TestAmbientOcclusionGenerator.cpp TestAmbientOcclusionGenerator)
# Array tests # Array tests
CREATE_TEST(TestArray.h TestArray.cpp TestArray) CREATE_TEST(TestArray.cpp TestArray)
# AStarPathfinder tests # 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 # Low pass filter tests
CREATE_TEST(TestLowPassFilter.h TestLowPassFilter.cpp TestLowPassFilter) CREATE_TEST(TestLowPassFilter.cpp TestLowPassFilter)
# Material tests # Material tests
CREATE_TEST(testmaterial.h testmaterial.cpp testmaterial) CREATE_TEST(testmaterial.cpp testmaterial)
# Raycast tests # Raycast tests
CREATE_TEST(TestRaycast.h TestRaycast.cpp TestRaycast) CREATE_TEST(TestRaycast.cpp TestRaycast)
# Picking tests # Picking tests
CREATE_TEST(TestPicking.h TestPicking.cpp TestPicking) CREATE_TEST(TestPicking.cpp TestPicking)
# Region tests # 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 #Vector tests
CREATE_TEST(testvector.h testvector.cpp testvector) CREATE_TEST(testvector.cpp testvector)
# Volume tests # Volume tests
CREATE_TEST(testvolume.h testvolume.cpp testvolume) CREATE_TEST(testvolume.cpp testvolume)
# Volume subclass tests # Volume subclass tests
CREATE_TEST(TestVolumeSubclass.h TestVolumeSubclass.cpp TestVolumeSubclass) CREATE_TEST(TestVolumeSubclass.cpp TestVolumeSubclass)