]> git.sur5r.net Git - fstl/blob - src/backdrop.cpp
New upstream version 0.10.0
[fstl] / src / backdrop.cpp
1 #include "backdrop.h"
2
3 Backdrop::Backdrop()
4 {
5     initializeOpenGLFunctions();
6
7     shader.addShaderFromSourceFile(QOpenGLShader::Vertex, ":/gl/quad.vert");
8     shader.addShaderFromSourceFile(QOpenGLShader::Fragment, ":/gl/quad.frag");
9     shader.link();
10
11     float vbuf[] = {
12         -1, -1, 0.00, 0.10, 0.15,
13         -1,  1, 0.03, 0.21, 0.26,
14          1, -1, 0.00, 0.12, 0.18,
15          1,  1, 0.06, 0.26, 0.30};
16
17     vertices.create();
18     vertices.bind();
19     vertices.allocate(vbuf, sizeof(vbuf));
20     vertices.release();
21 }
22
23 void Backdrop::draw()
24 {
25     shader.bind();
26     vertices.bind();
27
28     const GLuint vp = shader.attributeLocation("vertex_position");
29     const GLuint vc = shader.attributeLocation("vertex_color");
30
31     glEnableVertexAttribArray(vp);
32     glEnableVertexAttribArray(vc);
33
34     glVertexAttribPointer(vp, 2, GL_FLOAT, false,
35                           5 * sizeof(GLfloat), 0);
36     glVertexAttribPointer(vc, 3, GL_FLOAT, false,
37                           5 * sizeof(GLfloat),
38                           (GLvoid*)(2 * sizeof(GLfloat)));
39
40     glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);
41
42     vertices.release();
43     shader.release();
44 }