diff --git a/bin/pokemon.exe b/bin/pokemon.exe index 5cc0985..a01564e 100644 Binary files a/bin/pokemon.exe and b/bin/pokemon.exe differ diff --git a/bin/pokemon.pdb b/bin/pokemon.pdb index 8231430..c63bfc1 100644 Binary files a/bin/pokemon.pdb and b/bin/pokemon.pdb differ diff --git a/src/load_tga_file.cpp b/src/load_tga_file.cpp index cba17eb..3762da8 100644 --- a/src/load_tga_file.cpp +++ b/src/load_tga_file.cpp @@ -92,7 +92,7 @@ void swap(uint32_t& a, uint32_t& b) { b = h; } -BMP_Texture load_tga_file(const char* path) { +Image_Info load_tga_file(const char* path) { auto file = load_entire_file(path); auto start_file = file; diff --git a/src/load_tga_file.h b/src/load_tga_file.h index 24db431..a03ba8c 100644 --- a/src/load_tga_file.h +++ b/src/load_tga_file.h @@ -1,11 +1,11 @@ #pragma once #include -struct BMP_Texture { +struct Image_Info { int64_t bmp_width; int64_t bmp_height; uint32_t* pixel; }; -BMP_Texture load_tga_file(const char* path); \ No newline at end of file +Image_Info load_tga_file(const char* path); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 26977b2..28ea95c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,6 +52,8 @@ ID3D11VertexShader* vertex_shader; ID3DBlob* pixel_shader_code; ID3D11PixelShader* pixel_shader; +ID3D11Buffer* quad_instance_buffer; + int16 window_width; int16 window_height; @@ -61,7 +63,6 @@ bool Running = true; #define view_width 17 #define view_height 13 - struct Vertex { V4 pos; V4 uvst; @@ -109,6 +110,8 @@ Player player = { .pos_y = 6, }; +Instance quad_instance = { {0.1f, 0.1f, 0.1f, 0.1f } }; + void save_map() { log("Save file is under construction."); FILE* file = fopen("../assets/map/map.sv", "wb"); @@ -523,6 +526,7 @@ bool init_directx11(HWND Window) { index_buffer = CreateBuffer("index_buffer", sizeof(indices), indices, D3D11_BIND_INDEX_BUFFER); tiles_instance_buffer = CreateBuffer("tiles_instance_buffer", sizeof(tiles_instances), tiles_instances, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE); player_instance_buffer = CreateBuffer("player_instance_buffer", sizeof(player_instance), &player_instance, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE); + quad_instance_buffer = CreateBuffer("quad_instance_buffer", sizeof(quad_instance), &quad_instance, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE); D3D11_SAMPLER_DESC sampler_desc = { .Filter = D3D11_FILTER_MIN_MAG_MIP_POINT, @@ -573,7 +577,7 @@ bool init_directx11(HWND Window) { ID3D11ShaderResourceView* create_shader_texture_array(int num_textures, char** bmp_texture_paths, String debug_name) { assert(num_textures >= 1); - BMP_Texture* bmp_textures = (BMP_Texture*) malloc(num_textures * sizeof(BMP_Texture)); + Image_Info* bmp_textures = (Image_Info*) malloc(num_textures * sizeof(Image_Info)); defer(free(bmp_textures)); for (int i = 0; i < num_textures; i++) { @@ -634,7 +638,7 @@ ID3D11ShaderResourceView* create_shader_texture_array(int num_textures, char** b // 1 Texture erzeugen ID3D11ShaderResourceView* create_shader_texture(char* bmp_texture_path) { - BMP_Texture bmp_texture = load_tga_file(bmp_texture_path); + Image_Info bmp_texture = load_tga_file(bmp_texture_path); D3D11_TEXTURE2D_DESC texture_desc = { .Width = (UINT)bmp_texture.bmp_width, @@ -672,6 +676,40 @@ ID3D11ShaderResourceView* create_shader_texture(char* bmp_texture_path) { return resource_view; } +void render_quad(V2 pos, V2 size, ID3D11ShaderResourceView* texture, bool is_animated) { + + ID3D11ShaderResourceView* quad_texture = texture; + + quad_instance.pos_size.xy = pos; + quad_instance.pos_size.zw = size; + + //Grafikkarte updaten + D3D11_MAPPED_SUBRESOURCE quad_mapped_subressource; + devicecontext->Map(quad_instance_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &quad_mapped_subressource); + memcpy(quad_mapped_subressource.pData, &quad_instance, sizeof(quad_instance)); + devicecontext->Unmap(quad_instance_buffer, 0); + + UINT input_strides[] = { + sizeof(Vertex), + sizeof(Instance), + }; + + UINT input_offsets[] = { + 0, + 0, + }; + + ID3D11Buffer* quad_input_buffer[] = { + vertex_buffer, + quad_instance_buffer, + }; + + devicecontext->IASetVertexBuffers(0, sizeof(quad_input_buffer) / sizeof(*quad_input_buffer), quad_input_buffer, input_strides, input_offsets); + devicecontext->PSSetShaderResources(0, 1, &quad_texture); + devicecontext->DrawIndexedInstanced(6, 1, 0, 0, 0); +} + + int main() { CoInitializeEx(0, COINIT_MULTITHREADED); @@ -693,20 +731,20 @@ int main() { if (init_directx11(Window)) return 1; - // Eine Textur erzeugen - ID3D11ShaderResourceView* tile_texture = 0; - if (!(tile_texture = create_shader_texture("../assets/tile_grass_2.tga"))) { - log_error("CreateShaderTexture has failed."); - return 1; - } - ID3D11ShaderResourceView* player_texture = 0; if (!(player_texture = create_shader_texture("../assets/strawberry.tga"))) { log_error("CreateShaderTexture has failed."); return 1; } + ID3D11ShaderResourceView* quad_texture = 0; + if (!(quad_texture = create_shader_texture("../assets/tile_grass_2.tga"))) { + log_error("CreateShaderTexture has failed."); + return 1; + } + //mehrere Texturen erzeugen + ID3D11ShaderResourceView* tile_texture = 0; char* tile_texture_array[] = { "../assets/tile_empty.tga", "../assets/tile_grass_2.tga" , "../assets/tile_dirt.tga" , "../assets/tile_water.tga", "../assets/tile_error.tga" }; if (!(tile_texture = create_shader_texture_array(sizeof(tile_texture_array) / sizeof(*tile_texture_array), tile_texture_array, "tile_textures"))) { log_error("CreateShaderTextrueArray has failed."); @@ -714,6 +752,9 @@ int main() { } load_map(); + + V2 quad_pos = { 0.001f, 0.001f }; + V2 quad_size = { 0.1f, 0.1f }; MSG Message; while (Running) { @@ -771,7 +812,6 @@ int main() { devicecontext->IASetVertexBuffers(0, sizeof(tiles_input_buffers) / sizeof(*tiles_input_buffers), tiles_input_buffers, input_strides, input_offsets); devicecontext->IASetIndexBuffer(index_buffer, DXGI_FORMAT_R16_UINT, 0); - devicecontext->IASetInputLayout(input_layout); devicecontext->VSSetShader(vertex_shader, 0, 0); devicecontext->PSSetShader(pixel_shader, 0, 0); @@ -791,8 +831,14 @@ int main() { devicecontext->PSSetShaderResources(0, 1, &player_texture); devicecontext->DrawIndexedInstanced(6, 1, 0, 0, 0); + //Moving Quad + quad_pos += {0.001f, 0.001f}; + + render_quad(quad_pos, quad_size, quad_texture, 1); + render_quad({ 0.1, 0.2 }, { 0.01, 0.01 }, quad_texture, 0); // - swap_chain->Present(0, 0); + + swap_chain->Present(1, 0); } return 0; } \ No newline at end of file