Minor Update - Gestion des Texture Update

Feat :

+ Utilisation de vector pour stocker les texture filename
~ Refonte du chargement des textures
This commit is contained in:
2024-04-12 17:11:06 +02:00
parent 42226741ce
commit aa4f1146b7
6 changed files with 54 additions and 102 deletions

View File

@@ -41,11 +41,12 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
try
{
char mouseString1[32], mouseString2[32], mouseString3[32];
char modelFilename[128], textureFilename1[128], textureFilename2[128], textureFilename3[128], textureFilename4[128], textureFilename5[128], textureFilename6[128], renderString[32];
char modelFilename[128], renderString[32];
char bitmapFilename[128];
char spriteFilename[128];
char fpsString[32];
bool result;
std::vector<std::string> Filename;
m_screenWidth = screenWidth;
m_screenHeight = screenHeight;
@@ -169,18 +170,17 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
strcpy_s(modelFilename, "cube.txt");
// Set the file name of the textures.
strcpy_s(textureFilename1, "stone01.tga");
strcpy_s(textureFilename2, "normal01.tga");
strcpy_s(textureFilename3, "spec02.tga");
strcpy_s(textureFilename4, "alpha01.tga");
strcpy_s(textureFilename5, "light01.tga");
strcpy_s(textureFilename6, "moss01.tga");
Filename.push_back("stone01.tga");
Filename.push_back("normal01.tga");
Filename.push_back("spec02.tga");
Filename.push_back("alpha01.tga");
Filename.push_back("light01.tga");
Filename.push_back("moss01.tga");
// Create and initialize the model object.
m_Model = new ModelClass;
result = m_Model->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename1, textureFilename2, textureFilename3, textureFilename4,
textureFilename5, textureFilename6);
result = m_Model->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, Filename);
if (!result)
{
logger.Log("Could not initialize the model object", __FILE__, __LINE__, Logger::LogLevel::Error);
@@ -1168,12 +1168,7 @@ void ApplicationClass::GenerateTerrain()
logger.Log("Generating terrain", __FILE__, __LINE__);
char modelFilename[128];
char textureFilename1[128];
char textureFilename2[128];
char textureFilename3[128];
char textureFilename4[128];
char textureFilename5[128];
char textureFilename6[128];
std::vector<string> Filename;
XMMATRIX scaleMatrix;
float scaleX, scaleY, scaleZ;
@@ -1186,12 +1181,13 @@ void ApplicationClass::GenerateTerrain()
// Set the file name of the model.
strcpy_s(modelFilename, "plane.txt");
strcpy_s(textureFilename1, "stone01.tga");
strcpy_s(textureFilename2, "normal01.tga");
strcpy_s(textureFilename3, "spec02.tga");
strcpy_s(textureFilename4, "alpha01.tga");
strcpy_s(textureFilename5, "light01.tga");
strcpy_s(textureFilename6, "moss01.tga");
Filename.push_back("stone01.tga");
Filename.push_back("normal01.tga");
Filename.push_back("spec02.tga");
Filename.push_back("alpha01.tga");
Filename.push_back("light01.tga");
Filename.push_back("moss01.tga");
// for loop to generate terrain chunks for a 10x10 grid
for (int i = 0; i < 10; i++)
@@ -1199,7 +1195,7 @@ void ApplicationClass::GenerateTerrain()
for (int j = 0; j < 10; j++)
{
Object* newTerrain = new Object();
newTerrain->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename1, textureFilename2, textureFilename3, textureFilename4, textureFilename5, textureFilename6);
newTerrain->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, Filename);
newTerrain->SetScaleMatrix(scaleMatrix);
@@ -1218,12 +1214,7 @@ void ApplicationClass::AddKobject(WCHAR* filepath)
logger.Log("Adding object", __FILE__, __LINE__);
char modelFilename[128];
char textureFilename1[128];
char textureFilename2[128];
char textureFilename3[128];
char textureFilename4[128];
char textureFilename5[128];
char textureFilename6[128];
vector<string> Filename;
filesystem::path p(filepath);
string filename = p.stem().string();
@@ -1233,15 +1224,15 @@ void ApplicationClass::AddKobject(WCHAR* filepath)
// Set the name of the texture file that we will be loading.
strcpy_s(textureFilename1, "stone01.tga");
strcpy_s(textureFilename2, "normal01.tga");
strcpy_s(textureFilename3, "spec02.tga");
strcpy_s(textureFilename4, "alpha01.tga");
strcpy_s(textureFilename5, "light01.tga");
strcpy_s(textureFilename6, "moss01.tga");
Filename.push_back("stone01.tga");
Filename.push_back("normal01.tga");
Filename.push_back("spec02.tga");
Filename.push_back("alpha01.tga");
Filename.push_back("light01.tga");
Filename.push_back("moss01.tga");
Object* newObject = new Object();
newObject->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename1, textureFilename2, textureFilename3, textureFilename4, textureFilename5, textureFilename6);
newObject->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, Filename);
newObject->SetTranslateMatrix(XMMatrixTranslation(0.0f, 0.0f, 0.0f));
newObject->SetName(filename);
@@ -1255,27 +1246,23 @@ void ApplicationClass::AddCube()
logger.Log("Adding cube", __FILE__, __LINE__);
char modelFilename[128];
char textureFilename1[128];
char textureFilename2[128];
char textureFilename3[128];
char textureFilename4[128];
char textureFilename5[128];
char textureFilename6[128];
vector<string> Filename;
// Set the file name of the model.
strcpy_s(modelFilename, "cube.txt");
// Set the name of the texture file that we will be loading.
strcpy_s(textureFilename1, "stone01.tga");
strcpy_s(textureFilename2, "normal01.tga");
strcpy_s(textureFilename3, "spec02.tga");
strcpy_s(textureFilename4, "alpha01.tga");
strcpy_s(textureFilename5, "light01.tga");
strcpy_s(textureFilename6, "moss01.tga");
Filename.push_back("stone01.tga");
Filename.push_back("normal01.tga");
Filename.push_back("spec02.tga");
Filename.push_back("alpha01.tga");
Filename.push_back("light01.tga");
Filename.push_back("moss01.tga");
static int cubeCount = 0;
float position = cubeCount * 2.0f;
Object* newCube = new Object();
newCube->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename1, textureFilename2, textureFilename3, textureFilename4, textureFilename5, textureFilename6);
newCube->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, Filename);
newCube->SetTranslateMatrix(XMMatrixTranslation(position, 0.0f, 0.0f));