1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
{
#include "AppWindow.h"
struct vec3
{
float x, y, z;
};
struct vertex
{
vec3 position;
vec3 color;
};
AppWindow::AppWindow()
{
}
AppWindow::~AppWindow()
{
}
void AppWindow::onCreate()
{
Window::onCreate();
GraphicsEngine::get()->init();
m_swap_chain = GraphicsEngine::get()->createSwapChain();
RECT rc = this->getClientWindowRect();
m_swap_chain->init(this->m_hwnd, rc.right - rc.left, rc.bottom - rc.top);
vertex list[] =
{
// X - Y - Z //
{-0.5f, -0.5f, 0.0f, 1,0,0 }, // POS 1 //
{-0.5f, 0.5f, 0.0f, 0,1,0 }, // POS 2 //
{ 0.5f, -0.5f, 0.0f, 0,0,1 }, // POS 2 //
{ 0.5f, -0.5f, 0.0f, 1,1,0 }
};
m_vb = GraphicsEngine::get()->createVertexBuffer();
UINT size_list = ARRAYSIZE(list);
void* shader_byte_code = nullptr;
size_t size_shader = 0;
GraphicsEngine::get()->compileVertexShader(L"VertexShader.hlsl", "vsmain", &shader_byte_code, &size_shader);
m_vs = GraphicsEngine::get()->createVertexShader(shader_byte_code, size_shader);
m_vb->load(list, sizeof(vertex), size_list, shader_byte_code, size_shader);
GraphicsEngine::get()->releaseCompiledShader();
GraphicsEngine::get()->compilePixelShader(L"VPixelShader.hlsl", "psmain", &shader_byte_code, &size_shader);
m_ps = GraphicsEngine::get()->createPixelShader(shader_byte_code, size_shader);
GraphicsEngine::get()->releaseCompiledShader();
}
void AppWindow::onUpdate()
{
Window::onUpdate();
// CLEAR THE RENDER TARGET //
GraphicsEngine::get()->getImmediateDeviceContext()->clearRenderTargetColor(this->m_swap_chain,
0, 0.3f, 0.4f, 1);
// SET VIEWPORT OF RENDER TARGET IN WHICH E HAVE TO DRAW //
RECT rc = this->getClientWindowRect();
GraphicsEngine::get()->getImmediateDeviceContext()->setViewportSize(rc.right - rc.left, rc.bottom - rc.top);
// SET DEFAULT SHADER IN THE GRAPHICS PIPELINE TO BE ABLE TO DRAW //
GraphicsEngine::get()->getImmediateDeviceContext()->setVertexShader(m_vs);
GraphicsEngine::get()->getImmediateDeviceContext()->setPixelShader(m_ps);
// SET THE VERTICES OF THE TRAINGLETO DRAW //
GraphicsEngine::get()->getImmediateDeviceContext()->setVertexBuffer(m_vb);
// FINALLY DRAW THE TRIANGLE //
GraphicsEngine::get()->getImmediateDeviceContext()->drawTriangleList(m_vb->getSizeVertexList(), 0);
m_swap_chain->present(true);
}
void AppWindow::onDestroy()
{
Window::onDestroy();
m_vb->release();
m_swap_chain->release();
m_vs->release();
m_ps->release();
GraphicsEngine::get()->release();
}
}
|