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:
parent
42226741ce
commit
aa4f1146b7
@ -329,7 +329,7 @@ void SpriteClass::RenderBuffers(ID3D11DeviceContext* deviceContext)
|
||||
|
||||
bool SpriteClass::LoadTextures(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* filename)
|
||||
{
|
||||
char textureFilename[128];
|
||||
std::string textureFilename;
|
||||
std::ifstream fin;
|
||||
int i, j;
|
||||
char input;
|
||||
|
@ -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));
|
||||
|
||||
|
@ -19,8 +19,7 @@ ModelClass::~ModelClass()
|
||||
{
|
||||
}
|
||||
|
||||
bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename, char* textureFilename1, char* textureFilename2, char* textureFilename3,
|
||||
char* textureFilename4, char* textureFilename5, char* textureFilename6)
|
||||
bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename, vector<string> filename)
|
||||
{
|
||||
logger.Log("Initializing model class", __FILE__, __LINE__);
|
||||
|
||||
@ -45,7 +44,7 @@ bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCon
|
||||
return false;
|
||||
}
|
||||
// Load the textures for this model.
|
||||
result = LoadTextures(device, deviceContext, textureFilename1, textureFilename2, textureFilename3, textureFilename4, textureFilename5, textureFilename6);
|
||||
result = LoadTextures(device, deviceContext, filename);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to load textures", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
@ -220,57 +219,23 @@ void ModelClass::RenderBuffers(ID3D11DeviceContext* deviceContext)
|
||||
}
|
||||
|
||||
|
||||
bool ModelClass::LoadTextures(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* filename1, char* filename2, char* filename3, char* filename4, char* filename5,
|
||||
char* filename6)
|
||||
bool ModelClass::LoadTextures(ID3D11Device* device, ID3D11DeviceContext* deviceContext, vector<string> textureFile)
|
||||
{
|
||||
logger.Log("Loading textures", __FILE__, __LINE__);
|
||||
|
||||
bool result;
|
||||
|
||||
|
||||
// Create and initialize the texture object array.
|
||||
m_Textures = new TextureClass[6];
|
||||
m_Textures = new TextureClass[textureFile.size()];
|
||||
|
||||
result = m_Textures[0].Initialize(device, deviceContext, filename1);
|
||||
if (!result)
|
||||
for (int i = 0; i < textureFile.size(); i++)
|
||||
{
|
||||
logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
result = m_Textures[1].Initialize(device, deviceContext, filename2);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
result = m_Textures[2].Initialize(device, deviceContext, filename3);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
result = m_Textures[3].Initialize(device, deviceContext, filename4);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
result = m_Textures[4].Initialize(device, deviceContext, filename5);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
result = m_Textures[5].Initialize(device, deviceContext, filename6);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
result = m_Textures[i].Initialize(device, deviceContext, textureFile[i]);
|
||||
if (!result)
|
||||
{
|
||||
logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
logger.Log("Textures loaded", __FILE__, __LINE__);
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
ModelClass(const ModelClass&);
|
||||
~ModelClass();
|
||||
|
||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*, char*, char*, char*, char*, char*, char*);
|
||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*, vector<string>);
|
||||
void Shutdown();
|
||||
void Render(ID3D11DeviceContext*);
|
||||
|
||||
@ -93,7 +93,7 @@ private:
|
||||
bool InitializeBuffers(ID3D11Device*);
|
||||
void ShutdownBuffers();
|
||||
void RenderBuffers(ID3D11DeviceContext*);
|
||||
bool LoadTextures(ID3D11Device*, ID3D11DeviceContext*, char*, char*, char*, char*, char*, char*);
|
||||
bool LoadTextures(ID3D11Device*, ID3D11DeviceContext*, vector<string> filename);
|
||||
void ReleaseTextures();
|
||||
|
||||
bool LoadModel(char*);
|
||||
|
@ -17,7 +17,7 @@ TextureClass::~TextureClass()
|
||||
{
|
||||
}
|
||||
|
||||
bool TextureClass::Initialize(ID3D11Device * device, ID3D11DeviceContext * deviceContext, char* filename)
|
||||
bool TextureClass::Initialize(ID3D11Device * device, ID3D11DeviceContext * deviceContext, std::string filename)
|
||||
{
|
||||
logger.Log(("Iinitializing texture: %s", filename), __FILE__, __LINE__);
|
||||
|
||||
@ -113,7 +113,7 @@ ID3D11ShaderResourceView* TextureClass::GetTexture()
|
||||
return m_textureView;
|
||||
}
|
||||
|
||||
bool TextureClass::LoadTarga(char* filename)
|
||||
bool TextureClass::LoadTarga(std::string filename)
|
||||
{
|
||||
int error, bpp, imageSize, index, i, j, k;
|
||||
FILE* filePtr;
|
||||
@ -123,7 +123,7 @@ bool TextureClass::LoadTarga(char* filename)
|
||||
|
||||
|
||||
// Open the targa file for reading in binary.
|
||||
error = fopen_s(&filePtr, filename, "rb");
|
||||
error = fopen_s(&filePtr, filename.c_str(), "rb");
|
||||
if (error != 0)
|
||||
{
|
||||
logger.Log("Failed to open targa file", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
TextureClass(const TextureClass&);
|
||||
~TextureClass();
|
||||
|
||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*);
|
||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, std::string);
|
||||
void Shutdown();
|
||||
|
||||
ID3D11ShaderResourceView* GetTexture();
|
||||
@ -39,7 +39,7 @@ public:
|
||||
int GetHeight();
|
||||
|
||||
private:
|
||||
bool LoadTarga(char*);
|
||||
bool LoadTarga(std::string);
|
||||
|
||||
private:
|
||||
unsigned char* m_targaData;
|
||||
|
Loading…
x
Reference in New Issue
Block a user