Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Mesh.h"
- #include <iostream>
- #include <vector>
- #include <GL/glew.h>
- #include "vec2.h"
- #include "vec3.h"
- #include "utils.h"
- using namespace std;
- Mesh::Mesh(vector<float> data)
- {
- this->data_size = data.size() / 8;
- cout << "Data size: " << data.size();
- // Load the shading program. TODO make it so that it gets it from a kind of cache.
- this->program_id = loadShadingProgram("mesh_vs.glsl", "mesh_fs.glsl");
- // Create and bind the VAO:
- glGenVertexArrays(1, &this->vao_id);
- glBindVertexArray(this->vao_id);
- // Create and bind the VBO:
- GLuint vbo_id;
- glGenBuffers(1, &vbo_id);
- glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
- float * float_data = data.data();
- glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(GLfloat), float_data, GL_STATIC_DRAW);
- // Tell how the data is stored:
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0); // The location attrib.
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float))); // The texcoord attrib.
- glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(5 * sizeof(float))); // The normal attrib.
- glEnableVertexAttribArray(0);
- glEnableVertexAttribArray(1);
- glEnableVertexAttribArray(2);
- glBindVertexArray(0);
- glBindVertexArray(0);
- }
- void Mesh::draw(vec3 location, vec3 rotation) {
- glUseProgram(this->program_id);
- glBindVertexArray(this->vao_id);
- glDrawArrays(GL_TRIANGLES, 0, this->data_size);
- }
- Mesh::~Mesh()
- {
- //dtor
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement