45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
#ifndef ECSGAME_LINES_H
|
|
#define ECSGAME_LINES_H
|
|
|
|
#include "../../Util/geometry.h"
|
|
#include <GLFW/glfw3.h>
|
|
#include <glad/glad.h>
|
|
#include <glm/fwd.hpp>
|
|
#include <vector>
|
|
|
|
struct Lines {
|
|
explicit Lines(std::vector<Vector> lines) : vertex_count(lines.size()) {
|
|
GLfloat linearray[vertex_count * 3];
|
|
int pos = 0;
|
|
|
|
for (const Vector &vec : lines) {
|
|
linearray[pos++] = vec[0];
|
|
linearray[pos++] = vec[1];
|
|
linearray[pos++] = vec[2];
|
|
}
|
|
|
|
glGenVertexArrays(1, &lineVAO);
|
|
glGenBuffers(1, &lineVBO);
|
|
glBindVertexArray(lineVAO);
|
|
glBindBuffer(GL_ARRAY_BUFFER, lineVBO);
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(linearray), &linearray, GL_STATIC_DRAW);
|
|
glEnableVertexAttribArray(0);
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (void *)0);
|
|
}
|
|
|
|
void render() const {
|
|
// glEnable(GL_LINE_SMOOTH);
|
|
// glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
|
glBindVertexArray(lineVAO);
|
|
glLineWidth(3.3f);
|
|
glDrawArrays(GL_LINES, 0, vertex_count);
|
|
glLineWidth(1.0f);
|
|
}
|
|
|
|
private:
|
|
GLuint lineVAO, lineVBO;
|
|
int vertex_count;
|
|
};
|
|
|
|
#endif // ECSGAME_LINES_H
|