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:
@@ -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);
|
||||
|
||||
|
||||
+72
-5
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user