2d rendering

This commit is contained in:
StratiX0
2024-03-26 12:59:46 +01:00
parent ccb666faaf
commit 4f4e4bca44
11 changed files with 1005 additions and 2 deletions

View File

@@ -7,6 +7,8 @@ ApplicationClass::ApplicationClass()
m_Model = 0;
m_LightShader = 0;
m_Light = 0;
m_TextureShader = 0;
m_Bitmap = 0;
}
@@ -25,6 +27,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
char modelFilename[128];
char outputModelFilename[128];
char textureFilename[128];
char bitmapFilename[128];
bool result;
@@ -54,6 +57,28 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
m_Camera->SetPosition(0.0f, 0.0f, -10.0f);
m_Camera->SetRotation(0.0f, 0.0f, 0.0f);
// Create and initialize the texture shader object.
m_TextureShader = new TextureShaderClass;
result = m_TextureShader->Initialize(m_Direct3D->GetDevice(), hwnd);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the texture shader object.", L"Error", MB_OK);
return false;
}
// Set the file name of the bitmap file.
strcpy_s(bitmapFilename, "stone01.tga");
// Create and initialize the bitmap object.
m_Bitmap = new BitmapClass;
result = m_Bitmap->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), screenWidth, screenHeight, bitmapFilename, 50, 50);
if (!result)
{
return false;
}
// Set the file name of the model.
strcpy_s(modelFilename, "sphere.obj");
@@ -124,6 +149,22 @@ void ApplicationClass::Shutdown()
m_Model = 0;
}
// Release the bitmap object.
if (m_Bitmap)
{
m_Bitmap->Shutdown();
delete m_Bitmap;
m_Bitmap = 0;
}
// Release the texture shader object.
if (m_TextureShader)
{
m_TextureShader->Shutdown();
delete m_TextureShader;
m_TextureShader = 0;
}
// Release the camera object.
if (m_Camera)
{
@@ -180,7 +221,7 @@ bool ApplicationClass::Frame()
bool ApplicationClass::Render(float rotation, float x, float y, float z)
{
XMMATRIX worldMatrix, viewMatrix, projectionMatrix, rotateMatrix, translateMatrix, scaleMatrix, srMatrix;
XMMATRIX worldMatrix, viewMatrix, orthoMatrix, projectionMatrix, rotateMatrix, translateMatrix, scaleMatrix, srMatrix;
bool result;
@@ -194,6 +235,26 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z)
m_Direct3D->GetWorldMatrix(worldMatrix);
m_Camera->GetViewMatrix(viewMatrix);
m_Direct3D->GetProjectionMatrix(projectionMatrix);
m_Direct3D->GetOrthoMatrix(orthoMatrix);
// Turn off the Z buffer to begin all 2D rendering.
m_Direct3D->TurnZBufferOff();
// Put the bitmap vertex and index buffers on the graphics pipeline to prepare them for drawing.
result = m_Bitmap->Render(m_Direct3D->GetDeviceContext());
if (!result)
{
return false;
}
m_Bitmap->SetRenderLocation(300, 50);
// Render the bitmap with the texture shader.
result = m_TextureShader->Render(m_Direct3D->GetDeviceContext(), m_Bitmap->GetIndexCount(), worldMatrix, viewMatrix, orthoMatrix, m_Bitmap->GetTexture());
if (!result)
{
return false;
}
scaleMatrix = XMMatrixScaling(0.5f, 0.5f, 0.5f); // Build the scaling matrix.
rotateMatrix = XMMatrixRotationY(rotation); // Build the rotation matrix.
@@ -233,6 +294,9 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z)
return false;
}
// Turn the Z buffer back on now that all 2D rendering has completed.
m_Direct3D->TurnZBufferOn();
// Present the rendered scene to the screen.
m_Direct3D->EndScene();