CMake packaging updates

This commit is contained in:
2023-01-14 16:33:06 -05:00
parent 4bc0ae22c6
commit cf433ad7fc
18 changed files with 243 additions and 119 deletions

View File

@@ -0,0 +1,67 @@
################################################################################
## Example client project using qtk ##
## ##
## Author: Shaun Reed | Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ##
## All Content (c) 2023 Shaun Reed, all rights reserved ##
################################################################################
cmake_minimum_required(VERSION 3.23)
################################################################################
# Constants
################################################################################
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/wd4131 /wd4127)
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")
# If you did not install Qt6 on a system path, point cmake to installation.
set(
QT_INSTALL_DIR
"/home/kapper/Code/Clones/Qt/6.3.1/gcc_64/"
CACHE PATH "Path to Qt6 install"
)
################################################################################
# Project
################################################################################
project(
#[[NAME]] QtkClient
VERSION 0.1
DESCRIPTION "An example project using Qtk"
LANGUAGES CXX C
)
list(APPEND CMAKE_PREFIX_PATH "${QTK_PATH}")
list(APPEND CMAKE_PREFIX_PATH "${QT_INSTALL_DIR}")
find_package(Qtk 0.2 REQUIRED)
# Print all QTK variables
get_cmake_property(VAR_NAMES VARIABLES)
list(FILTER VAR_NAMES INCLUDE REGEX "^Q[tT][kK]_.*$")
list(SORT VAR_NAMES)
foreach(VAR_NAME ${VAR_NAMES})
message(STATUS "[Qtk] ${VAR_NAME}=${${VAR_NAME}}")
endforeach()
find_package(Qt6 COMPONENTS Core Widgets OpenGLWidgets REQUIRED)
set(
EXAMPLE_SOURCES
main.cpp
examplescene.cpp examplescene.h
examplewidget.cpp examplewidget.h
)
add_executable(example ${EXAMPLE_SOURCES})
target_link_libraries(example PUBLIC Qt6::Widgets Qt6::OpenGLWidgets Qt6::Core)
target_link_libraries(example PUBLIC Qtk::qtk-library)

68
example-app/README.md Normal file
View File

