forked from yiming-cai/OursCraft
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimplePointer.cpp
More file actions
69 lines (61 loc) · 2.13 KB
/
Copy pathSimplePointer.cpp
File metadata and controls
69 lines (61 loc) · 2.13 KB
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
#include "SimplePointer.h"
SimplePointer::SimplePointer(int id,float xpos, float ypos, glm::vec3 color)
{
this->id = id;
pointLen = 0;
for (int i = xpos - 5; i <= xpos + 5; ++i) {
this->position[3 * pointLen] = i / 500.0f;
this->position[3 * pointLen + 1] = ypos;
this->position[3 * pointLen + 2] = 0;
this->color[3 * pointLen] = color.x;
this->color[3 * pointLen + 1] = color.y;
this->color[3 * pointLen + 2] = color.z;
++pointLen;
}
for (int i = ypos - 10; i <= ypos + 10; ++i) {
this->position[3 * pointLen] = xpos;
this->position[3 * pointLen + 1] = i / 500.0f;
this->position[3 * pointLen + 2] = 0;
this->color[3 * pointLen] = color.x;
this->color[3 * pointLen + 1] = color.y;
this->color[3 * pointLen + 2] = color.z;
++pointLen;
}
this->shader = Shader_SimplePointer;
printf("this shader is %d\n", Shader_SimplePointer);
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &CBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, 3 * pointLen * sizeof(GLfloat), this ->position, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
glBindBuffer(GL_ARRAY_BUFFER, CBO);
glBufferData(GL_ARRAY_BUFFER, 3 * pointLen * sizeof(GLfloat), this -> color, GL_STATIC_DRAW);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
glBindVertexArray(0);
}
SimplePointer::~SimplePointer()
{
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
glDeleteBuffers(1, &CBO);
}
void SimplePointer::draw(glm::mat4 C)
{
glUseProgram(shader);
glm::mat4 modelview = glm::mat4(1.0f);
//glm::vec4 temp = glm::vec4(vertices[6], vertices[7], vertices[8], 1.0f);
GLuint uProjection = glGetUniformLocation(shader, "projection");
GLuint uModelview = glGetUniformLocation(shader, "modelview");
glUniformMatrix4fv(uProjection, 1, GL_FALSE, &modelview[0][0]);
glUniformMatrix4fv(uModelview, 1, GL_FALSE, &modelview[0][0]);
glBindVertexArray(VAO);
glDrawArrays(GL_POINTS, 0, pointLen * 3);
glBindVertexArray(0);
}
void SimplePointer::update()
{
}