Compare commits

..

No commits in common. "d03afb31e18695adb200395483a83a7d96ef7e13" and "187bf4c1d191854b6c27414943b5d2d1950fbba4" have entirely different histories.

11 changed files with 26 additions and 12 deletions

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

View file

@ -83,6 +83,7 @@ Scene setup() {
components::Scene config = utils::load_scene_config("config.json"); components::Scene config = utils::load_scene_config("config.json");
Scene scene(config); Scene scene(config);
scene.configure();
return scene; return scene;
} }
@ -90,7 +91,7 @@ Scene setup() {
void update(GLFWwindow* window, Scene& scene) { void update(GLFWwindow* window, Scene& scene) {
glfwPollEvents(); glfwPollEvents();
process_input(window, scene); process_input(window, scene);
scene.update(); scene.updateDelta();
} }
void render(GLFWwindow* window, Scene& scene) { void render(GLFWwindow* window, Scene& scene) {

View file

@ -2,25 +2,22 @@
#include "dbc.hpp" #include "dbc.hpp"
void Mesh::draw(Shader &shader) { void Mesh::draw(Shader &shader) {
// CAN WE DO THIS LESS OFTEN OUTSIDE DRAWING?
apply_textures(shader);
glBindVertexArray(VAO); glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0); glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
glBindVertexArray(0); glBindVertexArray(0);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
} }
void Mesh::apply_textures(const Shader& shader) { void Mesh::connect_shader(const Shader& shader) {
for(unsigned int i = 0; i < textures.size(); i++) { for(unsigned int i = 0; i < textures.size(); i++) {
Texture& texture = textures[i]; Texture& texture = textures[i];
texture.uniform_id = glGetUniformLocation(shader.ID, texture.target.c_str());
glActiveTexture(GL_TEXTURE0 + i); glActiveTexture(GL_TEXTURE0 + i);
// move this to setup_mesh // move this to setup_mesh
glUniform1i(texture.uniform_id, i); glUniform1i(texture.uniform_id, i);
glBindTexture(GL_TEXTURE_2D, texture.id); glBindTexture(GL_TEXTURE_2D, texture.id);
texture.uniform_id = glGetUniformLocation(shader.ID, texture.target.c_str());
} }
} }

View file

@ -68,5 +68,5 @@ struct Mesh {
void draw(Shader &shader); void draw(Shader &shader);
void setup_mesh(); void setup_mesh();
void apply_textures(const Shader& shader); void connect_shader(const Shader& shader);
}; };

View file

@ -209,3 +209,9 @@ void Model::load_material_textures(const aiScene *scene, std::vector<Texture>& t
} }
} }
} }
void Model::connect_shader(const Shader& shader) {
for(auto& mesh : meshes) {
mesh.connect_shader(shader);
}
}

View file

@ -39,4 +39,6 @@ struct Model {
Mesh process_mesh(const aiScene *scene, aiMesh *mesh); Mesh process_mesh(const aiScene *scene, aiMesh *mesh);
void load_material_textures(const aiScene *scene, std::vector<Texture>& textures, aiMaterial *mat, aiTextureType type, std::string typeName); void load_material_textures(const aiScene *scene, std::vector<Texture>& textures, aiMaterial *mat, aiTextureType type, std::string typeName);
void connect_shader(const Shader& shader);
}; };

View file

@ -2,12 +2,17 @@
#include "dbc.hpp" #include "dbc.hpp"
#include <math.h> #include <math.h>
void Scene::update() { void Scene::updateDelta() {
float currentFrame = glfwGetTime(); float currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame; deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame; lastFrame = currentFrame;
}
camera.update(deltaTime); void Scene::configure() {
// REFACTOR: really this should be done somewhere else
for(auto& [name, model] : models) {
model.connect_shader(shader);
}
} }
void Scene::draw_model(Model& scene_model, Material& material, glm::mat4& projection, glm::mat4& view, glm::vec3& position) void Scene::draw_model(Model& scene_model, Material& material, glm::mat4& projection, glm::mat4& view, glm::vec3& position)
@ -33,6 +38,8 @@ void Scene::render(GLFWwindow* window) {
// time is used for fake 3d rotation // time is used for fake 3d rotation
float time = glfwGetTime(); float time = glfwGetTime();
camera.update(deltaTime);
glm::mat4 view = camera.look_at(); glm::mat4 view = camera.look_at();
glm::mat4 projection = glm::mat4(1.0f); glm::mat4 projection = glm::mat4(1.0f);

View file

@ -56,7 +56,8 @@ struct Scene {
} }
} }
void update(); void updateDelta();
void configure();
void draw_model(Model& scene_model, Material& material, glm::mat4& projection, glm::mat4& view, glm::vec3& position); void draw_model(Model& scene_model, Material& material, glm::mat4& projection, glm::mat4& view, glm::vec3& position);
void render(GLFWwindow* window); void render(GLFWwindow* window);
void cleanup(); void cleanup();