Compare commits
2 commits
187bf4c1d1
...
d03afb31e1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d03afb31e1 | ||
|
|
2ce7375233 |
11 changed files with 12 additions and 26 deletions
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
|
|
@ -83,7 +83,6 @@ Scene setup() {
|
|||
|
||||
components::Scene config = utils::load_scene_config("config.json");
|
||||
Scene scene(config);
|
||||
scene.configure();
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
|
@ -91,7 +90,7 @@ Scene setup() {
|
|||
void update(GLFWwindow* window, Scene& scene) {
|
||||
glfwPollEvents();
|
||||
process_input(window, scene);
|
||||
scene.updateDelta();
|
||||
scene.update();
|
||||
}
|
||||
|
||||
void render(GLFWwindow* window, Scene& scene) {
|
||||
|
|
|
|||
|
|
@ -2,22 +2,25 @@
|
|||
#include "dbc.hpp"
|
||||
|
||||
void Mesh::draw(Shader &shader) {
|
||||
// CAN WE DO THIS LESS OFTEN OUTSIDE DRAWING?
|
||||
apply_textures(shader);
|
||||
|
||||
glBindVertexArray(VAO);
|
||||
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);
|
||||
glBindVertexArray(0);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
void Mesh::connect_shader(const Shader& shader) {
|
||||
void Mesh::apply_textures(const Shader& shader) {
|
||||
for(unsigned int i = 0; i < textures.size(); i++) {
|
||||
Texture& texture = textures[i];
|
||||
|
||||
texture.uniform_id = glGetUniformLocation(shader.ID, texture.target.c_str());
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
|
||||
// move this to setup_mesh
|
||||
glUniform1i(texture.uniform_id, i);
|
||||
glBindTexture(GL_TEXTURE_2D, texture.id);
|
||||
|
||||
texture.uniform_id = glGetUniformLocation(shader.ID, texture.target.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,5 +68,5 @@ struct Mesh {
|
|||
|
||||
void draw(Shader &shader);
|
||||
void setup_mesh();
|
||||
void connect_shader(const Shader& shader);
|
||||
void apply_textures(const Shader& shader);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -209,9 +209,3 @@ 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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,4 @@ struct Model {
|
|||
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 connect_shader(const Shader& shader);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,17 +2,12 @@
|
|||
#include "dbc.hpp"
|
||||
#include <math.h>
|
||||
|
||||
void Scene::updateDelta() {
|
||||
void Scene::update() {
|
||||
float currentFrame = glfwGetTime();
|
||||
deltaTime = currentFrame - lastFrame;
|
||||
lastFrame = currentFrame;
|
||||
}
|
||||
|
||||
void Scene::configure() {
|
||||
// REFACTOR: really this should be done somewhere else
|
||||
for(auto& [name, model] : models) {
|
||||
model.connect_shader(shader);
|
||||
}
|
||||
camera.update(deltaTime);
|
||||
}
|
||||
|
||||
void Scene::draw_model(Model& scene_model, Material& material, glm::mat4& projection, glm::mat4& view, glm::vec3& position)
|
||||
|
|
@ -38,8 +33,6 @@ void Scene::render(GLFWwindow* window) {
|
|||
// time is used for fake 3d rotation
|
||||
float time = glfwGetTime();
|
||||
|
||||
camera.update(deltaTime);
|
||||
|
||||
glm::mat4 view = camera.look_at();
|
||||
glm::mat4 projection = glm::mat4(1.0f);
|
||||
|
||||
|
|
|
|||
|
|
@ -56,8 +56,7 @@ struct Scene {
|
|||
}
|
||||
}
|
||||
|
||||
void updateDelta();
|
||||
void configure();
|
||||
void update();
|
||||
void draw_model(Model& scene_model, Material& material, glm::mat4& projection, glm::mat4& view, glm::vec3& position);
|
||||
void render(GLFWwindow* window);
|
||||
void cleanup();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue