70 lines
1.5 KiB
C++
70 lines
1.5 KiB
C++
#include "LineSegment.h"
|
|
#define GLM_ENABLE_EXPERIMENTAL
|
|
#include "glm/gtx/string_cast.hpp"
|
|
|
|
void LineSegment::setup()
|
|
{
|
|
std::vector<glm::vec3> seg_vertices =
|
|
{ { .0, -1.0f, .0}, {.0, 1.0f, .0} };
|
|
|
|
std::vector<glm::vec3> seg_colors =
|
|
{ { 1.f, .0, .0}, {1.f, .0, .0} };
|
|
|
|
glGenVertexArrays(1, &_vaoHandle);
|
|
glBindVertexArray(_vaoHandle);
|
|
|
|
glGenBuffers(1, &_vbo_vertices);
|
|
glBindBuffer(GL_ARRAY_BUFFER, _vbo_vertices);
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * seg_vertices.size() * 3, seg_vertices.data(), GL_STATIC_DRAW);
|
|
|
|
glVertexAttribPointer(
|
|
0, //attr number = 0
|
|
3,
|
|
GL_FLOAT,
|
|
GL_FALSE,
|
|
0,
|
|
(void*)0);
|
|
glEnableVertexAttribArray(0); //attr number = 0
|
|
|
|
|
|
glGenBuffers(1, &_vbo_colors);
|
|
glBindBuffer(GL_ARRAY_BUFFER, _vbo_colors);
|
|
glBufferData(GL_ARRAY_BUFFER, seg_colors.size() * sizeof(GLfloat) * 3, seg_colors.data(), GL_STATIC_DRAW);
|
|
|
|
glVertexAttribPointer(
|
|
1,
|
|
3,
|
|
GL_FLOAT,
|
|
GL_FALSE,
|
|
0,
|
|
(void*)0);
|
|
glEnableVertexAttribArray(1);
|
|
|
|
}
|
|
|
|
LineSegment::LineSegment()
|
|
{
|
|
setup();
|
|
}
|
|
|
|
void LineSegment::draw(ShaderProgram *shader, glm::mat4x4 proj_matrix, glm::mat4x4 view_matrix)
|
|
{
|
|
_model.glPushMatrix();
|
|
effectTransformations();
|
|
glm::mat4 mvpMatrix = proj_matrix * view_matrix * _model.getMatrix();
|
|
glUniformMatrix4fv(shader->uniform("mvp"), 1, GL_FALSE, glm::value_ptr(mvpMatrix));
|
|
glLineWidth(4);
|
|
glBindVertexArray(_vaoHandle);
|
|
glDrawArrays(GL_LINES, 0, 2);
|
|
_model.glPopMatrix();
|
|
}
|
|
|
|
DrawableType LineSegment::getType()
|
|
{
|
|
return DrawableType::LINE_SEGMENT;
|
|
}
|
|
|
|
LineSegment::~LineSegment()
|
|
{
|
|
}
|