]> git.sur5r.net Git - fstl/commitdiff
Adding backdrop
authorMatt Keeter <matt.j.keeter@gmail.com>
Tue, 4 Mar 2014 02:33:54 +0000 (21:33 -0500)
committerMatt Keeter <matt.j.keeter@gmail.com>
Tue, 4 Mar 2014 02:33:54 +0000 (21:33 -0500)
src/backdrop.cpp [new file with mode: 0644]
src/backdrop.h [new file with mode: 0644]
src/canvas.cpp
src/canvas.h
src/fstl.pro
src/window.cpp

diff --git a/src/backdrop.cpp b/src/backdrop.cpp
new file mode 100644 (file)
index 0000000..7975f72
--- /dev/null
@@ -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
new file mode 100644 (file)
index 0000000..53e0074
--- /dev/null
@@ -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
index 346890751b80e02fb2b2af22332d43017d1b042f..290885b6e32457c9e4044d72681094f8a680b581 100644 (file)
@@ -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();
 }
 
index e867898a68410d7611f609048505e511608a1de6..c094e5b228d1238129f593907fd151c53d1ae682 100644 (file)
@@ -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;
index ac58ee19e83860eda29288491b20fefee60eb434..a5a0f0fce01a810c5a95474e9afe6ea4496cbd6c 100644 (file)
@@ -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
 
index 55669a6a97af91dab34c16c7768f1f4c41d00a03..b4d7c99e889005a9c4cf69d6276f88da18bb43dc 100644 (file)
@@ -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)