From 89fb2f7ef3e6a24a0048f33ea45eb9944119fcaf Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Tue, 2 May 2023 14:16:05 +0500 Subject: [PATCH] Added basic opengl rendering --- 3dobj-renderer.pro | 8 +++++--- opglwidget.cpp | 22 ++++++++++++++++++---- opglwidget.h | 4 ++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/3dobj-renderer.pro b/3dobj-renderer.pro index 317b9a9..10ca2df 100644 --- a/3dobj-renderer.pro +++ b/3dobj-renderer.pro @@ -4,7 +4,10 @@ TEMPLATE = app TARGET = 3dobj-renderer -INCLUDEPATH += . +INCLUDEPATH += . \ + /usr/include/GL +DEPENDPATH += . \ + /usr/include/GL # You can make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. @@ -14,7 +17,6 @@ INCLUDEPATH += . #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 # Input -SOURCES += main.cpp +SOURCES += main.cpp opglwidget.cpp FORMS += mainwindow.ui - QT += core gui widgets diff --git a/opglwidget.cpp b/opglwidget.cpp index c75dfa7..0907b3d 100644 --- a/opglwidget.cpp +++ b/opglwidget.cpp @@ -1,8 +1,22 @@ #include "opglwidget.h" -#include +#include +#include -//virtual void OPGLWidget::initializeGL() override {} +void OPGLWidget::initializeGL() { + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); +} -//virtual void OPGLWidget::paintGL() override {} +void OPGLWidget::paintGL() { + glClear(GL_COLOR_BUFFER_BIT); +} -//virtual void OPGLWidget::resizeGL(int w, int h) override {} +void OPGLWidget::resizeGL(int w, int h) { + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + float aspect = w / float(h); + float top = 0.2f * tan(M_PI / 8); + float right = 0.2f * tan(M_PI / 8) * aspect; + glFrustum(-right , right, -top, top, 0.1f, 100.0f); + glMatrixMode(GL_MODELVIEW); +} diff --git a/opglwidget.h b/opglwidget.h index 022f020..3a32627 100644 --- a/opglwidget.h +++ b/opglwidget.h @@ -4,4 +4,8 @@ class OPGLWidget : public QOpenGLWidget { public: OPGLWidget(QWidget *parent) : QOpenGLWidget(parent) {} +protected: + void paintGL(); + void initializeGL(); + void resizeGL(int w, int h); };