charcoal/OpenGLEngine/MyTriangle.cpp
elipzer b494f68d0c A Working Triangle
Now using GLFW3 instead of the custom window class. This library
looks like it will make development much simpler and will make it
so that I am less worried about my windows code breaking. Currently
setup the http://antongerdelan.net/opengl/hellotriangle.html
tutorial in the MySimpleScene. Will probably create another scene
file to try to get the object oriented stuff working.
2018-09-05 16:26:50 -04:00

53 lines
1023 B
C++

#include "MyTriangle.h"
#include "Mesh.h"
MyTriangle::MyTriangle()
{
MeshType* mesh = new MeshType();
mesh->vertices = new VertexType[3]
{
{ 0.0, 0.5, 1.0 },
{ 0.5, -0.5, 1.0 },
{ -0.5, -0.5, 1.0 },
};
mesh->vertex_count = 3;
mesh->indices = new unsigned int[3] { 0, 1, 2, };
mesh->index_count = 3;
m_p_mesh = mesh;
}
MyTriangle::~MyTriangle()
{
if (m_p_mesh != nullptr)
{
if (m_p_mesh->vertices != nullptr)
{
delete[] m_p_mesh->vertices;
}
if (m_p_mesh->indices != nullptr)
{
delete[] m_p_mesh->indices;
}
delete m_p_mesh;
m_p_mesh = nullptr;
}
}
void MyTriangle::populate_vbo() const
{
glBufferData(GL_ARRAY_BUFFER, m_p_mesh->vertex_count * sizeof(VertexType), m_p_mesh->vertices, GL_STATIC_DRAW);
}
/*
GLuint MyTriangle::gen_vbo() const
{
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, m_p_mesh->vertex_count * sizeof(VertexType), m_p_mesh->vertices, GL_STATIC_DRAW); // TODO: Optimise Usage
return vbo;
}
*/