Khaotic Engine Reborn
Loading...
Searching...
No Matches
Skybox.cpp
1#include "Skybox.h"
2
6
7Skybox::~Skybox()
8{
9 for (auto& texture : textures)
10 {
11 if (texture)
12 {
13 texture->Release();
14 texture = nullptr;
15 }
16 }
17 textures.clear();
18 translations.clear();
19}
20
22{
23 m_d3dClassRef = d3dClassRef;
24}
25
27{
28 Logger::Get().Log("Construct skybox", __FILE__, __LINE__, Logger::LogLevel::Initialize);
29
30 char modelFilename[128];
31 strcpy_s(modelFilename, "assets/Model/OBJ/skysphere.obj");
32
33 std::vector<std::wstring> skyboxTextures = {
34 L"assets/Skybox/skybox.png",
35 };
36
37 TextureContainer SkyboxTextures;
38
39 // Load the textures
40 for (const auto& textureFilename : skyboxTextures)
41 {
42 ID3D11ShaderResourceView* texture = nullptr;
43 HRESULT result = DirectX::CreateWICTextureFromFile(m_d3dClassRef->get_device(), m_d3dClassRef->get_device_context(), textureFilename.c_str(), nullptr, &texture);
44 if (FAILED(result))
45 {
46 Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
47 return nullptr;
48 }
49 SkyboxTextures.diffuse.push_back(texture);
50
51 }
52
53 // Create the model object
54 m_Skybox = new object(*app);
55 HRESULT result = m_Skybox->Initialize(m_d3dClassRef->get_device(), m_d3dClassRef->get_device_context(), modelFilename, SkyboxTextures);
56 if (!result)
57 {
58 Logger::Get().Log("Could not initialize the skybox model object", __FILE__, __LINE__, Logger::LogLevel::Error);
59 delete m_Skybox;
60 return nullptr;
61 }
62 m_Skybox->SetTranslateMatrix(XMMatrixTranslation(0.0f, 0.0f, 0.0f)); // Set the initial translation of the skybox
63 m_Skybox->SetActiveShader(ShaderType::SKYBOX);
64
65 return m_Skybox; // Return the constructed skybox object
66}
static Logger & Get()
Definition Logger.h:20
void Log(const std::string &message, const std::string &fileName, int lineNumber, LogLevel level=LogLevel::Info)
Definition Logger.h:158
object * ConstructSkybox(application_class *app)
Definition Skybox.cpp:26
Skybox()
Constructor for the Skybox class. Initializes the skybox with a reference to the d_3d_class instance.
Definition Skybox.cpp:3
void Initialize(d_3d_class *d3dClassRef)
Definition Skybox.cpp:21
ID3D11Device * get_device()
Gets the Direct3D device.
ID3D11DeviceContext * get_device_context()
Gets the Direct3D device context.