text: #include "Mesh.h"
  
  
  
  Mesh::Mesh(std::vector<Vertex> verticies, std::vector<GLuint> indicies, std::vector<Texture> textures)
  {
  	this->verticies = verticies;
  	this->indicies = indicies;
  	this->textures = textures;
  
  	setupMesh();
  }
  
  
  Mesh::~Mesh()
  {
  }
  
  void Mesh::setupMesh() {
  	glGenVertexArrays(1, &VAO);
  	glGenBuffers(1, &VBO);
  	glGenBuffers(1, &EBO);
  
  	glBindVertexArray(VAO);
  
  	glBindBuffer(GL_ARRAY_BUFFER, VBO);
  	glBufferData(GL_ARRAY_BUFFER, verticies.size() * sizeof(Vertex), &verticies[0], GL_STATIC_DRAW);
  
  	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
  	glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicies.size() * sizeof(GLuint), &indicies[0], GL_STATIC_DRAW);
  
  	glEnableVertexAttribArray(0);
  	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)0);
  
  	glEnableVertexAttribArray(1);
  	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, Normal));
  
  	glEnableVertexAttribArray(2);
  	glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, TexCoords));
  	
  	glBindVertexArray(0);
  
  
  }
  
  void Mesh::Draw(GLuint shader) {
  	GLuint diffuseNr = 1;
  	GLuint specularNr = 1;
  
  	//std::cout << textures.size() << std::endl;
  	for (GLuint i = 0; i < textures.size(); i++) {
  		std::stringstream ss;
  		std::string number;
  		std::string name = textures[i].type;
  		if (name == "texture_diffuse") {
  			ss << diffuseNr++;
  		}
  		else if (name == "texture_specular") {
  			ss << specularNr++;
  		}
  		number = ss.str();
  		glUniform1i(glGetUniformLocation(shader, (name + number).c_str()), i);
  		glBindTexture(GL_TEXTURE_2D, textures[i].id);
  	}
  	glUniform1f(glGetUniformLocation(shader, "material.shininess"), 16.0f);
  
  	if (VAO == NULL) {
  		std::cout << "VAO was null" << std::endl;
  	}
  
  	//std::cout << indicies.size() << std::endl;
  	glBindVertexArray(VAO);
  	glDrawElements(GL_TRIANGLES, indicies.size(), GL_UNSIGNED_INT, 0);
  	glBindVertexArray(0);
  
  	for (GLuint i = 0; i < textures.size(); i++) {
  		glActiveTexture(GL_TEXTURE0 + i);
  		glBindTexture(GL_TEXTURE_2D, 0);
  	}
  }