Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
//Load the Image FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; FIBITMAP *dib = NULL; BYTE *bits = NULL; unsigned int width, height; fif = FreeImage_GetFileType(filename, 0); if(fif == FIF_UNKNOWN) fif = FreeImage_GetFIFFromFilename(filename); if(fif == FIF_UNKNOWN) return false; if(FreeImage_FIFSupportsReading(fif)) dib = FreeImage_Load(fif, filename); if(!dib) return false; bits = FreeImage_GetBits(dib); width = FreeImage_GetWidth(dib); height = FreeImage_GetHeight(dib); if((bits == 0) || (width == 0) || (height == 0)) return false; Vertex vertices[] = { {XMFLOAT3(width/2, height/2, 1.0f)}, {XMFLOAT3(width/2, -(height/2), 1.0f)}, {XMFLOAT3(-(width/2), -(height/2), 1.0f)}, {XMFLOAT3(-(width/2), -(height/2), 1.0f)}, {XMFLOAT3(-(width/2), height/2, 1.0f)}, {XMFLOAT3(width/2, height/2, 1.0f)} }; D3D11_TEXTURE2D_DESC textureDesc; textureDesc.Width = width; textureDesc.Height = height; textureDesc.MipLevels = 1; textureDesc.ArraySize = 1; textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; textureDesc.SampleDesc.Count = 1; textureDesc.Usage = D3D11_USAGE_DYNAMIC; textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; textureDesc.BindFlags = NULL; if(!d3dDevice->CreateTexture2D(&textureDesc, NULL, &texture)) return false; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
Texture2DImpl::Texture2DImpl(ID3D11DevicePtr device, int width, int height, GPUInterface::ColorFormat format, void* data) { /* Fill out texture desc */ D3D11_TEXTURE2D_DESC desc; desc.Width = width; desc.Height = height; desc.MipLevels = 1; /* TODO: Allow specifiying */ desc.ArraySize = 1; desc.Format = Utils::ColorFormatToDXFormat (format); desc.SampleDesc.Count = 1; desc.SampleDesc.Quality = 0; desc.Usage = D3D11_USAGE_IMMUTABLE; desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; desc.CPUAccessFlags = 0; desc.MiscFlags = 0; /* As we are immutable, init subresource data now. */ D3D11_SUBRESOURCE_DATA srd; srd.pSysMem = data; srd.SysMemPitch = Utils::GetPitch (width, format); srd.SysMemSlicePitch = 0; /* Create */ HRESULT hr = device->CreateTexture2D (&desc, &srd, &m_texture); if (FAILED (hr)) { throw std::exception ("Failed to create texture"); } CreateSrvAndSamplerState (device, format); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
void Texture2DImpl::CreateSrvAndSamplerState (ID3D11DevicePtr device, GPUInterface::ColorFormat format) { /* And now create the resource view for it */ D3D11_SHADER_RESOURCE_VIEW_DESC srvd; srvd.Format = Utils::ColorFormatToDXFormat (format); srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; srvd.Texture2D.MipLevels = -1; srvd.Texture2D.MostDetailedMip = 0; HRESULT hr = device->CreateShaderResourceView (m_texture, &srvd, &m_srv); if (FAILED(hr)) { throw std::exception ("Failed to create shader resource view"); } /* And the sampler state */ D3D11_SAMPLER_DESC sd; sd.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; /* TODO: Allow specificying */ sd.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; sd.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; sd.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; sd.MipLODBias = 0; sd.MaxAnisotropy = 1; /* TODO: Allow specifying */ sd.ComparisonFunc = D3D11_COMPARISON_NEVER; sd.BorderColor[0] = 0.0f; sd.BorderColor[1] = 0.0f; sd.BorderColor[2] = 0.0f; sd.BorderColor[3] = 0.0f; sd.MinLOD = 0; sd.MaxLOD = D3D11_FLOAT32_MAX; hr = device->CreateSamplerState (&sd, &m_sampler); if (FAILED (hr)) { throw std::exception ("Failed to create sample state."); } } |
Werbeanzeige