-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshapes.cc
73 lines (55 loc) · 1.88 KB
/
shapes.cc
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <memory>
#include <cstdio>
#include <iostream>
#include <ux/shapes.h>
ColorQuad::ColorQuad() {
vertexArray = new VertexArray((const GLfloat *)quadVertices, sizeof(quadVertices));
}
void ColorQuad::bindData(ColorShaderProgram *shaderProgram) {
vertexArray->bindBuffer();
vertexArray->setVertexAttribPointer(
0,
shaderProgram->getPositionAttributeLocation(),
4,
0);
}
void ColorQuad::draw() {
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
for (GLenum err = glGetError(); err != GL_NO_ERROR; err = glGetError()) {
fprintf(stderr, "%d: %s\n", err, gluErrorString(err));
}
vertexArray->unbindBuffer();
glUseProgram(0);
}
TextureQuad::TextureQuad() {
vertexArray = new VertexArray((const GLfloat *)textureQuadVertices, sizeof(textureQuadVertices));
}
void TextureQuad::bindData(TextureShaderProgram *shaderProgram) {
vertexArray->bindBuffer();
int positionComponentCount = 2;
int textureComponentCount = 2;
int stride = (positionComponentCount + textureComponentCount) * 4;
vertexArray->setVertexAttribPointer(
0,
shaderProgram->getPositionAttributeLocation(),
2,
stride);
// vertexArray->setVertexAttribPointer(
// 0,
// shaderProgram->getTextureCoordinatesAttributeLocation(),
// 2,
// stride);
vertexArray->setVertexAttribPointer(
(void *)8, //positionComponentCount
shaderProgram->getTextureCoordinatesAttributeLocation(),
textureComponentCount,
stride);
}
void TextureQuad::draw() {
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
for (GLenum err = glGetError(); err != GL_NO_ERROR; err = glGetError()) {
fprintf(stderr, "%d: %s\n", err, gluErrorString(err));
}
vertexArray->unbindBuffer();
glUseProgram(0);
}