diff --git a/assets/shader/basic_pixel_shader.hlsl b/assets/shader/basic_pixel_shader.hlsl index 3d29910..e23a1d4 100644 --- a/assets/shader/basic_pixel_shader.hlsl +++ b/assets/shader/basic_pixel_shader.hlsl @@ -1,16 +1,22 @@ struct PixelShaderInput { float4 pos : SV_POSITION; float4 color : COLOR; + float4 uvst : COORDINATES; }; struct PixelShaderOutput { float4 color : SV_TARGET; }; +Texture2D tex1 : register(t0); + +SamplerState texture_sampler : register(s0); + PixelShaderOutput main(PixelShaderInput input) { PixelShaderOutput output; + #if 1 - output.color = input.color; + output.color = tex1.Sample(texture_sampler, input.uvst.xy); #else output.color = float4(1, 0, 1, 1); #endif diff --git a/assets/shader/basic_vertex_shader.hlsl b/assets/shader/basic_vertex_shader.hlsl index bd1db96..fe3bf93 100644 --- a/assets/shader/basic_vertex_shader.hlsl +++ b/assets/shader/basic_vertex_shader.hlsl @@ -1,6 +1,7 @@ struct VertexShaderInput { // Per Vertex float4 pos : VERTEX_POSITION; + float4 uvst : COORDINATES; uint vid : SV_VertexID; // Per Instance @@ -12,6 +13,7 @@ struct VertexShaderInput { struct VertexShaderOutput { float4 pos : SV_POSITION; float4 color : COLOR; + float4 uvst : COORDINATES; }; @@ -47,7 +49,7 @@ VertexShaderOutput main(VertexShaderInput input) { output.pos.zw = float2(0, 1); output.color = input.left_color; - + output.uvst = input.uvst; return output; } \ No newline at end of file diff --git a/assets/strawberry.tga b/assets/strawberry.tga new file mode 100644 index 0000000..38a5641 Binary files /dev/null and b/assets/strawberry.tga differ diff --git a/assets/strawberry_paintnet.tga b/assets/strawberry_paintnet.tga new file mode 100644 index 0000000..e5a314f Binary files /dev/null and b/assets/strawberry_paintnet.tga differ diff --git a/bin/pokemon.exe b/bin/pokemon.exe index 7df4d36..ceee3e8 100644 Binary files a/bin/pokemon.exe and b/bin/pokemon.exe differ diff --git a/bin/pokemon.pdb b/bin/pokemon.pdb index f378662..42032ff 100644 Binary files a/bin/pokemon.pdb and b/bin/pokemon.pdb differ diff --git a/pokemon.vcxproj b/pokemon.vcxproj index e01035f..28b34c6 100644 --- a/pokemon.vcxproj +++ b/pokemon.vcxproj @@ -109,6 +109,7 @@ -Wno-missing-braces -Wno-parentheses -Wno-reorder-init-list -Wno-unused-variable -Wno-format %(AdditionalOptions) + stdcpp17 diff --git a/src/load_tga_file.cpp b/src/load_tga_file.cpp index a345525..12b32a4 100644 --- a/src/load_tga_file.cpp +++ b/src/load_tga_file.cpp @@ -110,7 +110,8 @@ BMP_Texture load_tga_file(const char* path) { auto descriptor_mask = 0x30; auto image_origin = image_specification.image_descriptor & descriptor_mask; - expect(image_origin, 32, "wrong image origin"); + expect(image_origin, 0, "wrong image origin"); + //TODO: y-achse flippen, weil microsoft, spaeter beide faelle implementieren advance(file, id_length); diff --git a/src/main.cpp b/src/main.cpp index f25b161..df945ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,17 +47,19 @@ ID3D11PixelShader* pixel_shader; bool Running = true; -BMP_Texture tex1 = load_tga_file("../assets/strawberry.tga"); +BMP_Texture tex1 = load_tga_file("../assets/strawberry_paintnet.tga"); +//strawberry_paintnet.tga kommt aus paintNet... ich will kein GIMP :O struct Vertex { V4 pos; + V4 uvst; }; Vertex vertices[] = { - {{ -1, 1, 1, 1 } }, - {{ 1, -1, 1, 1 } }, - {{ -1, -1, 1, 1 } }, - {{ 1, 1, 1, 1 } }, + {{ -1, 1, 1, 1 } , { 0, 1, 0, 0 }}, + {{ 1, -1, 1, 1 } , { 1, 0, 0, 0 }}, + {{ -1, -1, 1, 1 } , { 0, 0, 0, 0 }}, + {{ 1, 1, 1, 1 } , { 1, 1, 0, 0 }}, }; uint16 indices[] = { @@ -75,6 +77,10 @@ Instance instances[1] = { {{0.1, 0.1, 0.2, 0.2}, {0, 1, 1, 1}, {1, 0, 1, 1}}, }; +//TODO + + + bool LoadShaders() { ID3DBlob* error_msgs = 0; @@ -274,6 +280,7 @@ bool init_directx11(HWND Window) { D3D11_INPUT_ELEMENT_DESC input_element_desc[] = { { "VERTEX_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "COORDINATES", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "INSTANCE_POSITION_SIZE", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, { "LEFT_COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 16, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, { "RIGHT_COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 32, D3D11_INPUT_PER_INSTANCE_DATA, 1 }, @@ -308,6 +315,8 @@ bool init_directx11(HWND Window) { } int main() { + HRESULT hresult; + CoInitializeEx(0, COINIT_MULTITHREADED); auto Window = (HWND)create_window(WindowMsgs); @@ -320,6 +329,58 @@ int main() { if (init_directx11(Window)) return 1; + D3D11_SAMPLER_DESC sampler_desc = { + .Filter = D3D11_FILTER_MIN_MAG_MIP_POINT, + .AddressU = D3D11_TEXTURE_ADDRESS_CLAMP, + .AddressV = D3D11_TEXTURE_ADDRESS_CLAMP, + .AddressW = D3D11_TEXTURE_ADDRESS_CLAMP, + .MipLODBias = 0, + .MaxAnisotropy = 1, + .ComparisonFunc = D3D11_COMPARISON_ALWAYS, + .BorderColor = {0}, + .MinLOD = 0, + .MaxLOD = 0, + }; + + ID3D11SamplerState* sampler_state; + + if ((hresult = device->CreateSamplerState(&sampler_desc, &sampler_state)) != S_OK) { + log_error("CreateSamplerState has failed. %ld", hresult); + return 1; + } + + D3D11_TEXTURE2D_DESC texture_desc = { + .Width = (UINT)tex1.bmp_width, + .Height = (UINT)tex1.bmp_height, + .MipLevels = 1, + .ArraySize = 1, + .Format = DXGI_FORMAT_B8G8R8A8_UNORM, + .SampleDesc = {.Count = 1, .Quality = 0}, + .Usage = D3D11_USAGE_DEFAULT, + .BindFlags = D3D11_BIND_SHADER_RESOURCE, + .CPUAccessFlags = 0, + .MiscFlags = 0, + }; + + D3D11_SUBRESOURCE_DATA initial_data = { + .pSysMem = tex1.pixel, + .SysMemPitch = (UINT)tex1.bmp_width * 4, + }; + + ID3D11Texture2D* texture; + + if ((hresult = device->CreateTexture2D(&texture_desc, &initial_data, &texture)) != S_OK) { + log_error("CreateTexture2D has failed. %ld", hresult); + return 1; + } + + ID3D11ShaderResourceView* resource_view; + + if ((hresult = device->CreateShaderResourceView(texture, 0, &resource_view)) != S_OK) { + log_error("CreateShaderResourceView failed. %ld", hresult); + return 1; + } + MSG Message; while (Running) { while (PeekMessage(&Message, 0, 0, 0, PM_REMOVE)) { @@ -364,8 +425,14 @@ int main() { devicecontext->IASetInputLayout(input_layout); devicecontext->VSSetShader(vertex_shader, 0, 0); devicecontext->PSSetShader(pixel_shader, 0, 0); + + devicecontext->PSSetSamplers(0, 1, &sampler_state); + devicecontext->PSSetShaderResources(0, 1, &resource_view); + devicecontext->DrawIndexedInstanced(6, 1, 0, 0, 0); + + // swap_chain->Present(0, 0); }