Compare commits
2 Commits
30d5712c07
...
3bed6d2fd3
Author | SHA1 | Date |
---|---|---|
Shaun Reed | 3bed6d2fd3 | |
Shaun Reed | 590ac52dfb |
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "extern/assimp/assimp"]
|
||||||
|
path = extern/assimp/assimp
|
||||||
|
url = https://github.com/assimp/assimp.git
|
|
@ -19,16 +19,25 @@ set(CMAKE_AUTORCC ON)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# Qtk build options
|
||||||
option(QTK_DEBUG "Enable debugger" ON)
|
option(QTK_DEBUG "Enable debugger" ON)
|
||||||
option(BUILD_SHARED_LIBS "Build shared library" ON)
|
option(BUILD_SHARED_LIBS "Build shared library" ON)
|
||||||
option(ASSIMP_NEW_INTERFACE "Use assimp::assimp as target instead of assimp" OFF)
|
option(UPDATE_SUBMODULES "Update external project (assimp) git submodule" ON)
|
||||||
|
|
||||||
|
# Qt options
|
||||||
|
set(QT_DIR "$ENV{HOME}/Code/Clones/Qt/6.3.1/gcc_64/" CACHE PATH "Path to Qt6")
|
||||||
|
|
||||||
|
# Options for bringing your own assimp installation; Otherwise not needed
|
||||||
|
set(ASSIMP_DIR "" CACHE PATH "Path to local installation of assimp")
|
||||||
|
option(ASSIMP_NEW_INTERFACE "Use the assimp::assimp interface (WIN / OSX)" OFF)
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# External Libraries
|
# External Libraries
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
# For CLion builds, point CMAKE_PREFIX_PATH to Qt6 install directory
|
# For CLion builds, point CMAKE_PREFIX_PATH to Qt6 install directory
|
||||||
list(APPEND CMAKE_PREFIX_PATH $ENV{HOME}/Code/Clones/Qt/6.3.1/gcc_64/)
|
# + QtCreator will handle this for you if that is used instead
|
||||||
|
list(APPEND CMAKE_PREFIX_PATH "${QT_DIR}")
|
||||||
|
|
||||||
# Find Qt
|
# Find Qt
|
||||||
find_package(Qt6 COMPONENTS OpenGLWidgets)
|
find_package(Qt6 COMPONENTS OpenGLWidgets)
|
||||||
|
@ -37,11 +46,24 @@ if (NOT Qt6_FOUND)
|
||||||
message(FATAL_ERROR "Specify path to Qt6 with `cmake -DCMAKE_PREFIX_PATH=/path/to/Qt/6.x.x/gcc_64 -S /path/to/qtk -B /path/to/qtk/build && cmake --build /path/to/qtk/build -j $(nprocs)`")
|
message(FATAL_ERROR "Specify path to Qt6 with `cmake -DCMAKE_PREFIX_PATH=/path/to/Qt/6.x.x/gcc_64 -S /path/to/qtk -B /path/to/qtk/build && cmake --build /path/to/qtk/build -j $(nprocs)`")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Find Assimp
|
if (UPDATE_SUBMODULES)
|
||||||
# https://github.com/assimp/assimp/commit/6ac8279977c3a54118551e549d77329497116f66
|
include("${CMAKE_SOURCE_DIR}/cmake/include/git_submodule.cmake")
|
||||||
find_package(assimp REQUIRED)
|
submodule_update(extern/assimp/assimp/)
|
||||||
|
add_subdirectory(extern/assimp/assimp)
|
||||||
|
else()
|
||||||
|
if (ASSIMP_DIR)
|
||||||
|
message(STATUS "Using custom ASSIMP_DIR: ${ASSIMP_DIR}")
|
||||||
|
list(APPEND CMAKE_PREFIX_PATH "${ASSIMP_DIR}")
|
||||||
|
endif()
|
||||||
|
find_package(assimp REQUIRED)
|
||||||
|
if (assimp_FOUND)
|
||||||
|
message(STATUS "Found assimp: ${assimp_DIR}")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Could not find assimp at: ${CMAKE_PREFIX_PATH}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
include(GenerateExportHeader)
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Qtk
|
# Qtk
|
||||||
|
@ -75,6 +97,8 @@ set(SOURCE_FILES
|
||||||
src/texture.cpp
|
src/texture.cpp
|
||||||
src/transform3D.cpp
|
src/transform3D.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
include(GenerateExportHeader)
|
||||||
qt_add_library(qtk-widget STATIC ${PUBLIC_HEADERS} ${SOURCE_FILES})
|
qt_add_library(qtk-widget STATIC ${PUBLIC_HEADERS} ${SOURCE_FILES})
|
||||||
target_include_directories(qtk-widget PRIVATE src/ app/)
|
target_include_directories(qtk-widget PRIVATE src/ app/)
|
||||||
generate_export_header(qtk-widget)
|
generate_export_header(qtk-widget)
|
||||||
|
@ -84,23 +108,12 @@ set_target_properties(qtk-widget PROPERTIES
|
||||||
VERSION ${PROJECT_VERSION}
|
VERSION ${PROJECT_VERSION}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(qtk-widget PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
|
target_link_libraries(qtk-widget PUBLIC Qt6::OpenGLWidgets)
|
||||||
if(BUILD_SHARED_LIBS)
|
|
||||||
target_compile_definitions(qtk-widget PRIVATE QTK_EXPORT PUBLIC QTK_SHARED)
|
if ((UPDATE_SUBMODULES AND NOT ASSIMP_DIR) OR NOT ASSIMP_NEW_INTERFACE)
|
||||||
target_link_libraries(qtk-widget PRIVATE Qt6::OpenGLWidgets)
|
target_link_libraries(qtk-widget PRIVATE assimp)
|
||||||
if(ASSIMP_NEW_INTERFACE)
|
elseif(ASSIMP_NEW_INTERFACE)
|
||||||
target_link_libraries(qtk-widget PUBLIC assimp::assimp)
|
target_link_libraries(qtk-widget PRIVATE assimp::assimp)
|
||||||
else()
|
|
||||||
target_link_libraries(qtk-widget PUBLIC assimp)
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
target_compile_definitions(qtk-widget PUBLIC QTK_STATIC)
|
|
||||||
target_link_libraries(qtk-widget PUBLIC Qt6::OpenGLWidgets)
|
|
||||||
if(ASSIMP_NEW_INTERFACE)
|
|
||||||
target_link_libraries(qtk-widget PUBLIC assimp::assimp)
|
|
||||||
else()
|
|
||||||
target_link_libraries(qtk-widget PUBLIC assimp)
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(QTK_DEBUG)
|
if(QTK_DEBUG)
|
||||||
|
@ -148,19 +161,19 @@ set(QTK_APP_SOURCES app/main.cpp
|
||||||
)
|
)
|
||||||
qt6_add_big_resources(QTK_APP_SOURCES resources.qrc)
|
qt6_add_big_resources(QTK_APP_SOURCES resources.qrc)
|
||||||
|
|
||||||
qt_add_executable(qtk-app ${QTK_APP_SOURCES})
|
qt_add_executable(qtk-main ${QTK_APP_SOURCES})
|
||||||
target_include_directories(qtk-app PRIVATE src/ app/)
|
target_include_directories(qtk-main PRIVATE src/ app/)
|
||||||
|
|
||||||
# Link qtk-app executable to main qtk-widget library
|
# Link qtk-main executable to main qtk-widget library
|
||||||
target_link_libraries(qtk-app PRIVATE Qt6::OpenGLWidgets qtk-widget)
|
target_link_libraries(qtk-main PRIVATE qtk-widget)
|
||||||
|
|
||||||
set_target_properties(qtk-app PROPERTIES
|
set_target_properties(qtk-main PROPERTIES
|
||||||
WIN32_EXECUTABLE TRUE
|
WIN32_EXECUTABLE TRUE
|
||||||
MACOSX_BUNDLE TRUE
|
MACOSX_BUNDLE TRUE
|
||||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||||
)
|
)
|
||||||
install(TARGETS qtk-app
|
install(TARGETS qtk-main
|
||||||
BUNDLE DESTINATION .
|
BUNDLE DESTINATION .
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
)
|
)
|
||||||
|
@ -170,16 +183,16 @@ if(WIN32)
|
||||||
execute_process(COMMAND "${_qt6_qmake_location}" -query QT_INSTALL_PREFIX RESULT_VARIABLE return_code OUTPUT_VARIABLE qt6_install_prefix OUTPUT_STRIP_TRAILING_WHITESPACE)
|
execute_process(COMMAND "${_qt6_qmake_location}" -query QT_INSTALL_PREFIX RESULT_VARIABLE return_code OUTPUT_VARIABLE qt6_install_prefix OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
file(TO_NATIVE_PATH "${qt6_install_prefix}/bin" qt6_install_prefix)
|
file(TO_NATIVE_PATH "${qt6_install_prefix}/bin" qt6_install_prefix)
|
||||||
if(TARGET Qt6::windeployqt)
|
if(TARGET Qt6::windeployqt)
|
||||||
add_custom_command(TARGET qtk-app
|
add_custom_command(TARGET qtk-main
|
||||||
POST_BUILD
|
POST_BUILD
|
||||||
COMMAND set PATH=%PATH%$<SEMICOLON>${qt6_install_prefix}
|
COMMAND set PATH=%PATH%$<SEMICOLON>${qt6_install_prefix}
|
||||||
COMMAND Qt6::windeployqt --dir "${CMAKE_BINARY_DIR}/windeployqt" "$<TARGET_FILE_DIR:qtk-app>/$<TARGET_FILE_NAME:qtk-app>"
|
COMMAND Qt6::windeployqt --dir "${CMAKE_BINARY_DIR}/windeployqt" "$<TARGET_FILE_DIR:qtk-main>/$<TARGET_FILE_NAME:qtk-main>"
|
||||||
)
|
)
|
||||||
install(DIRECTORY "${CMAKE_BINARY_DIR}/windeployqt/" DESTINATION bin)
|
install(DIRECTORY "${CMAKE_BINARY_DIR}/windeployqt/" DESTINATION bin)
|
||||||
endif()
|
endif()
|
||||||
if(MSVC AND TARGET Qt6::qmake)
|
if(MSVC AND TARGET Qt6::qmake)
|
||||||
set(VSUSER_FILE ${CMAKE_CURRENT_BINARY_DIR}/qtk-app.vcxproj.user)
|
set(VSUSER_FILE ${CMAKE_CURRENT_BINARY_DIR}/qtk-main.vcxproj.user)
|
||||||
file(TO_NATIVE_PATH "${assimp_DIR}/bin" assimp_bin)
|
file(TO_NATIVE_PATH "${ASSIMP_INSTALL_DIR}/bin" assimp_bin)
|
||||||
file(WRITE ${VSUSER_FILE} "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
file(WRITE ${VSUSER_FILE} "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
||||||
file(APPEND ${VSUSER_FILE} "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n")
|
file(APPEND ${VSUSER_FILE} "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n")
|
||||||
file(APPEND ${VSUSER_FILE} " <PropertyGroup>\n")
|
file(APPEND ${VSUSER_FILE} " <PropertyGroup>\n")
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<string>Qtk - MainWindow</string>
|
<string>Qtk - MainWindow</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<widget class="Qtk::MainWidget" name="openGLWidget">
|
<widget class="Qtk::MainWidget" name="openGLWidget" native="true">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>10</x>
|
<x>10</x>
|
||||||
|
@ -94,8 +94,8 @@
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>MainWidget</class>
|
<class>Qtk::MainWidget</class>
|
||||||
<extends>QOpenGLWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>mainwidget.h</header>
|
<header>mainwidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
|
|
|
@ -602,11 +602,7 @@ void ExampleScene::init()
|
||||||
|
|
||||||
void ExampleScene::draw()
|
void ExampleScene::draw()
|
||||||
{
|
{
|
||||||
mSkybox->draw();
|
Scene::draw();
|
||||||
|
|
||||||
for (auto & model : mModels) model->draw();
|
|
||||||
|
|
||||||
for (const auto &mesh : mMeshes) mesh->draw();
|
|
||||||
|
|
||||||
mTestPhong->mProgram.bind();
|
mTestPhong->mProgram.bind();
|
||||||
mTestPhong->setUniform("uModelInverseTransposed",
|
mTestPhong->setUniform("uModelInverseTransposed",
|
||||||
|
|
|
@ -17,12 +17,13 @@
|
||||||
|
|
||||||
|
|
||||||
class ExampleScene : public Qtk::Scene {
|
class ExampleScene : public Qtk::Scene {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ExampleScene();
|
ExampleScene();
|
||||||
~ExampleScene();
|
~ExampleScene();
|
||||||
|
|
||||||
virtual void init();
|
virtual void init();
|
||||||
virtual void draw();
|
virtual void draw() override;
|
||||||
virtual void update();
|
virtual void update();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
################################################################################
|
||||||
|
## Author: Shaun Reed | Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ##
|
||||||
|
## ##
|
||||||
|
## CMake function to update git submodules ##
|
||||||
|
################################################################################
|
||||||
|
include_guard()
|
||||||
|
|
||||||
|
find_package(Git)
|
||||||
|
|
||||||
|
# _PATH: Path to git submodule location that we want to update
|
||||||
|
# + submodule_update(extern/assimp)
|
||||||
|
function(submodule_update _PATH)
|
||||||
|
if (NOT UPDATE_SUBMODULES)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT GIT_FOUND)
|
||||||
|
message(FATAL_ERROR "Error: No git executable found")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "${_PATH}")
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${GIT_EXECUTABLE} submodule update --init "${_PATH}"
|
||||||
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||||
|
RESULT_VARIABLE result
|
||||||
|
)
|
||||||
|
|
||||||
|
if (NOT result EQUAL 0)
|
||||||
|
message(FATAL_ERROR "Error: Unable to update git submodule at ${_PATH}")
|
||||||
|
endif()
|
||||||
|
endfunction()
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit bd64cc88dff17f118ecf32ebcbacaf566f6b6449
|
|
@ -20,12 +20,13 @@
|
||||||
namespace Qtk {
|
namespace Qtk {
|
||||||
class Scene : protected QOpenGLFunctions {
|
class Scene : protected QOpenGLFunctions {
|
||||||
friend class MainWidget;
|
friend class MainWidget;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Scene();
|
Scene();
|
||||||
~Scene();
|
~Scene();
|
||||||
|
|
||||||
virtual void init() = 0;
|
virtual void init() = 0;
|
||||||
virtual void draw() = 0;
|
virtual void draw() { privDraw(); };
|
||||||
virtual void update() = 0;
|
virtual void update() = 0;
|
||||||
|
|
||||||
static Camera3D & Camera() { return mCamera;}
|
static Camera3D & Camera() { return mCamera;}
|
||||||
|
|
|
@ -65,7 +65,7 @@ void MainWidget::paintGL()
|
||||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
// Draw the scene first, since it handles drawing our skybox
|
// Draw the scene first, since it handles drawing our skybox
|
||||||
if (mScene != Q_NULLPTR) mScene->privDraw();
|
if (mScene != Q_NULLPTR) mScene->draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::initializeGL()
|
void MainWidget::initializeGL()
|
||||||
|
|
|
@ -15,14 +15,16 @@ using namespace Qtk;
|
||||||
Skybox::Skybox(std::string right, std::string top, std::string front,
|
Skybox::Skybox(std::string right, std::string top, std::string front,
|
||||||
std::string left, std::string bottom, std::string back,
|
std::string left, std::string bottom, std::string back,
|
||||||
const std::string & name)
|
const std::string & name)
|
||||||
: mCubeMap(Texture::initCubeMap(
|
: mVBO(QOpenGLBuffer::VertexBuffer),
|
||||||
QImage(right.c_str()).mirrored(), QImage(top.c_str()),
|
|
||||||
QImage(front.c_str()), QImage(left.c_str()),
|
|
||||||
QImage(bottom.c_str()), QImage(back.c_str()))),
|
|
||||||
mVBO(QOpenGLBuffer::VertexBuffer),
|
|
||||||
mVertices(Cube(QTK_DRAW_ELEMENTS).vertices()),
|
mVertices(Cube(QTK_DRAW_ELEMENTS).vertices()),
|
||||||
mIndices(Cube(QTK_DRAW_ELEMENTS).indices())
|
mIndices(Cube(QTK_DRAW_ELEMENTS).indices())
|
||||||
{ init();}
|
{
|
||||||
|
init();
|
||||||
|
mCubeMap = Texture::initCubeMap(
|
||||||
|
QImage(right.c_str()).mirrored(), QImage(top.c_str()),
|
||||||
|
QImage(front.c_str()), QImage(left.c_str()),
|
||||||
|
QImage(bottom.c_str()), QImage(back.c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
Skybox::Skybox(std::string name)
|
Skybox::Skybox(std::string name)
|
||||||
: Skybox(":/right.png", ":/top.png", ":/front.png",
|
: Skybox(":/right.png", ":/top.png", ":/front.png",
|
||||||
|
@ -87,13 +89,11 @@ void Skybox::init()
|
||||||
mVBO.setUsagePattern(QOpenGLBuffer::StaticDraw);
|
mVBO.setUsagePattern(QOpenGLBuffer::StaticDraw);
|
||||||
mVBO.bind();
|
mVBO.bind();
|
||||||
// Allocate vertex positions into VBO
|
// Allocate vertex positions into VBO
|
||||||
mVBO.allocate(mVertices.data(),
|
mVBO.allocate(mVertices.data(), mVertices.size() * sizeof(mVertices[0]));
|
||||||
mVertices.size() * sizeof(mVertices[0]));
|
|
||||||
|
|
||||||
// Enable attribute array for vertex positions
|
// Enable attribute array for vertex positions
|
||||||
mProgram.enableAttributeArray(0);
|
mProgram.enableAttributeArray(0);
|
||||||
mProgram.setAttributeBuffer(0, GL_FLOAT, 0,
|
mProgram.setAttributeBuffer(0, GL_FLOAT, 0, 3, sizeof(QVector3D));
|
||||||
3, sizeof(QVector3D));
|
|
||||||
// Set shader texture unit to 0
|
// Set shader texture unit to 0
|
||||||
mProgram.setUniformValue("uTexture", 0);
|
mProgram.setUniformValue("uTexture", 0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue