From 2d8b0edb4ad4ff83d874f96d1e9ac6d8149da71e Mon Sep 17 00:00:00 2001 From: Benjo Date: Thu, 3 Feb 2022 09:35:50 +0100 Subject: [PATCH] more setup --- headers/MainWindow.h | 2 +- headers/Mandelbrot.h | 17 +++++++++++++++++ headers/OutputWidget.h | 7 ++++++- src/Mandelbrot.cpp | 14 ++++++++++++++ src/OutputWidget.cpp | 14 +++++++++----- 5 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 headers/Mandelbrot.h create mode 100644 src/Mandelbrot.cpp diff --git a/headers/MainWindow.h b/headers/MainWindow.h index 1007800..ea0a868 100644 --- a/headers/MainWindow.h +++ b/headers/MainWindow.h @@ -12,7 +12,7 @@ private slots: private: void buildUI(); - OutputWidget* outputWidget = new OutputWidget; + OutputWidget* outputWidget = new OutputWidget(this); }; diff --git a/headers/Mandelbrot.h b/headers/Mandelbrot.h new file mode 100644 index 0000000..374dc12 --- /dev/null +++ b/headers/Mandelbrot.h @@ -0,0 +1,17 @@ + +#pragma once + +#include +#include + +class Mandelbrot : protected QOpenGLFunctions { +public: + Mandelbrot(); + void draw(); + void zoom(double); +private: + double scale; + QVector2D translation; +}; + + diff --git a/headers/OutputWidget.h b/headers/OutputWidget.h index d9f98f6..7c0b6cf 100644 --- a/headers/OutputWidget.h +++ b/headers/OutputWidget.h @@ -5,9 +5,12 @@ #include #include #include +#include "Mandelbrot.h" -class OutputWidget : public QOpenGLWidget, public QOpenGLFunctions { +class OutputWidget : public QOpenGLWidget, protected QOpenGLFunctions { Q_OBJECT +public: + explicit OutputWidget(QWidget* parent): QOpenGLWidget(parent) {}; private: void initializeGL() override; void paintGL() override; @@ -18,6 +21,8 @@ private: void mousePressEvent(QMouseEvent*) override; void mouseReleaseEvent(QMouseEvent*) override; void keyPressEvent(QKeyEvent*) override; + + Mandelbrot mandelbrot; }; diff --git a/src/Mandelbrot.cpp b/src/Mandelbrot.cpp new file mode 100644 index 0000000..53405f7 --- /dev/null +++ b/src/Mandelbrot.cpp @@ -0,0 +1,14 @@ + +#include "../headers/Mandelbrot.h" + +Mandelbrot::Mandelbrot() { + initializeOpenGLFunctions(); +} + +void Mandelbrot::draw() { + +} + +void Mandelbrot::zoom(double delta) { + +} diff --git a/src/OutputWidget.cpp b/src/OutputWidget.cpp index 2ffd040..b6f2ed2 100644 --- a/src/OutputWidget.cpp +++ b/src/OutputWidget.cpp @@ -2,19 +2,23 @@ #include #include "../headers/OutputWidget.h" +using std::cout, std::endl; + void OutputWidget::initializeGL() { + cout << "Initialize OpenGL" << endl; initializeOpenGLFunctions(); - std::cout << "Initialize GL" << std::endl; + auto format = this->format(); - std::cout << "OpenGL version: " << + cout << "OpenGL version: " << format.majorVersion() << "." << format.minorVersion() - << std::endl; + << endl; - ::glClearColor(0.5f, 0.5f, 0.5f, 1.0f); + glClearColor(0.5f, 0.5f, 0.5f, 1.0f); } void OutputWidget::paintGL() { - + glClear(GL_COLOR_BUFFER_BIT); + mandelbrot.draw(); } void OutputWidget::resizeGL(int w, int h) {