-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFullscreenQuad.cpp
35 lines (30 loc) · 925 Bytes
/
FullscreenQuad.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
#include <GL/glew.h>
#include "FullscreenQuad.h"
static float quad[6][2] = {
{-1.f, -1.f}, {1.f, -1.f}, {1.f, 1.f},
{-1.f, -1.f}, {1.f, 1.f}, {-1.f, 1.f}
};
FullscreenQuad::FullscreenQuad() {
glGenVertexArrays(1, &this->vao);
glBindVertexArray(this->vao);
glGenBuffers(1, &this->vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), 0);
glBufferData(GL_ARRAY_BUFFER, sizeof(quad), quad, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
void FullscreenQuad::draw() {
glDisable(GL_DEPTH_TEST);
glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLES, 0, sizeof(quad) / (2 * sizeof(float)));
glBindVertexArray(0);
}
FullscreenQuad::~FullscreenQuad() {
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
glDisableVertexAttribArray(0);
glDeleteBuffers(1, &vbo);
glDeleteVertexArrays(1, &vao);
}