master
Benjamin Kraft 3 years ago
parent 8671bcc5a2
commit 60962df591
  1. 7
      headers/Mandelbrot.h
  2. 3
      headers/OutputWidget.h
  3. 32
      src/Mandelbrot.cpp

@ -2,9 +2,9 @@
#pragma once
#include <QVector2D>
#include <QOpenGLFunctions>
#include <QOpenGLFunctions_3_3_Core>
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;

@ -3,11 +3,10 @@
#include <QWidget>
#include <QOpenGLFunctions>
#include <QOpenGLWidget>
#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) {}

@ -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
};
}

Loading…
Cancel
Save