textures du model
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Filename: applicationclass.cpp
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include "applicationclass.h"
|
||||
|
||||
|
||||
ApplicationClass::ApplicationClass()
|
||||
{
|
||||
m_Direct3D = 0;
|
||||
m_Camera = 0;
|
||||
m_Model = 0;
|
||||
m_ColorShader = 0;
|
||||
m_TextureShader = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,42 +21,53 @@ ApplicationClass::~ApplicationClass()
|
||||
|
||||
bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
||||
{
|
||||
char textureFilename[128];
|
||||
bool result;
|
||||
|
||||
|
||||
// Create and initialize the Direct3D object.
|
||||
// Create the Direct3D object.
|
||||
m_Direct3D = new D3DClass;
|
||||
if (!m_Direct3D)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Initialize the Direct3D object.
|
||||
result = m_Direct3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR);
|
||||
if (!result)
|
||||
{
|
||||
MessageBox(hwnd, L"Could not initialize Direct3D", L"Error", MB_OK);
|
||||
MessageBox(hwnd, L"Could not initialize Direct3D.", L"Error", MB_OK);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the camera object.
|
||||
m_Camera = new CameraClass;
|
||||
if (!m_Camera)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the initial position of the camera.
|
||||
m_Camera->SetPosition(0.0f, 0.0f, -5.0f);
|
||||
|
||||
// Create and initialize the model object.
|
||||
m_Model = new ModelClass;
|
||||
// Set the name of the texture file that we will be loading.
|
||||
strcpy_s(textureFilename, "stone01.tga");
|
||||
|
||||
result = m_Model->Initialize(m_Direct3D->GetDevice());
|
||||
result = m_Model->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), textureFilename);
|
||||
if (!result)
|
||||
{
|
||||
MessageBox(hwnd, L"Could not initialize the model object.", L"Error", MB_OK);
|
||||
return false;
|
||||
}
|
||||
// Create and initialize the texture shader object.
|
||||
m_TextureShader = new TextureShaderClass;
|
||||
|
||||
// Create and initialize the color shader object.
|
||||
m_ColorShader = new ColorShaderClass;
|
||||
|
||||
result = m_ColorShader->Initialize(m_Direct3D->GetDevice(), hwnd);
|
||||
result = m_TextureShader->Initialize(m_Direct3D->GetDevice(), hwnd);
|
||||
if (!result)
|
||||
{
|
||||
MessageBox(hwnd, L"Could not initialize the color shader object.", L"Error", MB_OK);
|
||||
MessageBox(hwnd, L"Could not initialize the texture shader object.", L"Error", MB_OK);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -70,12 +77,12 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
||||
|
||||
void ApplicationClass::Shutdown()
|
||||
{
|
||||
// Release the color shader object.
|
||||
if (m_ColorShader)
|
||||
// Release the texture shader object.
|
||||
if (m_TextureShader)
|
||||
{
|
||||
m_ColorShader->Shutdown();
|
||||
delete m_ColorShader;
|
||||
m_ColorShader = 0;
|
||||
m_TextureShader->Shutdown();
|
||||
delete m_TextureShader;
|
||||
m_TextureShader = 0;
|
||||
}
|
||||
|
||||
// Release the model object.
|
||||
@@ -93,7 +100,7 @@ void ApplicationClass::Shutdown()
|
||||
m_Camera = 0;
|
||||
}
|
||||
|
||||
// Release the Direct3D object.
|
||||
// Release the D3D object.
|
||||
if (m_Direct3D)
|
||||
{
|
||||
m_Direct3D->Shutdown();
|
||||
@@ -140,9 +147,8 @@ bool ApplicationClass::Render()
|
||||
|
||||
// Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
|
||||
m_Model->Render(m_Direct3D->GetDeviceContext());
|
||||
|
||||
// Render the model using the color shader.
|
||||
result = m_ColorShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix);
|
||||
// Render the model using the texture shader.
|
||||
result = m_TextureShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture());
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user