Files
panopainter/engine/shape.cpp
Omar Mohamed Ali Mudhir 13d8e6e563 base setup for osx in place
2017-01-14 18:30:19 +00:00

39 lines
1.3 KiB
C++

#include "pch.h"
#include "shape.hpp"
void Shape::create_buffers(GLvoid* idx, GLvoid* vertices, int isize, int vsize)
{
glGenBuffers(2, buffers);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, isize, idx, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
glBufferData(GL_ARRAY_BUFFER, vsize, vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenVertexArrays(2, arrays);
for (int i = 0; i < 2; i++)
{
glBindVertexArray(arrays[i]);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]);
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (GLvoid*)0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (GLvoid*)offsetof(vertex_t, uvs));
}
glBindVertexArray(0);
}
void Shape::draw_fill() const
{
glBindVertexArray(arrays[0]);
glDrawElements(GL_TRIANGLES, count[0], GL_UNSIGNED_SHORT, ioff[0]);
}
void Shape::draw_stroke() const
{
glBindVertexArray(arrays[1]);
glDrawElements(GL_LINES, count[1], GL_UNSIGNED_SHORT, ioff[1]);
}