@@ -0,0 +1,68 @@
This is an example application that is using the Qtk API to create custom Qt
OpenGL widgets. This is very similar to `QtkWidget` in the Qtk desktop
application, but could be modified for different uses if needed.
You can import your own models within `examplescene.cpp`, inside the
`ExampleScene::init()` function. Rotations and translations
are applied in `ExampleScene::update()`.
The syntax for adding shapes and models is seen in the example below.
This would result in a scene with a red cube and a miniature spartan model placed on top.
```C++
void ExampleScene::init() {
// Add a skybox to the scene using default cube map images and settings.
setSkybox(new Qtk::Skybox("Skybox"));
/* Create a red cube with a mini master chief on top. */
auto myCube = new MeshRenderer("My cube", Cube(Qtk::QTK_DRAW_ELEMENTS));
myCube->setColor(RED);
mMeshes.push_back(myCube);
auto mySpartan = new Model("My spartan", "/path/to/spartan/spartan.obj");
mySpartan->getTransform().setTranslation(0.0f, 0.5f, 0.0f);
mySpartan->getTransform().setScale(0.5f);
mModels.push_back(mySpartan);
}
```
If we want to make our spartan spin, we need to apply rotation in `update`
```C++
void ExampleScene::update() {
auto mySpartan = Model::getInstance("My spartan");
mySpartan->getTransform().rotate(0.75f, 0.0f, 1.0f, 0.0f);
auto myCube = MeshRenderer::getInstance("My cube");
myCube->getTransform().rotate(-0.75f, 0.0f, 1.0f, 0.0f);
}
```
Other examples can be found in the source files for this example project.
## Build Instructions
Currently, this application requires manual build and installation of Qtk.
In the future, once a release is published, I will be able to use `FetchContent`
or similar cmake functionality to remove this requirement.
For Qtk build instructions, see the README in the root of this repository.
```bash
cmake -S /path/to/qtk/example-app/ -B /path/to/qtk/example-app/build
cmake --build /path/to/qtk/example-app/build
```
If Qtk was not installed system-wide, we can set `QTK_PATH` to point to the 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
```
After this, we can run the example application -
```bash
./path/to/qtk/example-app/build/bin/example
```

View File

@@ -0,0 +1,94 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
## About: Example Qtk scene ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################*/
#include "examplescene.h"
using namespace Qtk;
ExampleScene::ExampleScene() {
setSceneName("Example Scene");
getCamera().getTransform().setTranslation(-8.0f, 0.0f, 10.0f);
getCamera().getTransform().setRotation(-5.0f, 0.0f, 1.0f, 0.0f);
}
ExampleScene::~ExampleScene() {}
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");
addObject(spartan);
auto mesh = addObject(
new Qtk::MeshRenderer("rightTriangle", Triangle(QTK_DRAW_ARRAYS)));
mesh->getTransform().setTranslation(-5.0f, 0.0f, -2.0f);
// QTK_DRAW_ARRAYS is the default for generic shapes in qtk/shape.h
addObject(new Qtk::MeshRenderer("centerCube", Cube(QTK_DRAW_ARRAYS)))
->getTransform()
.setTranslation(-7.0f, 0.0f, -2.0f);
mesh = addObject(
new Qtk::MeshRenderer("leftTriangle", Triangle(QTK_DRAW_ELEMENTS)));
mesh->getTransform().setTranslation(-9.0f, 0.0f, -2.0f);
mesh->setDrawType(GL_LINE_LOOP);
mesh = addObject(
new Qtk::MeshRenderer("topTriangle", Triangle(QTK_DRAW_ELEMENTS)));
mesh->getTransform().setTranslation(-7.0f, 2.0f, -2.0f);
mesh->getTransform().scale(0.25f);
mesh = addObject(
new Qtk::MeshRenderer("bottomTriangle", Triangle(QTK_DRAW_ELEMENTS)));
mesh->getTransform().setTranslation(-7.0f, -2.0f, -2.0f);
mesh->getTransform().scale(0.25f);
mesh->setDrawType(GL_LINE_LOOP);
mesh->setColor(GREEN);
}
void ExampleScene::draw() {
Scene::draw();
}
void ExampleScene::update() {
// Pitch forward and roll sideways
MeshRenderer::getInstance("leftTriangle")
->getTransform()
.rotate(0.75f, 1.0f, 0.0f, 0.0f);
MeshRenderer::getInstance("rightTriangle")
->getTransform()
.rotate(0.75f, 0.0f, 0.0f, 1.0f);
static float translateX = 0.025f;
float limit = -9.0f; // Origin position.x - 2.0f
float posX = MeshRenderer::getInstance("topTriangle")
->getTransform()
.getTranslation()
.x();
if(posX < limit || posX > limit + 4.0f) {
translateX = -translateX;
}
MeshRenderer::getInstance("topTriangle")
->getTransform()
.translate(translateX, 0.0f, 0.0f);
MeshRenderer::getInstance("bottomTriangle")
->getTransform()
.translate(-translateX, 0.0f, 0.0f);
MeshRenderer::getInstance("topTriangle")
->getTransform()
.rotate(0.75f, 0.2f, 0.0f, 0.4f);
MeshRenderer::getInstance("bottomTriangle")
->getTransform()
.rotate(0.75f, 0.0f, 0.2f, 0.4f);
MeshRenderer::getInstance("centerCube")
->getTransform()
.rotate(0.75f, 0.2f, 0.4f, 0.6f);
}

View File

@@ -0,0 +1,27 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
## About: Example Qtk scene ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################*/
#ifndef QTK_EXAMPLE_SCENE_H
#define QTK_EXAMPLE_SCENE_H
#include <qtk/scene.h>
class ExampleScene : public Qtk::Scene {
public:
ExampleScene();
~ExampleScene();
void init() override;
void draw() override;
void update() override;
};
#endif // QTK_EXAMPLE_SCENE_H

View File

@@ -0,0 +1,52 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
## About: Example Qtk widget ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################*/
#include <qtk/scene.h>
#include "examplewidget.h"
ExampleWidget::ExampleWidget(QWidget * parent) :
QOpenGLWidget(parent), mScene(new ExampleScene) {
QSurfaceFormat format;
format.setRenderableType(QSurfaceFormat::OpenGL);
format.setProfile(QSurfaceFormat::CoreProfile);
format.setVersion(4, 6);
format.setSamples(4);
format.setDepthBufferSize(16);
setFormat(format);
setFocusPolicy(Qt::ClickFocus);
}
void ExampleWidget::initializeGL() {
initializeOpenGLFunctions();
connect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
glEnable(GL_MULTISAMPLE);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LEQUAL);
glDepthRange(0.1f, 1.0f);
glClearDepth(1.0f);
glClearColor(0.0f, 0.25f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void ExampleWidget::resizeGL(int width, int height) {
Qtk::Scene::getProjectionMatrix().setToIdentity();
Qtk::Scene::getProjectionMatrix().perspective(
45.0f, float(width) / float(height), 0.1f, 1000.0f);
}
void ExampleWidget::paintGL() {
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
mScene->draw();
}
void ExampleWidget::update() {
mScene->update();
QWidget::update();
}

View File

@@ -0,0 +1,38 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
## About: Example Qtk widget ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################*/
#ifndef QTKCLIENT_EXAMPLEWIDGET_H
#define QTKCLIENT_EXAMPLEWIDGET_H
#include <QOpenGLFunctions>
#include <QOpenGLWidget>
#include "examplescene.h"
class ExampleWidget : public QOpenGLWidget, protected QOpenGLFunctions {
Q_OBJECT;
public:
explicit ExampleWidget(QWidget * parent = nullptr);
~ExampleWidget() = default;
void initializeGL() override;
void resizeGL(int width, int height) override;
void paintGL() override;
protected slots:
void update();
private:
ExampleScene * mScene;
};
#endif // QTKCLIENT_EXAMPLEWIDGET_H

22
example-app/main.cpp Normal file
View File

@@ -0,0 +1,22 @@
/*##############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2023 Shaun Reed, all rights reserved ##
## About: Example Qt desktop application using Qtk ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
##############################################################################*/
#include <QApplication>
#include <QMainWindow>
#include "examplewidget.h"
int main(int argc, char * argv[]) {
QApplication app(argc, argv);
auto window = new QMainWindow;
window->setCentralWidget(new ExampleWidget);
window->show();
app.exec();
}