-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
256 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "Mesh.hpp" | ||
|
||
|
||
namespace Future | ||
{ | ||
Mesh::Mesh(std::vector <Vertex>& vertices, std::vector <GLuint>& indices, std::vector<Texture>& textures) | ||
{ | ||
Mesh::vertices = vertices; | ||
Mesh::indices = indices; | ||
Mesh::textures = textures; | ||
|
||
VAO.Bind(); // Bind VAO | ||
|
||
VBO VBO (vertices); | ||
EBO EBO (indices); | ||
|
||
VAO.LinkAttrib(VBO, 0, 3, GL_FLOAT, sizeof(Vertex), (void*)0); // Position | ||
VAO.LinkAttrib(VBO, 1, 3, GL_FLOAT, sizeof(Vertex), (void*)(3 * sizeof(float))); // Color | ||
VAO.LinkAttrib(VBO, 2, 2, GL_FLOAT, sizeof(Vertex), (void*)(6 * sizeof(float))); // Texture Coordinate | ||
VAO.LinkAttrib(VBO, 3, 2, GL_FLOAT, sizeof(Vertex), (void*)(9 * sizeof(float))); // Normals | ||
|
||
VAO.Unbind(); | ||
VBO.Unbind(); | ||
EBO.Unbind(); | ||
} | ||
|
||
void Mesh::Draw(Shaders &shaders, Camera &camera) | ||
{ | ||
shaders.Activate(); | ||
VAO.Bind(); | ||
|
||
unsigned int numDiffuse = 0; | ||
unsigned int numSpecular = 0; | ||
|
||
for (unsigned int i = 0; i < textures.size(); i++) | ||
{ | ||
std::string num; | ||
std::string type = textures[i].type; | ||
if (type == "diffuse") | ||
{ | ||
num = std::to_string(numDiffuse++); | ||
} | ||
else if (type == "specular") | ||
{ | ||
num = std::to_string(numSpecular++); | ||
} | ||
textures[i].texUnit(shaders, (type + num).c_str(), i); | ||
textures[i].Bind(); | ||
} | ||
glUniform3f(glGetUniformLocation(shaders.ID, "camPos"), camera.Position.x, camera.Position.y, camera.Position.z); | ||
camera.Matrix(shaders, "camMatrix"); | ||
|
||
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0); | ||
} | ||
|
||
} // Future |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef MESH_HPP | ||
#define MESH_HPP | ||
|
||
#include <string> | ||
#include "Buffers/VAO.hpp" | ||
#include "Buffers/EBO.hpp"" | ||
#include "Camera.hpp" | ||
#include "Textures/Texture.hpp" | ||
namespace Future | ||
{ | ||
class Mesh | ||
{ | ||
public: | ||
std::vector<Vertex> vertices; | ||
std::vector<GLuint> indices; | ||
std::vector<Texture> textures; | ||
VAO VAO; | ||
Mesh(std::vector <Vertex>& vertices, std::vector <GLuint>& indices, std::vector<Texture>& textures); | ||
void Draw(Shaders& shaders, Camera& camera); | ||
}; | ||
} | ||
#endif //MESH_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.