diff --git a/headers/Mandelbrot.h b/headers/Mandelbrot.h index acf5d0f..fc332f6 100644 --- a/headers/Mandelbrot.h +++ b/headers/Mandelbrot.h @@ -2,9 +2,9 @@ #pragma once #include -#include +#include -class Mandelbrot : public QObject, protected QOpenGLFunctions { +class Mandelbrot : public QObject, protected QOpenGLFunctions_3_3_Core { Q_OBJECT public: void init(); @@ -13,6 +13,9 @@ public: public slots: void setIterations(int); private: + static float* genVertices(); + GLuint createVAO(); + GLuint vao; int iterations = 0; double scale = 1; QVector2D translation; diff --git a/headers/OutputWidget.h b/headers/OutputWidget.h index 5e8b041..f9797cb 100644 --- a/headers/OutputWidget.h +++ b/headers/OutputWidget.h @@ -3,11 +3,10 @@ #include -#include #include #include "Mandelbrot.h" -class OutputWidget : public QOpenGLWidget, protected QOpenGLFunctions { +class OutputWidget : public QOpenGLWidget, protected QOpenGLFunctions_3_3_Core { Q_OBJECT public: explicit OutputWidget(QWidget* parent): QOpenGLWidget(parent) {} diff --git a/src/Mandelbrot.cpp b/src/Mandelbrot.cpp index e05bfcf..813d6a9 100644 --- a/src/Mandelbrot.cpp +++ b/src/Mandelbrot.cpp @@ -4,7 +4,7 @@ void Mandelbrot::init() { initializeOpenGLFunctions(); - + vao = createVAO(); } void Mandelbrot::draw() { @@ -19,4 +19,34 @@ void Mandelbrot::setIterations(int value) { iterations = value; } +GLuint Mandelbrot::createVAO() { + GLuint vboId; + glGenBuffers(1, &vboId); + glBindBuffer(GL_ARRAY_BUFFER, vboId); + + float* vertices = genVertices(); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); + + GLuint vaoId; + glGenVertexArrays(1, &vaoId); + glBindVertexArray(vaoId); + glBindBuffer(GL_ARRAY_BUFFER, vboId); + + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*) nullptr); + glEnableVertexAttribArray(0); + + glBindVertexArray(0); + + return vaoId; +} + +float* Mandelbrot::genVertices() { + return new float[8]{ + -1, -1, + 1, -1, + 1, 1, + -1, 1 + }; +} +