|
|
|
#pragma comment(lib, "user32") |
|
#pragma comment(lib, "d3d11") |
|
#pragma comment(lib, "d3dcompiler") |
|
|
|
#include <windows.h> |
|
#include <d3d11.h> |
|
#include <d3dcompiler.h> |
|
|
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) |
|
{ |
|
IDXGISwapChain* swapchain; |
|
ID3D11Device* device; |
|
ID3D11DeviceContext* devicecontext; |
|
ID3D11Texture2D* rendertarget; |
|
ID3D11RenderTargetView* rendertargetview; |
|
ID3DBlob* cso; |
|
ID3D11VertexShader* vertexshader; |
|
ID3D11PixelShader* pixelshader; |
|
WNDCLASSA wndclass = { 0, DefWindowProcA, 0, 0, 0, 0, 0, 0, 0, "d7" }; |
|
RegisterClassA(&wndclass); |
|
DXGI_SWAP_CHAIN_DESC swapchaindesc = { { 0, 0, {}, DXGI_FORMAT_R8G8B8A8_UNORM }, { 1 }, 32, 2, CreateWindowExA(0, "d7", 0, 0x91000000, 0, 0, 0, 0, 0, 0, 0, 0), 1 }; |
|
D3D11CreateDeviceAndSwapChain(0, D3D_DRIVER_TYPE_HARDWARE, 0, 0, 0, 0, 7, &swapchaindesc, &swapchain, &device, 0, &devicecontext); |
|
swapchain->GetDesc(&swapchaindesc); |
|
swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&rendertarget); |
|
device->CreateRenderTargetView(rendertarget, 0, &rendertargetview); |
|
D3DCompileFromFile(L"gpu.hlsl", 0, 0, "vertex_shader", "vs_5_0", 0, 0, &cso, 0); |
|
device->CreateVertexShader(cso->GetBufferPointer(), cso->GetBufferSize(), 0, &vertexshader); |
|
D3DCompileFromFile(L"gpu.hlsl", 0, 0, "pixel_shader", "ps_5_0", 0, 0, &cso, 0); |
|
device->CreatePixelShader(cso->GetBufferPointer(), cso->GetBufferSize(), 0, &pixelshader); |
|
D3D11_VIEWPORT viewport = { 0, 0, (float)swapchaindesc.BufferDesc.Width, (float)swapchaindesc.BufferDesc.Height, 0, 1 }; |
|
devicecontext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); |
|
devicecontext->VSSetShader(vertexshader, 0, 0); |
|
devicecontext->RSSetViewports(1, &viewport); |
|
devicecontext->PSSetShader(pixelshader, 0, 0); |
|
devicecontext->OMSetRenderTargets(1, &rendertargetview, 0); |
|
devicecontext->Draw(3, 0); |
|
swapchain->Present(1, 0); |
|
GetMessageA((MSG*)WinMain, 0, WM_KEYFIRST, WM_KEYLAST); // PRESS ANY KEY TO EXIT |
|
} |
For anyone else who runs into the issue where the window doesn't open, ensure that gpu.hlsl is in the current working directory.