Remove large resources. (#16)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
## 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 ##
|
||||
## All Content (c) 2025 Shaun Reed, all rights reserved ##
|
||||
################################################################################
|
||||
cmake_minimum_required(VERSION 3.23)
|
||||
|
||||
@@ -56,7 +56,7 @@ 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)
|
||||
if(NOT TARGET Qtk::qtk)
|
||||
find_package(Qtk 0.2 REQUIRED)
|
||||
endif()
|
||||
|
||||
@@ -77,20 +77,27 @@ configure_file(
|
||||
|
||||
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_link_libraries(qtk_example PUBLIC Qtk::qtk)
|
||||
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)
|
||||
# qt_generate_deploy_app_script supports Windows and OSX in QtCore >= 6.3.
|
||||
# qt_generate_deploy_app_script is supported on Linux in QtCore >= 6.5.0.
|
||||
if((Qt6_VERSION VERSION_GREATER_EQUAL "6.3.0" AND (WIN32 OR APPLE))
|
||||
OR Qt6_VERSION VERSION_GREATER_EQUAL "6.5.0")
|
||||
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)
|
||||
elseif(NOT Qtk_IS_TOP_LEVEL)
|
||||
message(WARNING "[Qtk] Installation is only supported on Qt >=6.5.\n")
|
||||
endif()
|
||||
@@ -11,26 +11,21 @@
|
||||
|
||||
using namespace Qtk;
|
||||
|
||||
ExampleScene::ExampleScene(Qtk::Scene * scene) : Qtk::SceneInterface(scene) {
|
||||
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() {}
|
||||
ExampleScene::~ExampleScene() = default;
|
||||
|
||||
void ExampleScene::init() {
|
||||
auto skybox = new Qtk::Skybox("Skybox");
|
||||
setSkybox(skybox);
|
||||
|
||||
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);
|
||||
void ExampleScene::init()
|
||||
{
|
||||
setSkybox(new Qtk::Skybox);
|
||||
|
||||
auto mesh = addObject(
|
||||
new Qtk::MeshRenderer("rightTriangle", Triangle(QTK_DRAW_ARRAYS)));
|
||||
new Qtk::MeshRenderer("rightTriangle", Triangle(QTK_DRAW_ELEMENTS)));
|
||||
mesh->getTransform().setTranslation(-5.0f, 0.0f, -2.0f);
|
||||
|
||||
// QTK_DRAW_ARRAYS is the default for generic shapes in qtk/shape.h
|
||||
@@ -56,11 +51,20 @@ void ExampleScene::init() {
|
||||
mesh->setColor(GREEN);
|
||||
}
|
||||
|
||||
void ExampleScene::draw() {
|
||||
void ExampleScene::draw()
|
||||
{
|
||||
// The base class method _must_ be called first, before additional logic.
|
||||
Scene::draw();
|
||||
|
||||
// No additional custom draw logic for this example.
|
||||
// QtkScene in Qtk desktop application is an example using custom draw logic.
|
||||
}
|
||||
|
||||
void ExampleScene::update() {
|
||||
void ExampleScene::update()
|
||||
{
|
||||
auto top_triangle = MeshRenderer::getInstance("topTriangle");
|
||||
auto bottom_triangle = MeshRenderer::getInstance("bottomTriangle");
|
||||
|
||||
// Pitch forward and roll sideways
|
||||
MeshRenderer::getInstance("leftTriangle")
|
||||
->getTransform()
|
||||
@@ -69,27 +73,20 @@ void ExampleScene::update() {
|
||||
->getTransform()
|
||||
.rotate(0.75f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
// Make the top and bottom triangles slide left-to-right.
|
||||
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) {
|
||||
float posX = top_triangle->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);
|
||||
|
||||
top_triangle->getTransform().translate(translateX, 0.0f, 0.0f);
|
||||
bottom_triangle->getTransform().translate(-translateX, 0.0f, 0.0f);
|
||||
|
||||
// Apply some rotation to the triangles as they move left-to-right.
|
||||
top_triangle->getTransform().rotate(0.75f, 0.2f, 0.0f, 0.4f);
|
||||
bottom_triangle->getTransform().rotate(0.75f, 0.0f, 0.2f, 0.4f);
|
||||
|
||||
MeshRenderer::getInstance("centerCube")
|
||||
->getTransform()
|
||||
|
||||
@@ -11,16 +11,30 @@
|
||||
|
||||
#include <qtk/scene.h>
|
||||
|
||||
class ExampleScene : public Qtk::SceneInterface {
|
||||
class ExampleScene : public Qtk::Scene
|
||||
{
|
||||
public:
|
||||
ExampleScene(Qtk::Scene * scene);
|
||||
explicit ExampleScene();
|
||||
|
||||
~ExampleScene();
|
||||
|
||||
/**
|
||||
* Override the initialization logic for the scene.
|
||||
* This method should up the scene's objects, skybox, etc.
|
||||
*/
|
||||
void init() override;
|
||||
|
||||
/**
|
||||
* Optionally override the draw method for the scene.
|
||||
*
|
||||
* This is just here for example, it should be omitted entirely if we don't
|
||||
* want to provide a custom implementation for the ExampleScene.
|
||||
*/
|
||||
void draw() override;
|
||||
|
||||
/**
|
||||
* Update objects in the scene for translation or rotation.
|
||||
*/
|
||||
void update() override;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
#include "examplewidget.h"
|
||||
|
||||
ExampleWidget::ExampleWidget(QWidget * parent) :
|
||||
QOpenGLWidget(parent), mScene(new ExampleScene(new Qtk::SceneEmpty)) {
|
||||
QOpenGLWidget(parent), mScene(new ExampleScene)
|
||||
{
|
||||
// NOTE: The decorator pattern is used to save / load scenes in Qtk currently.
|
||||
// The initializer above sets mScene to the concrete decorator ExampleScene.
|
||||
// Qtk::SceneEmpty provides an empty scene as the concrete component.
|
||||
@@ -27,7 +28,8 @@ ExampleWidget::ExampleWidget(QWidget * parent) :
|
||||
setFocusPolicy(Qt::ClickFocus);
|
||||
}
|
||||
|
||||
void ExampleWidget::initializeGL() {
|
||||
void ExampleWidget::initializeGL()
|
||||
{
|
||||
initializeOpenGLFunctions();
|
||||
connect(this, SIGNAL(frameSwapped()), this, SLOT(update()));
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
@@ -40,18 +42,21 @@ void ExampleWidget::initializeGL() {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void ExampleWidget::resizeGL(int width, int height) {
|
||||
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() {
|
||||
void ExampleWidget::paintGL()
|
||||
{
|
||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
mScene->draw();
|
||||
}
|
||||
|
||||
void ExampleWidget::update() {
|
||||
void ExampleWidget::update()
|
||||
{
|
||||
mScene->update();
|
||||
QWidget::update();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
|
||||
#include "examplescene.h"
|
||||
|
||||
class ExampleWidget : public QOpenGLWidget, protected QOpenGLFunctions {
|
||||
class ExampleWidget : public QOpenGLWidget, protected QOpenGLFunctions
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
|
||||
#include "examplewidget.h"
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
auto window = new QMainWindow;
|
||||
|
||||
Reference in New Issue
Block a user