Global light

This commit is contained in:
2024-01-27 20:37:52 -05:00
parent fbca31de91
commit 932c8ad05d
4 changed files with 19 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
#include <types/vertex.h>
#include <types/texture.h>
#include <types/entity/entity.h>
#include <J3ML/LinearAlgebra/Vector4.h>
// TODO: Move data to Entity / or rename to DataModelEntry
struct ByteArray
@@ -38,9 +39,13 @@ public:
};
class World : public DataModel {
private:
LinearAlgebra::Vector4 globalLight= {0,0,0,0};
public:
std::string name;
World() : DataModel() {}
void setAmbientLight(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
LinearAlgebra::Vector4 getAmbientLight();
std::string name;
std::vector<VertexArray> geometryList;
std::vector<Texture> textureList;
};

View File

@@ -47,7 +47,7 @@ void Engine::initGL()
//glEnable(GL_BLEND);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
//glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_VERTEX_ARRAY);
//glDepthRange(-0.5f,0.5f);

View File

@@ -27,6 +27,7 @@ void Render::pre_render() {
skybox->draw = true;
skybox->angle = {0,0,0};
skybox->SetParent(engine->world);
engine->world->setAmbientLight(0.6, 0.6, 0.6, 1);
}
//std::cout << engine->frameCount << std::endl;
engine->window->pollEvents();

View File

@@ -114,4 +114,14 @@ Entity *Entity::GetFamilyTreeRoot() const {
if (parent->GetParent() == nullptr)
return parent;
return parent->GetFamilyTreeRoot();
}
}
void World::setAmbientLight(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
GLfloat ambient[4] = {red, green, blue, alpha};
globalLight.x = red; globalLight.y = green; globalLight.z = blue; globalLight.w = alpha;
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
}
LinearAlgebra::Vector4 World::getAmbientLight() {
return globalLight;
}