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)
|
bool SpriteClass::LoadTextures(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* filename)
|
||||||
{
|
{
|
||||||
char textureFilename[128];
|
std::string textureFilename;
|
||||||
std::ifstream fin;
|
std::ifstream fin;
|
||||||
int i, j;
|
int i, j;
|
||||||
char input;
|
char input;
|
||||||
|
@ -41,11 +41,12 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
char mouseString1[32], mouseString2[32], mouseString3[32];
|
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 bitmapFilename[128];
|
||||||
char spriteFilename[128];
|
char spriteFilename[128];
|
||||||
char fpsString[32];
|
char fpsString[32];
|
||||||
bool result;
|
bool result;
|
||||||
|
std::vector<std::string> Filename;
|
||||||
|
|
||||||
m_screenWidth = screenWidth;
|
m_screenWidth = screenWidth;
|
||||||
m_screenHeight = screenHeight;
|
m_screenHeight = screenHeight;
|
||||||
@ -169,18 +170,17 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
|||||||
strcpy_s(modelFilename, "cube.txt");
|
strcpy_s(modelFilename, "cube.txt");
|
||||||
|
|
||||||
// Set the file name of the textures.
|
// Set the file name of the textures.
|
||||||
strcpy_s(textureFilename1, "stone01.tga");
|
Filename.push_back("stone01.tga");
|
||||||
strcpy_s(textureFilename2, "normal01.tga");
|
Filename.push_back("normal01.tga");
|
||||||
strcpy_s(textureFilename3, "spec02.tga");
|
Filename.push_back("spec02.tga");
|
||||||
strcpy_s(textureFilename4, "alpha01.tga");
|
Filename.push_back("alpha01.tga");
|
||||||
strcpy_s(textureFilename5, "light01.tga");
|
Filename.push_back("light01.tga");
|
||||||
strcpy_s(textureFilename6, "moss01.tga");
|
Filename.push_back("moss01.tga");
|
||||||
|
|
||||||
// Create and initialize the model object.
|
// Create and initialize the model object.
|
||||||
m_Model = new ModelClass;
|
m_Model = new ModelClass;
|
||||||
|
|
||||||
result = m_Model->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename1, textureFilename2, textureFilename3, textureFilename4,
|
result = m_Model->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, Filename);
|
||||||
textureFilename5, textureFilename6);
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
logger.Log("Could not initialize the model object", __FILE__, __LINE__, Logger::LogLevel::Error);
|
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__);
|
logger.Log("Generating terrain", __FILE__, __LINE__);
|
||||||
|
|
||||||
char modelFilename[128];
|
char modelFilename[128];
|
||||||
char textureFilename1[128];
|
std::vector<string> Filename;
|
||||||
char textureFilename2[128];
|
|
||||||
char textureFilename3[128];
|
|
||||||
char textureFilename4[128];
|
|
||||||
char textureFilename5[128];
|
|
||||||
char textureFilename6[128];
|
|
||||||
|
|
||||||
XMMATRIX scaleMatrix;
|
XMMATRIX scaleMatrix;
|
||||||
float scaleX, scaleY, scaleZ;
|
float scaleX, scaleY, scaleZ;
|
||||||
@ -1186,12 +1181,13 @@ void ApplicationClass::GenerateTerrain()
|
|||||||
|
|
||||||
// Set the file name of the model.
|
// Set the file name of the model.
|
||||||
strcpy_s(modelFilename, "plane.txt");
|
strcpy_s(modelFilename, "plane.txt");
|
||||||
strcpy_s(textureFilename1, "stone01.tga");
|
|
||||||
strcpy_s(textureFilename2, "normal01.tga");
|
Filename.push_back("stone01.tga");
|
||||||
strcpy_s(textureFilename3, "spec02.tga");
|
Filename.push_back("normal01.tga");
|
||||||
strcpy_s(textureFilename4, "alpha01.tga");
|
Filename.push_back("spec02.tga");
|
||||||
strcpy_s(textureFilename5, "light01.tga");
|
Filename.push_back("alpha01.tga");
|
||||||
strcpy_s(textureFilename6, "moss01.tga");
|
Filename.push_back("light01.tga");
|
||||||
|
Filename.push_back("moss01.tga");
|
||||||
|
|
||||||
// for loop to generate terrain chunks for a 10x10 grid
|
// for loop to generate terrain chunks for a 10x10 grid
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
@ -1199,7 +1195,7 @@ void ApplicationClass::GenerateTerrain()
|
|||||||
for (int j = 0; j < 10; j++)
|
for (int j = 0; j < 10; j++)
|
||||||
{
|
{
|
||||||
Object* newTerrain = new Object();
|
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);
|
newTerrain->SetScaleMatrix(scaleMatrix);
|
||||||
|
|
||||||
@ -1218,12 +1214,7 @@ void ApplicationClass::AddKobject(WCHAR* filepath)
|
|||||||
logger.Log("Adding object", __FILE__, __LINE__);
|
logger.Log("Adding object", __FILE__, __LINE__);
|
||||||
|
|
||||||
char modelFilename[128];
|
char modelFilename[128];
|
||||||
char textureFilename1[128];
|
vector<string> Filename;
|
||||||
char textureFilename2[128];
|
|
||||||
char textureFilename3[128];
|
|
||||||
char textureFilename4[128];
|
|
||||||
char textureFilename5[128];
|
|
||||||
char textureFilename6[128];
|
|
||||||
|
|
||||||
filesystem::path p(filepath);
|
filesystem::path p(filepath);
|
||||||
string filename = p.stem().string();
|
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.
|
// Set the name of the texture file that we will be loading.
|
||||||
strcpy_s(textureFilename1, "stone01.tga");
|
Filename.push_back("stone01.tga");
|
||||||
strcpy_s(textureFilename2, "normal01.tga");
|
Filename.push_back("normal01.tga");
|
||||||
strcpy_s(textureFilename3, "spec02.tga");
|
Filename.push_back("spec02.tga");
|
||||||
strcpy_s(textureFilename4, "alpha01.tga");
|
Filename.push_back("alpha01.tga");
|
||||||
strcpy_s(textureFilename5, "light01.tga");
|
Filename.push_back("light01.tga");
|
||||||
strcpy_s(textureFilename6, "moss01.tga");
|
Filename.push_back("moss01.tga");
|
||||||
|
|
||||||
Object* newObject = new Object();
|
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->SetTranslateMatrix(XMMatrixTranslation(0.0f, 0.0f, 0.0f));
|
||||||
newObject->SetName(filename);
|
newObject->SetName(filename);
|
||||||
@ -1255,27 +1246,23 @@ void ApplicationClass::AddCube()
|
|||||||
logger.Log("Adding cube", __FILE__, __LINE__);
|
logger.Log("Adding cube", __FILE__, __LINE__);
|
||||||
|
|
||||||
char modelFilename[128];
|
char modelFilename[128];
|
||||||
char textureFilename1[128];
|
vector<string> Filename;
|
||||||
char textureFilename2[128];
|
|
||||||
char textureFilename3[128];
|
|
||||||
char textureFilename4[128];
|
|
||||||
char textureFilename5[128];
|
|
||||||
char textureFilename6[128];
|
|
||||||
|
|
||||||
// Set the file name of the model.
|
// Set the file name of the model.
|
||||||
strcpy_s(modelFilename, "cube.txt");
|
strcpy_s(modelFilename, "cube.txt");
|
||||||
|
|
||||||
// Set the name of the texture file that we will be loading.
|
// Set the name of the texture file that we will be loading.
|
||||||
strcpy_s(textureFilename1, "stone01.tga");
|
Filename.push_back("stone01.tga");
|
||||||
strcpy_s(textureFilename2, "normal01.tga");
|
Filename.push_back("normal01.tga");
|
||||||
strcpy_s(textureFilename3, "spec02.tga");
|
Filename.push_back("spec02.tga");
|
||||||
strcpy_s(textureFilename4, "alpha01.tga");
|
Filename.push_back("alpha01.tga");
|
||||||
strcpy_s(textureFilename5, "light01.tga");
|
Filename.push_back("light01.tga");
|
||||||
strcpy_s(textureFilename6, "moss01.tga");
|
Filename.push_back("moss01.tga");
|
||||||
|
|
||||||
static int cubeCount = 0;
|
static int cubeCount = 0;
|
||||||
float position = cubeCount * 2.0f;
|
float position = cubeCount * 2.0f;
|
||||||
Object* newCube = new Object();
|
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));
|
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,
|
bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename, vector<string> filename)
|
||||||
char* textureFilename4, char* textureFilename5, char* textureFilename6)
|
|
||||||
{
|
{
|
||||||
logger.Log("Initializing model class", __FILE__, __LINE__);
|
logger.Log("Initializing model class", __FILE__, __LINE__);
|
||||||
|
|
||||||
@ -45,7 +44,7 @@ bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceCon
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Load the textures for this model.
|
// Load the textures for this model.
|
||||||
result = LoadTextures(device, deviceContext, textureFilename1, textureFilename2, textureFilename3, textureFilename4, textureFilename5, textureFilename6);
|
result = LoadTextures(device, deviceContext, filename);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
logger.Log("Failed to load textures", __FILE__, __LINE__, Logger::LogLevel::Error);
|
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,
|
bool ModelClass::LoadTextures(ID3D11Device* device, ID3D11DeviceContext* deviceContext, vector<string> textureFile)
|
||||||
char* filename6)
|
|
||||||
{
|
{
|
||||||
logger.Log("Loading textures", __FILE__, __LINE__);
|
logger.Log("Loading textures", __FILE__, __LINE__);
|
||||||
|
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
|
|
||||||
// Create and initialize the texture object array.
|
// 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);
|
for (int i = 0; i < textureFile.size(); i++)
|
||||||
if (!result)
|
|
||||||
{
|
{
|
||||||
logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
result = m_Textures[i].Initialize(device, deviceContext, textureFile[i]);
|
||||||
return false;
|
if (!result)
|
||||||
}
|
{
|
||||||
|
logger.Log("Failed to initialize texture", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
result = m_Textures[1].Initialize(device, deviceContext, filename2);
|
return false;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Log("Textures loaded", __FILE__, __LINE__);
|
logger.Log("Textures loaded", __FILE__, __LINE__);
|
||||||
|
@ -82,7 +82,7 @@ public:
|
|||||||
ModelClass(const ModelClass&);
|
ModelClass(const ModelClass&);
|
||||||
~ModelClass();
|
~ModelClass();
|
||||||
|
|
||||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*, char*, char*, char*, char*, char*, char*);
|
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*, vector<string>);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
void Render(ID3D11DeviceContext*);
|
void Render(ID3D11DeviceContext*);
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ private:
|
|||||||
bool InitializeBuffers(ID3D11Device*);
|
bool InitializeBuffers(ID3D11Device*);
|
||||||
void ShutdownBuffers();
|
void ShutdownBuffers();
|
||||||
void RenderBuffers(ID3D11DeviceContext*);
|
void RenderBuffers(ID3D11DeviceContext*);
|
||||||
bool LoadTextures(ID3D11Device*, ID3D11DeviceContext*, char*, char*, char*, char*, char*, char*);
|
bool LoadTextures(ID3D11Device*, ID3D11DeviceContext*, vector<string> filename);
|
||||||
void ReleaseTextures();
|
void ReleaseTextures();
|
||||||
|
|
||||||
bool LoadModel(char*);
|
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__);
|
logger.Log(("Iinitializing texture: %s", filename), __FILE__, __LINE__);
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ ID3D11ShaderResourceView* TextureClass::GetTexture()
|
|||||||
return m_textureView;
|
return m_textureView;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextureClass::LoadTarga(char* filename)
|
bool TextureClass::LoadTarga(std::string filename)
|
||||||
{
|
{
|
||||||
int error, bpp, imageSize, index, i, j, k;
|
int error, bpp, imageSize, index, i, j, k;
|
||||||
FILE* filePtr;
|
FILE* filePtr;
|
||||||
@ -123,7 +123,7 @@ bool TextureClass::LoadTarga(char* filename)
|
|||||||
|
|
||||||
|
|
||||||
// Open the targa file for reading in binary.
|
// 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)
|
if (error != 0)
|
||||||
{
|
{
|
||||||
logger.Log("Failed to open targa file", __FILE__, __LINE__, Logger::LogLevel::Error);
|
logger.Log("Failed to open targa file", __FILE__, __LINE__, Logger::LogLevel::Error);
|
||||||
|
@ -30,7 +30,7 @@ public:
|
|||||||
TextureClass(const TextureClass&);
|
TextureClass(const TextureClass&);
|
||||||
~TextureClass();
|
~TextureClass();
|
||||||
|
|
||||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*);
|
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, std::string);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
ID3D11ShaderResourceView* GetTexture();
|
ID3D11ShaderResourceView* GetTexture();
|
||||||
@ -39,7 +39,7 @@ public:
|
|||||||
int GetHeight();
|
int GetHeight();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool LoadTarga(char*);
|
bool LoadTarga(std::string);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned char* m_targaData;
|
unsigned char* m_targaData;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user