-
Notifications
You must be signed in to change notification settings - Fork 0
/
RenderQuad.cpp
48 lines (39 loc) · 1.14 KB
/
RenderQuad.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "RenderQuad.h"
#include <iostream>
RenderQuad::RenderQuad() {
GLfloat data[] = {
-1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 0.0f, 0.0f,
1.0f, -1.0f, 1.0f, 0.0f,
1.0f, -1.0f, 1.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 0.0f, 1.0f
};
glGenVertexArrays(1, &vao);
glGenBuffers(1, &vbo);
glBindVertexArray(vao);
// Bind to the first VBO. We will use it to store the vertices.
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 6 * 4,
data, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), 0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (GLvoid*)(2 * sizeof(GLfloat)));
// Unbind from the VBOs.
glBindBuffer(GL_ARRAY_BUFFER, 0);
// Unbind from the VAO.
glBindVertexArray(0);
}
RenderQuad::~RenderQuad() {
glDeleteBuffers(1, &vbo);
glDeleteVertexArrays(1, &vao);
}
//draw the quad to the whole screen
void RenderQuad::draw() {
glDisable(GL_DEPTH_TEST);
glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
glEnable(GL_DEPTH_TEST);
}