Fixed the textures problem but it's still not amazing.
This commit is contained in:
parent
2ce7375233
commit
d03afb31e1
8 changed files with 11 additions and 25 deletions
Binary file not shown.
|
|
@ -83,7 +83,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
@ -91,7 +90,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.updateDelta();
|
scene.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void render(GLFWwindow* window, Scene& scene) {
|
void render(GLFWwindow* window, Scene& scene) {
|
||||||
|
|
|
||||||
|
|
@ -2,22 +2,25 @@
|
||||||
#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::connect_shader(const Shader& shader) {
|
void Mesh::apply_textures(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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,5 +68,5 @@ struct Mesh {
|
||||||
|
|
||||||
void draw(Shader &shader);
|
void draw(Shader &shader);
|
||||||
void setup_mesh();
|
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);
|
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);
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,12 @@
|
||||||
#include "dbc.hpp"
|
#include "dbc.hpp"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
void Scene::updateDelta() {
|
void Scene::update() {
|
||||||
float currentFrame = glfwGetTime();
|
float currentFrame = glfwGetTime();
|
||||||
deltaTime = currentFrame - lastFrame;
|
deltaTime = currentFrame - lastFrame;
|
||||||
lastFrame = currentFrame;
|
lastFrame = currentFrame;
|
||||||
}
|
|
||||||
|
|
||||||
void Scene::configure() {
|
camera.update(deltaTime);
|
||||||
// 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)
|
||||||
|
|
@ -38,8 +33,6 @@ 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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,7 @@ struct Scene {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateDelta();
|
void update();
|
||||||
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();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue