X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmodel.cpp;h=bbfc97f4fcfb121f8646feec9d59680213958189;hb=3baab6cca7423d55ea08288d96570b02380b1fe9;hp=7335ed9a5c3ec35a91219180e6105d8436f4a2d3;hpb=49c81f76b80e0de99ca57db49510eb5e3385e1d1;p=blank.git diff --git a/src/model.cpp b/src/model.cpp index 7335ed9..bbfc97f 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -1,32 +1,77 @@ #include "model.hpp" -#include -#include -#include - namespace blank { -Model::Model() -: velocity(0, 0, 0) -, position(0, 0, 0) -, pitch(0) -, yaw(0) { +Model::Model( + std::vector &&vtx, + std::vector &&col, + std::vector &&norm +) +: vertices(vtx) +, colors(col) +, normals(norm) +, handle{} { + glGenBuffers(ATTRIB_COUNT, handle); + + glBindBuffer(GL_ARRAY_BUFFER, handle[ATTRIB_VERTEX]); + glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), vertices.data(), GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, handle[ATTRIB_COLOR]); + glBufferData(GL_ARRAY_BUFFER, colors.size() * sizeof(glm::vec3), colors.data(), GL_STATIC_DRAW); + + glBindBuffer(GL_ARRAY_BUFFER, handle[ATTRIB_NORMAL]); + glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(glm::vec3), normals.data(), GL_STATIC_DRAW); } Model::~Model() { - + glDeleteBuffers(ATTRIB_COUNT, handle); } -glm::mat4 Model::Transform() const { - return glm::translate(position) * glm::eulerAngleYX(yaw, pitch); -} +void Model::Draw() { + glEnableVertexAttribArray(ATTRIB_VERTEX); + glBindBuffer(GL_ARRAY_BUFFER, handle[ATTRIB_VERTEX]); + glVertexAttribPointer( + ATTRIB_VERTEX, // location (for shader) + 3, // size + GL_FLOAT, // type + GL_FALSE, // normalized + 0, // stride + nullptr // offset + ); + + glEnableVertexAttribArray(ATTRIB_COLOR); + glBindBuffer(GL_ARRAY_BUFFER, handle[ATTRIB_COLOR]); + glVertexAttribPointer( + ATTRIB_COLOR, // location (for shader) + 3, // size + GL_FLOAT, // type + GL_FALSE, // normalized + 0, // stride + nullptr // offset + ); + + glEnableVertexAttribArray(ATTRIB_NORMAL); + glBindBuffer(GL_ARRAY_BUFFER, handle[ATTRIB_NORMAL]); + glVertexAttribPointer( + ATTRIB_NORMAL, // location (for shader) + 3, // size + GL_FLOAT, // type + GL_FALSE, // normalized + 0, // stride + nullptr // offset + ); + glDrawArrays( + GL_TRIANGLES, // how + 0, // start + vertices.size() // len + ); -void Model::Update(int dt) { - position += velocity * float(dt); + glDisableVertexAttribArray(ATTRIB_NORMAL); + glDisableVertexAttribArray(ATTRIB_COLOR); + glDisableVertexAttribArray(ATTRIB_VERTEX); } }