[FEATURE] single light support

This commit is contained in:
Menno
2021-05-21 08:36:04 +02:00
parent 01571d191f
commit 9e9d50da9e
12 changed files with 132 additions and 13 deletions

View File

@@ -17,12 +17,13 @@ namespace render_engine
/*
This function will generate a Model from vertex positions, textureCoordinates and indices.
*/
struct models::RawModel LoadToVAO(std::vector<float>& positions, std::vector<float>& texture_coords, std::vector<unsigned int>& indices)
models::RawModel LoadToVAO(std::vector<float>& positions, std::vector<float>& texture_coords, std::vector<float>& normals, std::vector<unsigned int>& indices)
{
GLuint vao_id = CreateVao();
BindIndicesBuffer(indices);
StoreDataInAttributeList(0, 3, positions);
StoreDataInAttributeList(1, 2, texture_coords);
StoreDataInAttributeList(2, 3, normals);
glBindVertexArray(0);
return { vao_id, static_cast<int>(indices.size()) };
}

View File

@@ -11,7 +11,7 @@ namespace render_engine
/*
This function generates a model from model data.
*/
struct models::RawModel LoadToVAO(std::vector<float>& positions, std::vector<float>& texture_coords, std::vector<unsigned int>& indices);
models::RawModel LoadToVAO(std::vector<float>& positions, std::vector<float>& texture_coords, std::vector<float>& normals, std::vector<unsigned int>& indices);
/*
Loads a texture from a file into openGL using stb_image.h

View File

@@ -17,9 +17,14 @@ namespace render_engine
*/
void Init(shaders::StaticShader& shader)
{
// Faces which are not facing the camera are not rendered
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
const glm::mat4 projectionMatrix =
glm::perspective(glm::radians(FOV), (WINDOW_WIDTH / WINDOW_HEIGT), NEAR_PLANE, FAR_PLANE);
// Load the projectionmatrix into the shader
shader.Start();
shader.LoadProjectionMatrix(projectionMatrix);
shader.Stop();
@@ -41,26 +46,31 @@ namespace render_engine
void Render(entities::Entity& entity, shaders::StaticShader& shader)
{
const models::TexturedModel model = entity.GetModel();
const models::RawModel rawModel = model.raw_model;
const models::RawModel raw_model = model.raw_model;
const models::ModelTexture texture = model.texture;
// Enable the model
glBindVertexArray(rawModel.vao_id);
glBindVertexArray(raw_model.vao_id);
// Enable the inputs for the vertexShader
// Enable the VBO's from the model (VAO)
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
// Load the transformation of the model into the shader
const glm::mat4 modelMatrix = toolbox::CreateModelMatrix(entity.GetPosition(), entity.GetRotation(), entity.GetScale());
shader.LoadModelMatrix(modelMatrix);
shader.LoadShineVariables(texture.shine_damper, texture.reflectivity);
// Draw the model
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, model.texture.texture_id);
glDrawElements(GL_TRIANGLES, rawModel.vertex_count, GL_UNSIGNED_INT, 0);
glDrawElements(GL_TRIANGLES, raw_model.vertex_count, GL_UNSIGNED_INT, 0);
// Disable the VBO's and model
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
glBindVertexArray(0);
}
}

View File

@@ -125,5 +125,5 @@ models::RawModel LoadObjModel(std::string file_name)
vertex_array[p++] = vertex.z;
}
return render_engine::loader::LoadToVAO( vertex_array, texture_array, indices);
return render_engine::loader::LoadToVAO( vertex_array, texture_array, normal_array, indices);
}