started fixing stuff with model imports

This commit is contained in:
2026-05-03 00:08:13 -05:00
parent 782bbcbadc
commit 68020255d0
13 changed files with 199571 additions and 81 deletions

View File

@@ -68,6 +68,7 @@ int main() {
}
ModelLoader::models["cube"] = ModelLoader::load_from_file("./resources/cube.obj");
ModelLoader::models["backpack"] = ModelLoader::load_from_file("./resources/backpack/backpack.obj");
loop();
@@ -132,11 +133,13 @@ void load_gl()
glfwGetFramebufferSize(gWindow, &fbWidth, &fbHeight);
glViewport(0, 0, fbWidth, fbHeight);
}
glEnable(GL_DEPTH_TEST);
}
void init_camera()
{
cameraPosition = glm::vec3{0, 5, 5};
cameraPosition = glm::vec3{5, 0, 5};
auto cameraTarget = glm::vec3{0, 0, 0};
auto behind = glm::normalize(cameraPosition - cameraTarget);
@@ -153,49 +156,42 @@ void loop() {
Texture* defaultSpecular = TextureLoader::textures["default_specular"].get();
while (!glfwWindowShouldClose(gWindow)) {
auto modelMatrix = glm::identity<glm::mat4>();
auto model = glm::identity<glm::mat4>();
glfwPollEvents();
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ShaderProgram* shader = ShaderLoader::shaders["phong_shader"].get();
Model* model = ModelLoader::models["cube"].get();
const Model* cube = ModelLoader::models["cube"].get();
const Model* backpack = ModelLoader::models["backpack"].get();
if (shader && model) {
Material* mat = model->materials[0].get();
if (shader && backpack) {
shader->bind();
shader->setMat4("projection", projection);
shader->setMat4("view", view);
shader->setMat4("model", modelMatrix);
shader->setMat4("model", model);
shader->setVec3("viewPosition", cameraPosition);
if (mat) {
shader->setVec3("phongAmbient", mat->phong.ambient);
shader->setVec3("phongDiffuse", mat->phong.diffuse);
shader->setVec3("phongSpecular", mat->phong.specular);
shader->setFloat("phongShininess", mat->phong.shininess);
}
shader->setVec3("phongAmbient", glm::vec3(0.3f, 0.3f, 0.3f));
shader->setVec3("phongDiffuse", glm::vec3(0.8f, 0.8f, 0.8f));
shader->setVec3("phongSpecular", glm::vec3(1.0f, 1.0f, 1.0f));
shader->setFloat("phongShininess", 32.0f);
shader->setVec3("lightPosition", glm::vec3(5.f, 5.f, 5.f));
shader->setVec3("lightAmbient", glm::vec3{.1f, .1f, .1f});
shader->setVec3("lightDiffuse", glm::vec3{.8f, .8f, .8f});
shader->setVec3("lightSpecular", glm::vec3{1.f, 1.f, 1.f});
shader->setVec3("lightDirection", glm::vec3(0, 1, 0));
shader->setVec3("lightAmbient", glm::vec3(0.3f, 0.3f, 0.3f));
shader->setVec3("lightDiffuse", glm::vec3(1.0f, 1.0f, 1.0f));
shader->setVec3("lightSpecular", glm::vec3(1.0f, 1.0f, 1.0f));
glActiveTexture(GL_TEXTURE0);
defaultDiffuse->bind();
shader->setInt("diffuse1", 0);
glActiveTexture(GL_TEXTURE1);
defaultSpecular->bind();
shader->setInt("specular1", 1);
for (auto mesh: model->meshes) {
for (const auto& mesh: backpack->meshes) {
glBindVertexArray(mesh.get()->vao);
glDrawElements(GL_TRIANGLES, mesh->numIndices, GL_UNSIGNED_INT, 0);
}
glBindVertexArray(0);
ShaderProgram::unbind();
}
glfwSwapBuffers(gWindow);