Advertisement
Guest User

Untitled

a guest
Jun 13th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include "Mesh.h"
  2. #include <iostream>
  3. #include <vector>
  4. #include <GL/glew.h>
  5. #include "vec2.h"
  6. #include "vec3.h"
  7. #include "utils.h"
  8.  
  9. using namespace std;
  10.  
  11. Mesh::Mesh(vector<float> data)
  12. {
  13.     this->data_size = data.size() / 8;
  14.     cout << "Data size: "  << data.size();
  15.  
  16.     // Load the shading program. TODO make it so that it gets it from a kind of cache.
  17.     this->program_id = loadShadingProgram("mesh_vs.glsl", "mesh_fs.glsl");
  18.  
  19.     // Create and bind the VAO:
  20.     glGenVertexArrays(1, &this->vao_id);
  21.     glBindVertexArray(this->vao_id);
  22.  
  23.     // Create and bind the VBO:
  24.     GLuint vbo_id;
  25.     glGenBuffers(1, &vbo_id);
  26.     glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
  27.     float * float_data = data.data();
  28.     glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(GLfloat), float_data, GL_STATIC_DRAW);
  29.  
  30.     // Tell how the data is stored:
  31.     glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0); // The location attrib.
  32.     glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float))); // The texcoord attrib.
  33.     glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(5 * sizeof(float))); // The normal attrib.
  34.     glEnableVertexAttribArray(0);
  35.     glEnableVertexAttribArray(1);
  36.     glEnableVertexAttribArray(2);
  37.  
  38.     glBindVertexArray(0);
  39.     glBindVertexArray(0);
  40. }
  41.  
  42.  
  43. void Mesh::draw(vec3 location, vec3 rotation) {
  44.  
  45.     glUseProgram(this->program_id);
  46.     glBindVertexArray(this->vao_id);
  47.     glDrawArrays(GL_TRIANGLES, 0, this->data_size);
  48.  
  49. }
  50.  
  51. Mesh::~Mesh()
  52. {
  53.     //dtor
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement