feat: add opengl widget
This commit is contained in:
@@ -12,7 +12,7 @@ project(enzo_project)
|
||||
|
||||
|
||||
# qt
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Widgets SvgWidgets)
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Widgets SvgWidgets OpenGLWidgets)
|
||||
qt_standard_project_setup()
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ qt_add_executable(${AppExec}
|
||||
src/gui/network/NodeIconGraphic.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets)
|
||||
target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets Qt6::OpenGLWidgets)
|
||||
target_include_directories(${AppExec} PUBLIC src)
|
||||
|
||||
# tests
|
||||
|
||||
0
src/gui/viewport/OpenGLWidget.cpp
Normal file
0
src/gui/viewport/OpenGLWidget.cpp
Normal file
31
src/gui/viewport/OpenGLWidget.h
Normal file
31
src/gui/viewport/OpenGLWidget.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <QOpenGLWidget>
|
||||
#include <QOpenGLFunctions>
|
||||
|
||||
class MyGLWidget : public QOpenGLWidget
|
||||
{
|
||||
public:
|
||||
MyGLWidget(QWidget *parent) : QOpenGLWidget(parent) { }
|
||||
|
||||
protected:
|
||||
void initializeGL() override
|
||||
{
|
||||
// Set up the rendering context, load shaders and other resources, etc.:
|
||||
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
||||
f->glClearColor(0.16f, 0.16f, 0.16f, 1.0f);
|
||||
}
|
||||
|
||||
void resizeGL(int w, int h) override
|
||||
{
|
||||
// // Update projection matrix and other size related settings:
|
||||
// m_projection.setToIdentity();
|
||||
// m_projection.perspective(45.0f, w / float(h), 0.01f, 100.0f);
|
||||
}
|
||||
|
||||
void paintGL() override
|
||||
{
|
||||
// Draw the scene:
|
||||
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
||||
f->glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "gui/viewport/Viewport.h"
|
||||
#include <qboxlayout.h>
|
||||
#include <qpushbutton.h>
|
||||
|
||||
Viewport::Viewport(QWidget *parent, Qt::WindowFlags f)
|
||||
: QWidget(parent, f)
|
||||
{
|
||||
mainLayout_=new QVBoxLayout();
|
||||
openGLWidget_ = new MyGLWidget(this);
|
||||
mainLayout_->addWidget(openGLWidget_);
|
||||
|
||||
setLayout(mainLayout_);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
#pragma once
|
||||
#include <qboxlayout.h>
|
||||
#include <qwidget.h>
|
||||
#include "gui/viewport/OpenGLWidget.h"
|
||||
|
||||
class Viewport
|
||||
: public QWidget
|
||||
{
|
||||
public:
|
||||
Viewport(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
private:
|
||||
QVBoxLayout* mainLayout_;
|
||||
MyGLWidget* openGLWidget_;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user