Allow triangle class to draw multiple gl triangles

This commit is contained in:
SeanOMik 2021-11-25 17:02:08 -05:00
parent 862833fc71
commit 625ba885c5
2 changed files with 10 additions and 14 deletions

View File

@ -46,24 +46,20 @@ int main(int argc, char *argv[]) {
glm::vec3(0.5f, -0.5f, 0.f),
glm::vec3(0.f, 0.5f, 0.f),
}; */
/* std::vector<glm::vec3> vertices = {
std::vector<glm::vec3> vertices = {
glm::vec3(0.5f, 0.5f, 0.0f),
glm::vec3(0.5f, -0.5f, 0.0f),
glm::vec3(-0.5f, 0.5f, 0.0f),
glm::vec3(0.5f, -0.5f, 0.0f),
glm::vec3(-0.5f, -0.5f, 0.0f),
glm::vec3(-0.5f, 0.5f, 0.0f),
};
std::shared_ptr<simpleengine::Event> tri(new simpleengine::shapes_2d::Triangle(base_shader_program, vertices));
game.add_event(tri); */
game.add_event(tri);
/* 0.5f, 0.5f, 0.0f, // top right
0.5f, -0.5f, 0.0f, // bottom right
-0.5f, 0.5f, 0.0f, // top left
// second triangle
0.5f, -0.5f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, // bottom left
-0.5f, 0.5f, 0.0f */
std::vector<glm::vec3> vertices = {
/* std::vector<glm::vec3> vertices = {
glm::vec3(0.5f, 0.5f, 0.f), // top right
glm::vec3(0.5f, -0.5f, 0.f), // bottom right
glm::vec3(-0.5f, -0.5f, 0.f), // bottom left
@ -76,7 +72,7 @@ int main(int argc, char *argv[]) {
};
std::shared_ptr<simpleengine::Event> square(new simpleengine::shapes_2d::Square(base_shader_program, vertices, indicies));
game.add_event(square);
game.add_event(square); */
return game.run();
}

View File

@ -39,7 +39,7 @@ namespace simpleengine::shapes_2d {
vao.bind();
vbo.buffer(vertices.data(), 0, vertices.size() * sizeof(float) * 3); // 3 floats are in each "row" of the vector.
vao.enable_attrib(vbo, 0, vertices.size(), GL_FLOAT, 3 * sizeof(float), 0);
vao.enable_attrib(vbo, 0, 3, GL_FLOAT, 3 * sizeof(float), 0);
}
virtual ~Triangle() = default;
@ -52,7 +52,7 @@ namespace simpleengine::shapes_2d {
glUseProgram(*shader_program);
vao.bind();
glDrawArrays(GL_TRIANGLES, 0, 3);
glDrawArrays(GL_TRIANGLES, 0, vertices.size());
}
};
}