2021-09-03 16:56:57 +00:00
|
|
|
/*##############################################################################
|
|
|
|
## Author: Shaun Reed ##
|
2022-03-06 16:54:05 +00:00
|
|
|
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
|
|
|
## About: Main window for Qt6 OpenGL widget application ##
|
2021-09-03 16:56:57 +00:00
|
|
|
## ##
|
|
|
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
|
|
##############################################################################*/
|
2022-08-21 19:37:42 +00:00
|
|
|
#ifndef QTK_QTKWIDGET_H
|
|
|
|
#define QTK_QTKWIDGET_H
|
2021-09-03 16:56:57 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <QMatrix4x4>
|
|
|
|
#include <QOpenGLDebugLogger>
|
|
|
|
#include <QOpenGLFunctions>
|
|
|
|
#include <QOpenGLWidget>
|
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
#include <qtkapi.h>
|
|
|
|
#include <abstractscene.h>
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
namespace Qtk {
|
2022-08-21 19:37:42 +00:00
|
|
|
class QTKAPI QtkWidget : public QOpenGLWidget,
|
|
|
|
protected QOpenGLFunctions {
|
2022-08-07 17:12:12 +00:00
|
|
|
Q_OBJECT;
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
public:
|
|
|
|
// Constructors
|
2022-08-21 19:37:42 +00:00
|
|
|
QtkWidget();
|
|
|
|
explicit QtkWidget(QWidget *parent);
|
|
|
|
explicit QtkWidget(const QSurfaceFormat &format);
|
|
|
|
~QtkWidget() override;
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
private:
|
|
|
|
void teardownGL();
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
public:
|
|
|
|
// Inherited virtual Members
|
|
|
|
void paintGL() override;
|
|
|
|
void initializeGL() override;
|
|
|
|
void resizeGL(int width, int height) override;
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-08-21 19:37:42 +00:00
|
|
|
inline Qtk::Scene * getScene() {return mScene;}
|
|
|
|
inline void setScene(Qtk::Scene * scene) {
|
2022-08-07 17:12:12 +00:00
|
|
|
if (mScene != Q_NULLPTR) delete mScene;
|
|
|
|
mScene = scene;
|
|
|
|
}
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
protected slots:
|
|
|
|
void update();
|
|
|
|
#ifdef QTK_DEBUG
|
|
|
|
void messageLogged(const QOpenGLDebugMessage &msg);
|
|
|
|
#endif
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
// Protected Helpers
|
|
|
|
protected:
|
|
|
|
void keyPressEvent(QKeyEvent *event);
|
|
|
|
void keyReleaseEvent(QKeyEvent *event);
|
|
|
|
void mousePressEvent(QMouseEvent *event);
|
|
|
|
void mouseReleaseEvent(QMouseEvent *event);
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-08-07 17:12:12 +00:00
|
|
|
private:
|
|
|
|
// Private helpers
|
|
|
|
void initializeWidget();
|
|
|
|
void updateCameraInput();
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-08-21 19:37:42 +00:00
|
|
|
Qtk::Scene * mScene;
|
2022-08-07 17:12:12 +00:00
|
|
|
#ifdef QTK_DEBUG
|
|
|
|
void printContextInformation();
|
|
|
|
QOpenGLDebugLogger * mDebugLogger;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
}
|
2021-09-03 16:56:57 +00:00
|
|
|
|
2022-08-21 19:37:42 +00:00
|
|
|
#endif // QTK_QTKWIDGET_H
|