#include "widget.hpp" #include "gfx.hpp" Widget::Widget(GLuint shaderProgram) : _shaderProgram(shaderProgram) { const float lineLength = 0.1; for (int i = 0; i < 3*6; i++) { _vertices[i] *= _lineLength; } glGenVertexArrays(1, &_vao); glGenBuffers(1, &_vbo); glBindVertexArray(_vao); glBindBuffer(GL_ARRAY_BUFFER, _vbo); size_t v3Size = 3 * sizeof(float); size_t lineSize = 2 * sizeof(float); size_t vboBufferSize = v3Size * lineSize * 3; glBufferData(GL_ARRAY_BUFFER, vboBufferSize, &_vertices[0], GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); } void Widget::render(const float time) { glUseProgram(_shaderProgram); updateModelViewProjectionMatrix(_shaderProgram, time); GLint modelLocation = getShaderUniformLocation(_shaderProgram, "_Model"); glUniformMatrix4fv(modelLocation, 1, GL_FALSE, &_modelMatrix[0][0]); glBindVertexArray(_vao); glBindBuffer(GL_ARRAY_BUFFER, _vbo); glDrawArrays(GL_LINES, 0, 6); } void Widget::setModelMatrix(const glm::mat4 matrix) { _modelMatrix = matrix; } Widget::~Widget() { glDeleteVertexArrays(1, &_vao); glDeleteBuffers(1, &_vbo); }