#include <Redacted3D/types/entity/skybox.h>
#include <Redacted3D/engine/engine.h>
#include <Redacted3D/types/entity/camera.h>

void Skybox::pre_render() {
    if (engine->world->getActiveCamera() != nullptr)
        position = engine->world->getActiveCamera()->GetPos();
}

void Skybox::render() {
    glPushMatrix();
    glTranslatef(position.x ,position.y, position.z);
    glBindTexture(GL_TEXTURE_2D, getTexture()->id);
    glCullFace(GL_FRONT);
    glScalef(getScale().x, getScale().y, getScale().z);
    getGeometry()->draw();
    glCullFace(GL_BACK);
    glBindTexture(GL_TEXTURE_2D,0);
    glPopMatrix();
}

Skybox::Skybox() {
    name = "skybox";
    setScale(engine->farPlane);
}