diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 1e97797..bcd0c0f 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -15,10 +15,83 @@ jobs: - os: ubuntu-latest cmake: -DCMAKE_PREFIX_PATH="/home/runner/work/qtk/Qt/6.3.1/gcc_64/" - os: windows-latest - cmake: -DCMAKE_PREFIX_PATH="D:/a/qtk/qtk/Qt/6.3.1/mingw81_64/" + cmake: -DCMAKE_PREFIX_PATH="D:/a/qtk/qtk/Qt/6.3.1/mingw81_64/" -DASSIMP_WARNINGS_AS_ERRORS=OFF - os: macos-latest cmake: -DCMAKE_PREFIX_PATH="/home/runner/work/qtk/Qt/6.3.1/gcc_64/" + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + + - name: Install Qt + uses: jurplel/install-qt-action@v2 + with: + version: '6.3.1' + + - name: Chocolatey Action + if: matrix.os == 'windows-latest' + uses: crazy-max/ghaction-chocolatey@v2.0.0 + with: + args: install pkgconfiglite + + - name: Build Qtk + shell: bash + run: | + cmake -S . -B build/ ${{ matrix.cmake }} && cmake --build build/ \ + --target qtk-main + + + Build-Qtk-Assimp-Targets: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest] + include: + - os: ubuntu-latest + cmake: -DCMAKE_PREFIX_PATH="/home/runner/work/qtk/Qt/6.3.1/gcc_64/" -DQTK_UPDATE_SUBMODULES=OFF + - os: macos-latest + cmake: -DCMAKE_PREFIX_PATH="/home/runner/work/qtk/Qt/6.3.1/gcc_64/" -DASSIMP_NEW_INTERFACE=ON -DQTK_UPDATE_SUBMODULES=OFF + + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + + - name: Install Qt + uses: jurplel/install-qt-action@v2 + with: + version: '6.3.1' + + - name: Install Assimp MacOS + if: matrix.os == 'macos-latest' + shell: bash + run: | + brew install assimp + + - name: Install Assimp Ubuntu + if: matrix.os == 'ubuntu-latest' + shell: bash + run: | + sudo apt install libassimp-dev + + - name: Build Qtk + shell: bash + run: | + cmake -S . -B build/ ${{ matrix.cmake }} && cmake --build build/ \ + --target qtk-main + + Build-Qtk-Static: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + include: + - os: ubuntu-latest + cmake: -DCMAKE_PREFIX_PATH="/home/runner/work/qtk/Qt/6.3.1/gcc_64/" -DQTK_BUILD_SHARED_LIBS=OFF + - os: windows-latest + cmake: -DCMAKE_PREFIX_PATH="D:/a/qtk/qtk/Qt/6.3.1/mingw81_64/" -DQTK_BUILD_SHARED_LIBS=OFF + - os: macos-latest + cmake: -DCMAKE_PREFIX_PATH="/home/runner/work/qtk/Qt/6.3.1/gcc_64/" -DQTK_BUILD_SHARED_LIBS=OFF + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -31,4 +104,5 @@ jobs: - name: Build Qtk shell: bash run: | - cmake -S . -B build/ ${{ matrix.cmake }} && cmake --build build/ + cmake -S . -B build/ ${{ matrix.cmake }} && cmake --build build/ \ + --target qtk-main diff --git a/CMakeLists.txt b/CMakeLists.txt index 31c280b..fab48ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,22 +19,35 @@ set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - add_compile_options(/wd4131 /wd4127) -endif() -message(STATUS "[Qtk]: Compiling with ${CMAKE_CXX_COMPILER_ID}") +#if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") +# add_compile_options(/wd4131 /wd4127) +#endif() +message(STATUS "[Qtk] Compiling with ${CMAKE_CXX_COMPILER_ID}") # Qtk build options option(QTK_DEBUG "Enable debugger" ON) -option(BUILD_SHARED_LIBS "Build shared library" ON) +message(STATUS "[Qtk] Compiling with QTK_DEBUG=${QTK_DEBUG}") +option(QTK_BUILD_SHARED_LIBS "Build shared library" ON) +message( + STATUS + "[Qtk] Compiling with QTK_BUILD_SHARED_LIBS=${QTK_BUILD_SHARED_LIBS}" +) +option(QTK_UPDATE_SUBMODULES "Update external project (assimp) submodule" ON) +message( + STATUS + "[Qtk] Compiling with QTK_UPDATE_SUBMODULES=${QTK_UPDATE_SUBMODULES}" +) # 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 -# + If assimp is available system-wide we can just set UPDATE_SUBMODULES OFF -option(UPDATE_SUBMODULES "Update external project (assimp) git submodule" ON) +# + If assimp is available system-wide we can just set QTK_UPDATE_SUBMODULES OFF option(ASSIMP_NEW_INTERFACE "Use the assimp::assimp interface (WIN / OSX)" OFF) +message( + STATUS + "[Qtk] Compiling with ASSIMP_NEW_INTERFACE=${ASSIMP_NEW_INTERFACE}" +) ################################################################################ # External Libraries @@ -47,15 +60,25 @@ list(APPEND CMAKE_PREFIX_PATH "${QT_DIR}") # Find Qt find_package(Qt6 COMPONENTS OpenGLWidgets) if (NOT Qt6_FOUND) - message(SEND_ERROR "[Qtk] Error: Unable to find Qt6 at CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") - message(FATAL_ERROR "[Qtk] 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( + SEND_ERROR "[Qtk] Error: Unable to find Qt6 at CMAKE_PREFIX_PATH: " + "${CMAKE_PREFIX_PATH}" + ) + message( + FATAL_ERROR + "[Qtk] 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() -if (UPDATE_SUBMODULES) - message(STATUS "[Qtk]: Updating submodules...") +if (QTK_UPDATE_SUBMODULES) + message(STATUS "[Qtk] Updating submodules...") include("${CMAKE_SOURCE_DIR}/cmake/include/git_submodule.cmake") - submodule_update(extern/assimp/assimp/) - add_subdirectory(extern/assimp/assimp) + submodule_update("${CMAKE_CURRENT_SOURCE_DIR}/extern/assimp/assimp/") + add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/extern/assimp/assimp/") +else() + find_package(assimp REQUIRED) endif() @@ -65,7 +88,7 @@ endif() set( PUBLIC_HEADERS - src/mainwidget.h + src/qtkwidget.h src/abstractscene.h src/camera3d.h src/mesh.h @@ -79,7 +102,7 @@ set( set( SOURCE_FILES - src/mainwidget.cpp + src/qtkwidget.cpp src/abstractscene.cpp src/camera3d.cpp src/input.cpp @@ -95,7 +118,12 @@ set( ) include(GenerateExportHeader) -qt_add_library(qtk-widget STATIC ${PUBLIC_HEADERS} ${SOURCE_FILES}) + +if (QTK_BUILD_SHARED_LIBS) + add_library(qtk-widget SHARED ${PUBLIC_HEADERS} ${SOURCE_FILES}) +else() + add_library(qtk-widget STATIC ${PUBLIC_HEADERS} ${SOURCE_FILES}) +endif() target_include_directories(qtk-widget PRIVATE src/ app/) set_target_properties(qtk-widget PROPERTIES @@ -104,15 +132,16 @@ set_target_properties(qtk-widget PROPERTIES ) target_link_libraries(qtk-widget PUBLIC Qt6::OpenGLWidgets) +target_link_libraries(qtk-widget PUBLIC Qt6::Widgets) -if (UPDATE_SUBMODULES OR NOT ASSIMP_NEW_INTERFACE) +if (QTK_UPDATE_SUBMODULES OR NOT ASSIMP_NEW_INTERFACE) target_link_libraries(qtk-widget PUBLIC assimp) elseif(ASSIMP_NEW_INTERFACE) target_link_libraries(qtk-widget PUBLIC assimp::assimp) endif() if(QTK_DEBUG) - message(STATUS "[Qtk]: Building with QTK_DEBUG=${QTK_DEBUG}") + message(STATUS "[Qtk] Building with QTK_DEBUG=${QTK_DEBUG}") target_compile_definitions(qtk-widget PUBLIC QTK_DEBUG) endif() @@ -122,7 +151,6 @@ if(WIN32) target_link_libraries(qtk-widget PUBLIC OpenGL::GL) endif() -generate_export_header(qtk-widget) # Install files install(TARGETS qtk-widget # Associate qtk-widget target with qtk-export @@ -156,8 +184,8 @@ configure_file( # Add our Qt resources.qrc file to our application set(QTK_APP_SOURCES app/main.cpp + app/examplescene.cpp app/examplescene.h app/mainwindow.cpp app/mainwindow.h app/mainwindow.ui - app/scene.cpp app/scene.h app/resourcemanager.h src/qtkresources.h.in ) @@ -167,7 +195,7 @@ qt_add_executable(qtk-main ${QTK_APP_SOURCES}) target_include_directories(qtk-main PRIVATE src/ app/) # Link qtk-main executable to main qtk-widget library -target_link_libraries(qtk-main PRIVATE qtk-widget) +target_link_libraries(qtk-main PUBLIC qtk-widget) set_target_properties(qtk-main PROPERTIES WIN32_EXECUTABLE TRUE @@ -180,6 +208,7 @@ install(TARGETS qtk-main LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) +generate_export_header(qtk-widget) if(WIN32) get_target_property(_qt6_qmake_location Qt6::qmake IMPORTED_LOCATION) execute_process(COMMAND "${_qt6_qmake_location}" -query QT_INSTALL_PREFIX RESULT_VARIABLE return_code OUTPUT_VARIABLE qt6_install_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) diff --git a/README.md b/README.md index e0ba2de..ca762a2 100644 --- a/README.md +++ b/README.md @@ -3,18 +3,18 @@ Practice project for learning about using OpenGL in Qt widget applications. Model loader using [Assimp](https://assimp.org/) within a Qt widget application. -You can import your own models within `mainwdget.cpp`, inside the -`MainWidget::initObjects()` function. I've commented throughout the code there -to explain which model or example I'm modifying. Rotations and translations -happen in `MainWidget::update()`, to get textures loading on models look into -[material files](http://www.paulbourke.net/dataformats/mtl/) and see some -examples in the `resources/models/` directory. For more in-depth examples, see -`scene.h` and `scene.cpp` +You can import your own models within `app/examplescene.cpp`, inside the +`ExampleScene::init()` function. Rotations and translations +happen in `ExampleScene::update()`. -Can be built with cmake manually or using -[Qt Creator](https://github.com/qt-creator/qt-creator). -For the build to be successful, I've found through testing on VMs that the system requires around 6GB of RAM. -This is mostly due to the large .obj files that are built into the project using [Qt Resource System](https://doc.qt.io/qt-6/resources.html) +To get textures loading on models look into [material files](http://www.paulbourke.net/dataformats/mtl/) +and see some examples in the `resources/models/` directory. + + +### Building + +Builds are configured for CLion or [Qt Creator](https://github.com/qt-creator/qt-creator). +Simply open the root `CMakeLists.txt` with either of these editors and configurations will be loaded. This project has been ported to Qt6, which is not yet available in Ubuntu apt repositories. To run this project, you will *need* to install [Qt6 Open Source Binaries](https://www.qt.io/download-qt-installer) for your system. @@ -24,8 +24,21 @@ Once Qt6 is installed, to build and run `qtk` on Ubuntu - ```bash sudo apt update -y && sudo apt install freeglut3-dev libassimp-dev cmake build-essential git git clone https://gitlab.com/shaunrd0/qtk -cmake -DCMAKE_PREFIX_PATH=$HOME/Qt/6.3.1/gcc_64 -S qtk/ -B qtk/build/ && cmake --build qtk/build/ -j $(nprocs) -./qtk/build/qtk +cmake -DCMAKE_PREFIX_PATH=$HOME/Qt/6.3.1/gcc_64 -S qtk/ -B qtk/build/ && cmake --build qtk/build/ -j $(nproc --ignore=2) --target qtk-main +./qtk/build/qtk-main +``` + +By default, the build will initialize Assimp as a git submodule and build from source. +We can turn this off by setting the `-DQTK_UPDATE_SUBMODULES=OFF` flag when running CMake. +This will greatly increase build speed, but we will need to make sure Assimp is available either system-wide or using a custom `CMAKE_PREFIX_PATH`. +Using `-DQTK_UPDATE_SUBMODULES=ON` supports providing assimp on cross-platform builds (Windows / Mac / Linux) and may be easier to configure. + +```bash +sudo apt update -y && sudo apt install freeglut3-dev libassimp-dev cmake build-essential git +git clone https://gitlab.com/shaunrd0/qtk +cmake -DQTK_UPDATE_SUBMODULES=OFF -DCMAKE_PREFIX_PATH=$HOME/Qt/6.3.1/gcc_64 -S qtk/ -B qtk/build/ && cmake --build qtk/build/ -j $(nproc --ignore=2) --target qtk-main +#cmake -DQTK_UPDATE_SUBMODULES=OFF -DCMAKE_PREFIX_PATH=$HOME/Qt/6.3.1/gcc_64;/path/to/assimp/dir -S qtk/ -B qtk/build/ && cmake --build qtk/build/ -j $(nproc --ignore=2) --target qtk-main +./qtk/build/qtk-main ``` You can fly around the scene if you hold the right mouse button and use WASD. @@ -43,8 +56,30 @@ Spartan with normals - ![](resources/spartan-normals.png) -## Model Artists +### QtkWidget in Qt Creator + +The `QtkWidget` class is exported as a shared library for use in Qt Creator's design mode. +We can add more QtkWidgets to view and render the scene from multiple perspectives. +There is still some work to be done here, so there isn't a builtin way to add an additional view within the application. + +![](resources/qtk-views.png) + +After building Qtk, we can drag and drop an `OpenGL Widget` onto the `mainwindow.ui`. +Then right-click the new OpenGLWidget and `Promote To->QtkWidget` to add a second view. + +![](resources/qtk-views-setup.png) + +If we demote or delete all widgets in `mainwindow.ui` and rebuild the project, Qt Creator will drop `QtkWidget` from the list of possible promoted widgets. +Add an `OpenGL Widget` to the UI, right-click it and navigate to `Promote Widget...` and enter the information below. + +![](resources/qtk-reference.png) + +After you fill out the `New Promoted Class` form, click `Add` *and*`Promote`, then rebuild. +After following these steps Qt Creator will list `QtkWidget` as an option to promote `OpenGL Widgets` again. + + +## Model Artists "Alien Hominid" (https://skfb.ly/onStx) by Nwilly_art is licensed under Creative Commons Attribution (http://creativecommons.org/licenses/by/4.0/). @@ -59,4 +94,3 @@ Modified (learnopengl.com) material assignment (Joey de Vries) for easier load i "Terror-bird (NHMW-Geo 2012/0007/0001)" (https://skfb.ly/onAWy) by Natural History Museum Vienna is licensed under Creative Commons Attribution-NonCommercial (http://creativecommons.org/licenses/by-nc/4.0/). "Golden Lion Sitting OBJ Low Poly FREE" (https://skfb.ly/onZAH) by LordSamueliSolo is licensed under Creative Commons Attribution (http://creativecommons.org/licenses/by/4.0/). - diff --git a/app/scene.cpp b/app/examplescene.cpp similarity index 99% rename from app/scene.cpp rename to app/examplescene.cpp index f509769..46ffa5f 100644 --- a/app/scene.cpp +++ b/app/examplescene.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include using namespace Qtk; diff --git a/app/scene.h b/app/examplescene.h similarity index 99% rename from app/scene.h rename to app/examplescene.h index d589694..ea30dba 100644 --- a/app/scene.h +++ b/app/examplescene.h @@ -17,7 +17,6 @@ class ExampleScene : public Qtk::Scene { - public: ExampleScene(); ~ExampleScene(); diff --git a/app/main.cpp b/app/main.cpp index 15f56c9..55312bf 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 713d43e..ea20f46 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -1,13 +1,24 @@ #include -#include +#include +#include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); - mScene = new ExampleScene(); - ui->openGLWidget->setScene(mScene); + // For use in design mode using Qt Creator + // + We can use the `ui` member to access nested widgets by name + for (const auto widget : ui->qWidget->children()) { + auto qtkWidget = dynamic_cast(widget); + if (qtkWidget != nullptr) { + std::string key = qtkWidget->objectName().toStdString(); + if (mScenes[key] == nullptr) { + mScenes[qtkWidget->objectName().toStdString()] = new ExampleScene(); + } + qtkWidget->setScene(mScenes[qtkWidget->objectName().toStdString()]); + } + } setWindowIcon(QIcon("../resources/icon.png")); } diff --git a/app/mainwindow.h b/app/mainwindow.h index 04397bb..0d4b340 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -1,10 +1,12 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H +#include + #include -#include -#include +#include "qtk-widget_export.h" +#include namespace Ui { @@ -21,7 +23,7 @@ public: private: Ui::MainWindow *ui; - Qtk::Scene * mScene; + std::unordered_map mScenes; }; #endif // MAINWINDOW_H diff --git a/app/mainwindow.ui b/app/mainwindow.ui index 938ff7d..3e6b31c 100644 --- a/app/mainwindow.ui +++ b/app/mainwindow.ui @@ -14,15 +14,25 @@ Qtk - MainWindow - + - 10 - 10 - 775 - 550 + 0 + 0 + 801 + 561 + + + + 10 + 10 + 781 + 541 + + + @@ -94,9 +104,9 @@ - Qtk::MainWidget - QWidget -
mainwidget.h
+ Qtk::QtkWidget + QOpenGLWidget +
qtkwidget.h
diff --git a/cmake/include/git_submodule.cmake b/cmake/include/git_submodule.cmake index c3d2b21..26274e2 100644 --- a/cmake/include/git_submodule.cmake +++ b/cmake/include/git_submodule.cmake @@ -10,7 +10,7 @@ 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) + if (NOT QTK_UPDATE_SUBMODULES) return() endif() @@ -19,12 +19,14 @@ function(submodule_update _PATH) endif() execute_process( - COMMAND ${GIT_EXECUTABLE} submodule update --init "${_PATH}" - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" - RESULT_VARIABLE result + COMMAND ${GIT_EXECUTABLE} submodule update --init --force "${_PATH}" + RESULT_VARIABLE result ) if (NOT result EQUAL 0) - message(FATAL_ERROR "[Qtk] Error: Unable to update git submodule at ${_PATH}") + message( + FATAL_ERROR + "[Qtk] Error: Unable to update git submodule at ${_PATH}" + ) endif() endfunction() diff --git a/resources/qtk-reference.png b/resources/qtk-reference.png new file mode 100644 index 0000000..6dc5057 Binary files /dev/null and b/resources/qtk-reference.png differ diff --git a/resources/qtk-views-setup.png b/resources/qtk-views-setup.png new file mode 100644 index 0000000..4dc4863 Binary files /dev/null and b/resources/qtk-views-setup.png differ diff --git a/resources/qtk-views.png b/resources/qtk-views.png new file mode 100644 index 0000000..44dd8b4 Binary files /dev/null and b/resources/qtk-views.png differ diff --git a/src/input.h b/src/input.h index 96d006f..ba68804 100644 --- a/src/input.h +++ b/src/input.h @@ -13,10 +13,11 @@ #include #include +#include namespace Qtk { class QTKAPI Input { - friend class MainWidget; + friend class Qtk::QtkWidget; public: // Possible key states enum InputState diff --git a/src/mainwidget.cpp b/src/qtkwidget.cpp similarity index 90% rename from src/mainwidget.cpp rename to src/qtkwidget.cpp index bf982a5..ede2b86 100644 --- a/src/mainwidget.cpp +++ b/src/qtkwidget.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include @@ -19,26 +19,26 @@ using namespace Qtk; * Constructors, Destructors ******************************************************************************/ -MainWidget::MainWidget() : mScene(Q_NULLPTR), mDebugLogger(Q_NULLPTR) +QtkWidget::QtkWidget() : mScene(Q_NULLPTR), mDebugLogger(Q_NULLPTR) { initializeWidget(); } // Constructor for using this widget in QtDesigner -MainWidget::MainWidget(QWidget *parent) : QOpenGLWidget(parent), +QtkWidget::QtkWidget(QWidget *parent) : QOpenGLWidget(parent), mScene(Q_NULLPTR), mDebugLogger(Q_NULLPTR) { initializeWidget(); } -MainWidget::MainWidget(const QSurfaceFormat &format) +QtkWidget::QtkWidget(const QSurfaceFormat &format) : mScene(Q_NULLPTR), mDebugLogger(Q_NULLPTR) { setFormat(format); setFocusPolicy(Qt::ClickFocus); } -MainWidget::~MainWidget() +QtkWidget::~QtkWidget() { makeCurrent(); teardownGL(); @@ -49,7 +49,7 @@ MainWidget::~MainWidget() * Private Member Functions ******************************************************************************/ -void MainWidget::teardownGL() +void QtkWidget::teardownGL() { // Nothing to teardown yet... } @@ -59,7 +59,7 @@ void MainWidget::teardownGL() * Inherited Virtual Member Functions ******************************************************************************/ -void MainWidget::paintGL() +void QtkWidget::paintGL() { // Clear buffers glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); @@ -68,7 +68,7 @@ void MainWidget::paintGL() if (mScene != Q_NULLPTR) mScene->draw(); } -void MainWidget::initializeGL() +void QtkWidget::initializeGL() { initializeOpenGLFunctions(); // Connect the frameSwapped signal to call the update() function @@ -98,7 +98,7 @@ void MainWidget::initializeGL() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } -void MainWidget::resizeGL(int width, int height) +void QtkWidget::resizeGL(int width, int height) { Scene::Projection().setToIdentity(); Scene::Projection().perspective(45.0f, @@ -111,7 +111,7 @@ void MainWidget::resizeGL(int width, int height) * Protected Slots ******************************************************************************/ -void MainWidget::update() +void QtkWidget::update() { updateCameraInput(); @@ -120,7 +120,7 @@ void MainWidget::update() QWidget::update(); } -void MainWidget::messageLogged(const QOpenGLDebugMessage &msg) +void QtkWidget::messageLogged(const QOpenGLDebugMessage &msg) { QString error; @@ -185,7 +185,7 @@ void MainWidget::messageLogged(const QOpenGLDebugMessage &msg) * Protected Helpers ******************************************************************************/ -void MainWidget::keyPressEvent(QKeyEvent *event) +void QtkWidget::keyPressEvent(QKeyEvent *event) { if (event->isAutoRepeat()) { // Do not repeat input while a key is held down @@ -195,7 +195,7 @@ void MainWidget::keyPressEvent(QKeyEvent *event) } } -void MainWidget::keyReleaseEvent(QKeyEvent *event) +void QtkWidget::keyReleaseEvent(QKeyEvent *event) { if (event->isAutoRepeat()) { event->ignore(); @@ -204,12 +204,12 @@ void MainWidget::keyReleaseEvent(QKeyEvent *event) } } -void MainWidget::mousePressEvent(QMouseEvent *event) +void QtkWidget::mousePressEvent(QMouseEvent *event) { Input::registerMousePress(event->button()); } -void MainWidget::mouseReleaseEvent(QMouseEvent *event) +void QtkWidget::mouseReleaseEvent(QMouseEvent *event) { Input::registerMouseRelease(event->button()); } @@ -219,7 +219,7 @@ void MainWidget::mouseReleaseEvent(QMouseEvent *event) * Private Helpers ******************************************************************************/ -void MainWidget::initializeWidget() +void QtkWidget::initializeWidget() { QSurfaceFormat format; format.setRenderableType(QSurfaceFormat::OpenGL); @@ -237,7 +237,7 @@ void MainWidget::initializeWidget() setFocusPolicy(Qt::ClickFocus); } -void MainWidget::printContextInformation() +void QtkWidget::printContextInformation() { QString glType; QString glVersion; @@ -273,7 +273,7 @@ void MainWidget::printContextInformation() } -void MainWidget::updateCameraInput() +void QtkWidget::updateCameraInput() { Input::update(); // Camera Transformation diff --git a/src/mainwidget.h b/src/qtkwidget.h similarity index 78% rename from src/mainwidget.h rename to src/qtkwidget.h index 219c125..cdd0cba 100644 --- a/src/mainwidget.h +++ b/src/qtkwidget.h @@ -5,8 +5,8 @@ ## ## ## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## ##############################################################################*/ -#ifndef QTK_MAINWIDGET_H -#define QTK_MAINWIDGET_H +#ifndef QTK_QTKWIDGET_H +#define QTK_QTKWIDGET_H #include @@ -18,18 +18,17 @@ #include #include - namespace Qtk { - class QTKAPI MainWidget : public QOpenGLWidget, - protected QOpenGLFunctions { + class QTKAPI QtkWidget : public QOpenGLWidget, + protected QOpenGLFunctions { Q_OBJECT; public: // Constructors - MainWidget(); - explicit MainWidget(QWidget *parent); - explicit MainWidget(const QSurfaceFormat &format); - ~MainWidget() override; + QtkWidget(); + explicit QtkWidget(QWidget *parent); + explicit QtkWidget(const QSurfaceFormat &format); + ~QtkWidget() override; private: void teardownGL(); @@ -40,8 +39,8 @@ namespace Qtk { void initializeGL() override; void resizeGL(int width, int height) override; - inline Scene * getScene() {return mScene;} - inline void setScene(Scene * scene) { + inline Qtk::Scene * getScene() {return mScene;} + inline void setScene(Qtk::Scene * scene) { if (mScene != Q_NULLPTR) delete mScene; mScene = scene; } @@ -64,7 +63,7 @@ namespace Qtk { void initializeWidget(); void updateCameraInput(); - Scene * mScene; + Qtk::Scene * mScene; #ifdef QTK_DEBUG void printContextInformation(); QOpenGLDebugLogger * mDebugLogger; @@ -72,4 +71,4 @@ namespace Qtk { }; } -#endif // QTK_MAINWIDGET_H +#endif // QTK_QTKWIDGET_H