commit f94a8de6c405cd518bf259c1371030d1bf7187e9
parent 97cf902b8751a7709f4f92bc34efd3ef0060104e
Author: Matt Keeter <matt.j.keeter@gmail.com>
Date: Mon, 3 Mar 2014 21:33:54 -0500
Adding backdrop
Diffstat:
6 files changed, 71 insertions(+), 2 deletions(-)
diff --git a/src/backdrop.cpp b/src/backdrop.cpp
@@ -0,0 +1,42 @@
+#include "backdrop.h"
+
+Backdrop::Backdrop()
+{
+ shader.addShaderFromSourceFile(QGLShader::Vertex, ":/gl/quad.vert");
+ shader.addShaderFromSourceFile(QGLShader::Fragment, ":/gl/quad.frag");
+ shader.link();
+
+ float vbuf[] = {
+ -1, -1, 0.00, 0.10, 0.15,
+ -1, 1, 0.03, 0.21, 0.26,
+ 1, -1, 0.00, 0.12, 0.18,
+ 1, 1, 0.06, 0.26, 0.30};
+
+ vertices.create();
+ vertices.bind();
+ vertices.allocate(vbuf, sizeof(vbuf));
+ vertices.release();
+}
+
+void Backdrop::draw()
+{
+ shader.bind();
+ vertices.bind();
+
+ const GLuint vp = shader.attributeLocation("vertex_position");
+ const GLuint vc = shader.attributeLocation("vertex_color");
+
+ glEnableVertexAttribArray(vp);
+ glEnableVertexAttribArray(vc);
+
+ glVertexAttribPointer(vp, 2, GL_FLOAT, false,
+ 5 * sizeof(GLfloat), 0);
+ glVertexAttribPointer(vc, 3, GL_FLOAT, false,
+ 5 * sizeof(GLfloat),
+ (GLvoid*)(2 * sizeof(GLfloat)));
+
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);
+
+ vertices.release();
+ shader.release();
+}
diff --git a/src/backdrop.h b/src/backdrop.h
@@ -0,0 +1,17 @@
+#ifndef BACKDROP_H
+#define BACKDROP_H
+
+#include <QtOpenGL/QGLShaderProgram>
+#include <QtOpenGL/QGLBuffer>
+
+class Backdrop
+{
+public:
+ Backdrop();
+ void draw();
+private:
+ QGLShaderProgram shader;
+ QGLBuffer vertices;
+};
+
+#endif // BACKDROP_H
diff --git a/src/canvas.cpp b/src/canvas.cpp
@@ -2,6 +2,7 @@
#include <QDebug>
#include "canvas.h"
+#include "backdrop.h"
#include "glmesh.h"
#include "mesh.h"
@@ -39,6 +40,8 @@ void Canvas::initializeGL()
mesh_shader.addShaderFromSourceFile(QGLShader::Fragment, ":/gl/mesh.frag");
mesh_shader.link();
+ backdrop = new Backdrop();
+
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
}
@@ -47,6 +50,7 @@ void Canvas::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ backdrop->draw();
if (mesh) draw_mesh();
}
diff --git a/src/canvas.h b/src/canvas.h
@@ -8,6 +8,7 @@
class GLMesh;
class Mesh;
+class Backdrop;
class Canvas : public QGLWidget
{
@@ -40,6 +41,7 @@ private:
QGLShaderProgram quad_shader;
GLMesh* mesh;
+ Backdrop* backdrop;
QVector3D center;
float scale;
diff --git a/src/fstl.pro b/src/fstl.pro
@@ -9,14 +9,16 @@ SOURCES += \
mesh.cpp \
glmesh.cpp \
loader.cpp \
- window.cpp
+ window.cpp \
+ backdrop.cpp
HEADERS += \
canvas.h \
mesh.h \
glmesh.h \
loader.h \
- window.h
+ window.h \
+ backdrop.h
CONFIG += c++11
diff --git a/src/window.cpp b/src/window.cpp
@@ -13,6 +13,8 @@ Window::Window(QWidget *parent) :
canvas = new Canvas(format, this);
setCentralWidget(canvas);
+
+ resize(600, 400);
}
void Window::load_stl(const QString &filename)