Can now load models from file, kinda

This commit is contained in:
Robert 2021-01-22 13:37:57 +01:00
parent 4c3c1687ef
commit ac5bf9abdb
13 changed files with 10247 additions and 12 deletions

View file

@ -23,4 +23,29 @@ namespace oglu
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
glClear(mask);
}
void Enable(GLenum cap)
{
glEnable(cap);
}
void Disable(GLenum cap)
{
glDisable(cap);
}
void Enable(GLenum cap, GLuint index)
{
glEnablei(cap, index);
}
void Disable(GLenum cap, GLuint index)
{
glDisablei(cap, index);
}
void PolygonMode(GLenum face, GLenum mode)
{
glPolygonMode(face, mode);
}
}

View file

@ -1,5 +1,10 @@
#include "vertexArray.hpp"
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
namespace oglu
{
AbstractVertexArray::AbstractVertexArray(const AbstractVertexArray& other) :
@ -22,6 +27,56 @@ namespace oglu
return VertexArray(obj);
}
std::shared_ptr<AbstractVertexArray> MakeVertexArray(const char* filepath)
{
std::ifstream file(filepath);
if (!file.good())
{
file.close();
throw std::runtime_error("Missing file: " + std::string(filepath));
}
std::vector<GLfloat> vertices;
std::vector<GLuint> indices;
std::string line;
while(!file.eof())
{
std::getline(file, line);
switch (line[0])
{
case 'v':
{
GLfloat x, y, z;
int shut_up_vs = sscanf(line.c_str(), "v %f %f %f", &x, &y, &z);
vertices.push_back(x);
vertices.push_back(y);
vertices.push_back(z);
} break;
case 'f':
{
GLuint a, b, c;
int shut_up_vs = sscanf(line.c_str(), "f %u %u %u", &a, &b, &c);
indices.push_back(a - 1);
indices.push_back(b - 1);
indices.push_back(c - 1);
} break;
default: break;
}
}
VertexAttribute topology[] = {
{0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0 },
};
return MakeVertexArray(vertices.data(), sizeof(GLfloat) * vertices.size(),
indices.data(), sizeof(GLuint) * indices.size(),
topology, sizeof(topology)
);
}
AbstractVertexArray::AbstractVertexArray(const GLfloat* vertices, size_t verticesSize,
const GLuint* indices, size_t indicesSize,
const VertexAttribute* topology, size_t topologySize) :