]> git.localhorst.tv Git - blank.git/blobdiff - src/model.cpp
add some light and color
[blank.git] / src / model.cpp
index 7335ed9a5c3ec35a91219180e6105d8436f4a2d3..bbfc97f4fcfb121f8646feec9d59680213958189 100644 (file)
@@ -1,32 +1,77 @@
 #include "model.hpp"
 
-#include <glm/gtc/matrix_transform.hpp>
-#include <glm/gtx/euler_angles.hpp>
-#include <glm/gtx/transform.hpp>
-
 
 namespace blank {
 
-Model::Model()
-: velocity(0, 0, 0)
-, position(0, 0, 0)
-, pitch(0)
-, yaw(0) {
+Model::Model(
+       std::vector<glm::vec3> &&vtx,
+       std::vector<glm::vec3> &&col,
+       std::vector<glm::vec3> &&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);
 }
 
 }