textures du model
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Filename: modelclass.cpp
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include "modelclass.h"
|
||||
|
||||
|
||||
@@ -8,6 +5,7 @@ ModelClass::ModelClass()
|
||||
{
|
||||
m_vertexBuffer = 0;
|
||||
m_indexBuffer = 0;
|
||||
m_Texture = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +18,7 @@ ModelClass::~ModelClass()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool ModelClass::Initialize(ID3D11Device* device)
|
||||
bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* textureFilename)
|
||||
{
|
||||
bool result;
|
||||
|
||||
@@ -32,6 +29,12 @@ bool ModelClass::Initialize(ID3D11Device* device)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Load the texture for this model.
|
||||
result = LoadTexture(device, deviceContext, textureFilename);
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -39,6 +42,9 @@ bool ModelClass::Initialize(ID3D11Device* device)
|
||||
|
||||
void ModelClass::Shutdown()
|
||||
{
|
||||
// Release the model texture.
|
||||
ReleaseTexture();
|
||||
|
||||
// Shutdown the vertex and index buffers.
|
||||
ShutdownBuffers();
|
||||
|
||||
@@ -60,6 +66,11 @@ int ModelClass::GetIndexCount()
|
||||
return m_indexCount;
|
||||
}
|
||||
|
||||
ID3D11ShaderResourceView* ModelClass::GetTexture()
|
||||
{
|
||||
return m_Texture->GetTexture();
|
||||
}
|
||||
|
||||
|
||||
bool ModelClass::InitializeBuffers(ID3D11Device* device)
|
||||
{
|
||||
@@ -71,39 +82,42 @@ bool ModelClass::InitializeBuffers(ID3D11Device* device)
|
||||
|
||||
|
||||
// Set the number of vertices in the vertex array.
|
||||
m_vertexCount = 3;
|
||||
m_vertexCount = 6;
|
||||
|
||||
// Set the number of indices in the index array.
|
||||
m_indexCount = 3;
|
||||
m_indexCount = 6;
|
||||
|
||||
// Create the vertex array.
|
||||
vertices = new VertexType[m_vertexCount];
|
||||
if (!vertices)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the index array.
|
||||
indices = new unsigned long[m_indexCount];
|
||||
if (!indices)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load the vertex array with data.
|
||||
vertices[0].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); // Bottom left.
|
||||
vertices[0].color = XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
vertices[0].texture = XMFLOAT2(0.0f, 1.0f);
|
||||
|
||||
vertices[1].position = XMFLOAT3(0.0f, 1.0f, 0.0f); // Top middle.
|
||||
vertices[1].color = XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
vertices[1].position = XMFLOAT3(1.0f, 1.0f, 0.0f); // Top Right.
|
||||
vertices[1].texture = XMFLOAT2(0.5f, 0.0f);
|
||||
|
||||
vertices[2].position = XMFLOAT3(1.0f, -1.0f, 0.0f); // Bottom right.
|
||||
vertices[2].color = XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
vertices[2].texture = XMFLOAT2(1.0f, 1.0f);
|
||||
|
||||
vertices[3].position = XMFLOAT3(-1.0f, 1.0f, 0.0f); // Top left.
|
||||
vertices[3].texture = XMFLOAT2(0.0f, 1.0f);
|
||||
|
||||
vertices[4].position = XMFLOAT3(1.0f, 1.0f, 0.0f); // Top right.
|
||||
vertices[4].texture = XMFLOAT2(0.5f, 0.0f);
|
||||
|
||||
vertices[5].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); // Bottom left.
|
||||
vertices[5].texture = XMFLOAT2(1.0f, 1.0f);
|
||||
|
||||
// Load the index array with data.
|
||||
indices[0] = 0; // Bottom left.
|
||||
indices[1] = 1; // Top middle.
|
||||
indices[2] = 2; // Bottom right.
|
||||
indices[3] = 3; // Top left.
|
||||
indices[4] = 4; // Top right.
|
||||
indices[5] = 5; // Bottom left.
|
||||
|
||||
// Set up the description of the static vertex buffer.
|
||||
vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||
@@ -195,5 +209,35 @@ void ModelClass::RenderBuffers(ID3D11DeviceContext* deviceContext)
|
||||
// Set the type of primitive that should be rendered from this vertex buffer, in this case triangles.
|
||||
deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool ModelClass::LoadTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* filename)
|
||||
{
|
||||
bool result;
|
||||
|
||||
|
||||
// Create and initialize the texture object.
|
||||
m_Texture = new TextureClass;
|
||||
|
||||
result = m_Texture->Initialize(device, deviceContext, filename);
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ModelClass::ReleaseTexture()
|
||||
{
|
||||
// Release the texture object.
|
||||
if (m_Texture)
|
||||
{
|
||||
m_Texture->Shutdown();
|
||||
delete m_Texture;
|
||||
m_Texture = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
Reference in New Issue
Block a user