-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsprite.cpp
More file actions
49 lines (38 loc) · 1.77 KB
/
Copy pathsprite.cpp
File metadata and controls
49 lines (38 loc) · 1.77 KB
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
#include "sprite.h"
IWICBitmapDecoder* pDecoder = nullptr;
IWICBitmapFrameDecode* pSource = nullptr;
IWICStream* pStream = nullptr;
IWICFormatConverter* pConverter = nullptr;
IWICBitmapScaler* pScaler = nullptr;
HRESULT LoadBitmapFromFile(ID2D1DeviceContext3* pD2D1Context, IWICImagingFactory* pIWICFactory, PCWSTR uri, UINT dWidth, UINT dHeight, ID2D1Bitmap** ppBitmap) {
HRESULT hr = pIWICFactory->CreateDecoderFromFilename(uri, NULL, GENERIC_READ, WICDecodeMetadataCacheOnLoad, &pDecoder);
if (SUCCEEDED(hr)) {
hr = pDecoder->GetFrame(0, &pSource);
}
if (SUCCEEDED(hr)) {
hr = pIWICFactory->CreateFormatConverter(&pConverter);
}
if (SUCCEEDED(hr)) {
hr = pConverter->Initialize(pSource, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, nullptr, 0.f, WICBitmapPaletteTypeMedianCut);
};
if (SUCCEEDED(hr)) {
hr = pD2D1Context->CreateBitmapFromWicBitmap(pConverter, nullptr, ppBitmap);
};
if (pDecoder) pDecoder->Release();
if (pSource) pSource->Release();
if (pStream) pStream->Release();
if (pConverter) pConverter->Release();
if (pScaler) pScaler->Release();
return hr;
};
void RenderSprite(ID2D1DeviceContext3* pDeviceContext, ID2D1SpriteBatch* spriteBatch, ID2D1Bitmap* pBitmap) {
pDeviceContext->DrawSpriteBatch(spriteBatch, pBitmap);
}
void RenderImage(ID2D1DeviceContext3* pDeviceContext, ID2D1Bitmap* pBmap, float playerX, float playerY, float playerZ) {
D2D1_SIZE_F size = pBmap->GetSize();
float scale = size.width / 2;
D2D1_POINT_2F imageCenter = D2D1::Point2F(playerX + scale, playerY + scale);
pDeviceContext->SetTransform(D2D1::Matrix3x2F::Rotation(playerZ, imageCenter));
pDeviceContext->DrawBitmap(pBmap, D2D1::RectF(playerX, playerY, 256 + playerX, 256 + playerY));
pDeviceContext->SetTransform(D2D1::Matrix3x2F::Rotation(0, imageCenter));
};