Drag and drop model loading (#14)
This commit was merged in pull request #14.
This commit is contained in:
@@ -22,7 +22,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
endif()
|
||||
|
||||
# If you did not install Qtk on a system path, point cmake to installation.
|
||||
set(QTK_PATH /usr/local CACHE PATH "Path to installation of Qtk")
|
||||
set(
|
||||
QTK_PATH ../build/install/lib/cmake/Qtk
|
||||
CACHE PATH "Path to installation of Qtk"
|
||||
FORCE
|
||||
)
|
||||
|
||||
# If you did not install Qt6 on a system path, point cmake to installation.
|
||||
set(QT_INSTALL_DIR "$ENV{HOME}/Qt/6.5.0/gcc_64/" CACHE PATH "Path to Qt6")
|
||||
@@ -40,12 +44,6 @@ project(
|
||||
list(APPEND CMAKE_PREFIX_PATH "${QTK_PATH}")
|
||||
list(APPEND CMAKE_PREFIX_PATH "${QT_INSTALL_DIR}")
|
||||
|
||||
# Allow add_subdirectory on this project to use target ALIAS if available.
|
||||
# If this example project is opened standalone we will use find_package.
|
||||
if(NOT TARGET Qtk::qtk_library)
|
||||
find_package(Qtk 0.2 REQUIRED)
|
||||
endif()
|
||||
|
||||
# Print all QTK variables
|
||||
if (NOT Qtk_IS_TOP_LEVEL)
|
||||
get_cmake_property(VAR_NAMES VARIABLES)
|
||||
@@ -56,6 +54,12 @@ if (NOT Qtk_IS_TOP_LEVEL)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# Allow add_subdirectory on this project to use target ALIAS if available.
|
||||
# If this example project is opened standalone we will use find_package.
|
||||
if(NOT TARGET Qtk::qtk_library)
|
||||
find_package(Qtk 0.2 REQUIRED)
|
||||
endif()
|
||||
|
||||
find_package(Qt6 COMPONENTS Core Widgets OpenGLWidgets REQUIRED)
|
||||
|
||||
set(
|
||||
@@ -65,6 +69,28 @@ set(
|
||||
examplewidget.cpp examplewidget.h
|
||||
)
|
||||
|
||||
add_executable(example_app ${EXAMPLE_SOURCES})
|
||||
target_link_libraries(example_app PUBLIC Qt6::Widgets Qt6::OpenGLWidgets Qt6::Core)
|
||||
target_link_libraries(example_app PUBLIC Qtk::qtk_library)
|
||||
configure_file(
|
||||
#[[INPUT]] "${CMAKE_CURRENT_SOURCE_DIR}/resources.h.in"
|
||||
#[[OUTPUT]] "${CMAKE_CURRENT_BINARY_DIR}/resources.h"
|
||||
@ONLY
|
||||
)
|
||||
|
||||
qt_add_executable(qtk_example ${EXAMPLE_SOURCES})
|
||||
target_link_libraries(qtk_example PUBLIC Qt6::Widgets Qt6::OpenGLWidgets Qt6::Core)
|
||||
target_link_libraries(qtk_example PUBLIC Qtk::qtk_library)
|
||||
target_include_directories(qtk_example PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
install(
|
||||
TARGETS qtk_example
|
||||
COMPONENT qtk_example
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib/static
|
||||
RUNTIME DESTINATION bin
|
||||
)
|
||||
qt_generate_deploy_app_script(
|
||||
TARGET qtk_example
|
||||
OUTPUT_SCRIPT QTK_EXAMPLE_DEPLOY_SCRIPT
|
||||
NO_UNSUPPORTED_PLATFORM_ERROR
|
||||
)
|
||||
install(SCRIPT ${QTK_EXAMPLE_DEPLOY_SCRIPT} COMPONENT qtk_example)
|
||||
|
||||
@@ -62,11 +62,12 @@ custom installation directory.
|
||||
|
||||
```bash
|
||||
cmake -S /path/to/qtk/example-app/ -B /path/to/qtk/example-app/build -DQTK_PATH=/path/to/qtk/install/
|
||||
cmake --build /path/to/qtk/example-app/build
|
||||
cmake --build /path/to/qtk/example-app/build --target qtk_example -- -j $(nproc)
|
||||
cmake --install build/ --component qtk_example
|
||||
```
|
||||
|
||||
After this, we can run the example application -
|
||||
|
||||
```bash
|
||||
./path/to/qtk/example-app/build/bin/example
|
||||
./path/to/qtk/example-app/build/install/bin/example
|
||||
```
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
##############################################################################*/
|
||||
|
||||
#include "examplescene.h"
|
||||
#include <resources.h>
|
||||
|
||||
using namespace Qtk;
|
||||
|
||||
@@ -22,9 +23,11 @@ void ExampleScene::init() {
|
||||
auto skybox = new Qtk::Skybox("Skybox");
|
||||
setSkybox(skybox);
|
||||
|
||||
auto spartan = new Model(
|
||||
"spartan", "/home/kapper/Code/qtk/resources/models/spartan/spartan.obj");
|
||||
std::string spartanPath = QTK_EXAMPLE_SOURCE_DIR;
|
||||
spartanPath += "/resources/models/spartan/spartan.obj";
|
||||
auto spartan = new Model("spartan", spartanPath.c_str());
|
||||
addObject(spartan);
|
||||
spartan->getTransform().setTranslation(-4.0f, 0.0f, 0.0f);
|
||||
|
||||
auto mesh = addObject(
|
||||
new Qtk::MeshRenderer("rightTriangle", Triangle(QTK_DRAW_ARRAYS)));
|
||||
|
||||
6
example-app/resources.h.in
Normal file
6
example-app/resources.h.in
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef QTK_RESOURCES_H_IN_H
|
||||
#define QTK_RESOURCES_H_IN_H
|
||||
|
||||
#define QTK_EXAMPLE_SOURCE_DIR "@CMAKE_SOURCE_DIR@"
|
||||
|
||||
#endif // QTK_RESOURCES_H_IN_H
|
||||
Reference in New Issue
Block a user