added tga file output, noch funktion ergaenzen, um mehrere files auszugeben

git-svn-id: svn://ammerhai.com/home/mike/pokemon_repo@3 24008968-59e6-ed4c-a10b-0b2c954b24ab
This commit is contained in:
mikeb 2021-02-24 20:09:21 +00:00
parent c9a741df87
commit 685fdf3fa9
9 changed files with 85 additions and 8 deletions

View File

@ -1,16 +1,22 @@
struct PixelShaderInput { struct PixelShaderInput {
float4 pos : SV_POSITION; float4 pos : SV_POSITION;
float4 color : COLOR; float4 color : COLOR;
float4 uvst : COORDINATES;
}; };
struct PixelShaderOutput { struct PixelShaderOutput {
float4 color : SV_TARGET; float4 color : SV_TARGET;
}; };
Texture2D<float4> tex1 : register(t0);
SamplerState texture_sampler : register(s0);
PixelShaderOutput main(PixelShaderInput input) { PixelShaderOutput main(PixelShaderInput input) {
PixelShaderOutput output; PixelShaderOutput output;
#if 1 #if 1
output.color = input.color; output.color = tex1.Sample(texture_sampler, input.uvst.xy);
#else #else
output.color = float4(1, 0, 1, 1); output.color = float4(1, 0, 1, 1);
#endif #endif

View File

@ -1,6 +1,7 @@
struct VertexShaderInput { struct VertexShaderInput {
// Per Vertex // Per Vertex
float4 pos : VERTEX_POSITION; float4 pos : VERTEX_POSITION;
float4 uvst : COORDINATES;
uint vid : SV_VertexID; uint vid : SV_VertexID;
// Per Instance // Per Instance
@ -12,6 +13,7 @@ struct VertexShaderInput {
struct VertexShaderOutput { struct VertexShaderOutput {
float4 pos : SV_POSITION; float4 pos : SV_POSITION;
float4 color : COLOR; float4 color : COLOR;
float4 uvst : COORDINATES;
}; };
@ -47,7 +49,7 @@ VertexShaderOutput main(VertexShaderInput input) {
output.pos.zw = float2(0, 1); output.pos.zw = float2(0, 1);
output.color = input.left_color; output.color = input.left_color;
output.uvst = input.uvst;
return output; return output;
} }

BIN
assets/strawberry.tga Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -109,6 +109,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile> <ClCompile>
<AdditionalOptions>-Wno-missing-braces -Wno-parentheses -Wno-reorder-init-list -Wno-unused-variable -Wno-format %(AdditionalOptions)</AdditionalOptions> <AdditionalOptions>-Wno-missing-braces -Wno-parentheses -Wno-reorder-init-list -Wno-unused-variable -Wno-format %(AdditionalOptions)</AdditionalOptions>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile> </ClCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>

View File

@ -110,7 +110,8 @@ BMP_Texture load_tga_file(const char* path) {
auto descriptor_mask = 0x30; auto descriptor_mask = 0x30;
auto image_origin = image_specification.image_descriptor & descriptor_mask; 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); advance(file, id_length);

View File

@ -47,17 +47,19 @@ ID3D11PixelShader* pixel_shader;
bool Running = true; 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 { struct Vertex {
V4 pos; V4 pos;
V4 uvst;
}; };
Vertex vertices[] = { Vertex vertices[] = {
{{ -1, 1, 1, 1 } }, {{ -1, 1, 1, 1 } , { 0, 1, 0, 0 }},
{{ 1, -1, 1, 1 } }, {{ 1, -1, 1, 1 } , { 1, 0, 0, 0 }},
{{ -1, -1, 1, 1 } }, {{ -1, -1, 1, 1 } , { 0, 0, 0, 0 }},
{{ 1, 1, 1, 1 } }, {{ 1, 1, 1, 1 } , { 1, 1, 0, 0 }},
}; };
uint16 indices[] = { 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}}, {{0.1, 0.1, 0.2, 0.2}, {0, 1, 1, 1}, {1, 0, 1, 1}},
}; };
//TODO
bool LoadShaders() { bool LoadShaders() {
ID3DBlob* error_msgs = 0; ID3DBlob* error_msgs = 0;
@ -274,6 +280,7 @@ bool init_directx11(HWND Window) {
D3D11_INPUT_ELEMENT_DESC input_element_desc[] = { D3D11_INPUT_ELEMENT_DESC input_element_desc[] = {
{ "VERTEX_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "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 }, { "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 }, { "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 }, { "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() { int main() {
HRESULT hresult;
CoInitializeEx(0, COINIT_MULTITHREADED); CoInitializeEx(0, COINIT_MULTITHREADED);
auto Window = (HWND)create_window(WindowMsgs); auto Window = (HWND)create_window(WindowMsgs);
@ -320,6 +329,58 @@ int main() {
if (init_directx11(Window)) if (init_directx11(Window))
return 1; 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; MSG Message;
while (Running) { while (Running) {
while (PeekMessage(&Message, 0, 0, 0, PM_REMOVE)) { while (PeekMessage(&Message, 0, 0, 0, PM_REMOVE)) {
@ -364,8 +425,14 @@ int main() {
devicecontext->IASetInputLayout(input_layout); devicecontext->IASetInputLayout(input_layout);
devicecontext->VSSetShader(vertex_shader, 0, 0); devicecontext->VSSetShader(vertex_shader, 0, 0);
devicecontext->PSSetShader(pixel_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); devicecontext->DrawIndexedInstanced(6, 1, 0, 0, 0);
// //
swap_chain->Present(0, 0); swap_chain->Present(0, 0);
} }