This commit is contained in:
Claire Schwarzer 2026-07-09 18:38:46 +02:00
parent dc5654ba9a
commit 3ffed086b1
7 changed files with 54 additions and 9 deletions

BIN
assets/DefaultTexture.jpg (Stored with Git LFS)

Binary file not shown.

View file

@ -90,9 +90,8 @@ void main()
vec3 viewDir = normalize(viewPos - FragPos);
vec3 albedo = calcTextures();
albedo = vec3(1,1,1);
//result += calcDirectLight(dirLight, norm, viewDir, albedo);
result += calcDirectLight(dirLight, norm, viewDir, albedo);
for(int i = 0; i < numberOfPointLights; i++){
if (pointLights[i].disabled) continue;

View file

@ -96,4 +96,9 @@ namespace engine::Backend
void scroll_callback(GLFWwindow* window2, double xoffset, double yoffset)
{
}
GLFWwindow* getWindow()
{
return window;
}
}

View file

@ -18,4 +18,6 @@ namespace engine::Backend
bool Init(const char* title, int width, int height);
void Cleanup();
GLFWwindow* getWindow();
}

View file

@ -187,7 +187,7 @@ vector<Texture> Model::loadMaterialTextures(aiMaterial *mat, aiTextureType type,
string defaultPath = "DefaultTexture.jpg";
Texture texture;
texture.id = TextureFromFile(defaultPath.c_str(), "assets/");
texture.id = TextureFromFile(defaultPath.c_str(), "assets");
texture.type = typeName;
texture.path = defaultPath;
textures.push_back(texture);
@ -201,8 +201,7 @@ vector<Texture> Model::loadMaterialTextures(aiMaterial *mat, aiTextureType type,
unsigned inline int TextureFromFile(const char *path, const string &directory, bool gamma)
{
string filename = string(path);
filename = directory + '/' + filename;
string filename = directory + '/' + path;
unsigned int textureID;
glGenTextures(1, &textureID);
@ -232,7 +231,8 @@ unsigned inline int TextureFromFile(const char *path, const string &directory, b
}
else
{
std::cout << "Texture failed to load at path: " << path << std::endl;
std::cout << "Texture failed to load at path: " << filename << std::endl;
std::cerr << "STB Reason: " << stbi_failure_reason() << "\n";
stbi_image_free(data);
}

View file

@ -3,7 +3,6 @@
#include <iostream>
#include <glad/glad.h>
#define STB_IMAGE_IMPLEMENTATION
#include <stb/stb_image.h>
Texture::Texture(const char* texturePath, bool flip)

View file

@ -4,10 +4,14 @@
#include <engine/Backend/Model.h>
#include <glad/glad.h>
#include <glfw/include/GLFW/glfw3.h>
#include <optional>
#include <iostream>
#include <glm/gtc/matrix_transform.hpp>
#include "engine/Backend/Backend.h"
namespace game
{
const int SCREEN_WIDTH = 1366;
@ -26,9 +30,19 @@ namespace game
shader.emplace("assets/shaders/basicVertex.vert", "assets/shaders/basicFragment.frag");
shader->Use();
shader->setInt("ourTexture", 0);
shader->setInt("material.diffuse", 0);
shader->setInt("material.specular", 1);
shader->setInt("numberOfPointLights", 1);
shader->setInt("numberOfSpotLights", 1);
camera.emplace(glm::vec3(0.0f, 0.0f, 0.0f));
model.emplace("assets/models/sponza/Sponza.gltf");
glfwSetInputMode(engine::Backend::getWindow(), GLFW_CURSOR, GLFW_CURSOR_DISABLED);
glfwSetInputMode(engine::Backend::getWindow(), GLFW_RAW_MOUSE_MOTION, GLFW_TRUE);
return true;
}
@ -40,6 +54,32 @@ namespace game
shader->Use();
camera->Update(shader.value(), SCREEN_WIDTH, SCREEN_HEIGHT);
shader->setFloat("material.shininess", 32.0f);
shader->setVec3("dirLight.direction", -0.2f, -1.0f, -0.3f);
shader->setVec3("dirLight.ambient", 0.05f, 0.05f, 0.05f);
shader->setVec3("dirLight.diffuse", 0.8f, 0.8f, 0.8f);
shader->setVec3("dirLight.specular", 0.8f, 0.8f, 0.8f);
shader->setVec3("pointLights[0].position", -1.88f, 8.45f, -0.98f);
shader->setVec3("pointLights[0].ambient", 0.05f, 0.05f, 0.05f);
shader->setVec3("pointLights[0].diffuse", 1.0f, 0.7f, 0.4f);
shader->setVec3("pointLights[0].specular", 1.0f, 1.0f, 1.0f);
shader->setFloat("pointLights[0].constant", 1.0f);
shader->setFloat("pointLights[0].linear", 0.09f);
shader->setFloat("pointLights[0].quadratic", 0.032f);
shader->setVec3("spotLights[0].position", camera->position);
shader->setVec3("spotLights[0].direction", camera->front);
shader->setVec3("spotLights[0].ambient", 0.0f, 0.0f, 0.0f);
shader->setVec3("spotLights[0].diffuse", 1.0f, 1.0f, 1.0f);
shader->setVec3("spotLights[0].specular", 1.0f, 1.0f, 1.0f);
shader->setFloat("spotLights[0].constant", 1.0f);
shader->setFloat("spotLights[0].linear", 0.09f);
shader->setFloat("spotLights[0].quadratic", 0.032f);
shader->setFloat("spotLights[0].cutOff", glm::cos(glm::radians(12.5f)));
shader->setFloat("spotLights[0].outerCutOff", glm::cos(glm::radians(15.0f)));
}
void Render()