Hey devs, still brand new to gauge development so I apologize if this isn't the way we discuss code on FSDeveloper.
I've been experimenting with the Direct2D way of gauge development; I have done D2D in Win32 C++ in the past, so it wasn't so hard to pick up (I implemented a draw animation as a test project).
However, the part I'm stuck at is the bitmap loading. I wrote it all in the d2dg->pRT->BeginDraw() temporarily for sandbox purposes.
(I'm using Naruto-kun's blank D2D template)
Here's the code:
The code compiles, but whenever P3D attempts to load the gauge, it crashes. I have attached my Visual Studio debugger to P3D and ran it in Debug Mode with breakpoints, but there's nothing showing that could cause the sim to crash. Wondering if anyone has any suggestions on how they'd load a bitmap in D2D graphics?
Cheers,
hdcoder
I've been experimenting with the Direct2D way of gauge development; I have done D2D in Win32 C++ in the past, so it wasn't so hard to pick up (I implemented a draw animation as a test project).
However, the part I'm stuck at is the bitmap loading. I wrote it all in the d2dg->pRT->BeginDraw() temporarily for sandbox purposes.
(I'm using Naruto-kun's blank D2D template)
Here's the code:
Code:
d2dg->pRT->BeginDraw();
HRESULT hr;
ID2D1Bitmap* bmp;
// Create a WIC Factory
IWICImagingFactory *wicFactory = NULL;
hr = CoCreateInstance(
CLSID_WICImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory,
(LPVOID*)&wicFactory);
// Create a decoder
IWICBitmapDecoder *wicDecoder = NULL;
hr = wicFactory->CreateDecoderFromFilename(
L"image1.png",
NULL,
GENERIC_READ,
WICDecodeMetadataCacheOnLoad,
&wicDecoder);
// Read a frame from the image
IWICBitmapFrameDecode* wicFrame = NULL;
hr = wicDecoder->GetFrame(0, &wicFrame);
// Create a converter
IWICFormatConverter *wicConverter = NULL;
hr = wicFactory->CreateFormatConverter(&wicConverter);
// Setup the converter
hr = wicConverter->Initialize(
wicFrame,
GUID_WICPixelFormat32bppBGRA,
WICBitmapDitherTypeNone,
NULL,
0.0,
WICBitmapPaletteTypeCustom);
// Use the converter to create an D2D1Bitmap
hr = d2dg->pRT->CreateBitmapFromWicBitmap(
wicConverter,
NULL,
&bmp);
if (wicFactory)
wicFactory->Release();
if (wicDecoder)
wicDecoder->Release();
if (wicConverter)
wicConverter->Release();
if (wicFrame)
wicFrame->Release();
// Draw the bitmap to the gauge screen
d2dg->pRT->DrawBitmap(
bmp,
D2D1::RectF(0.0f, 0.0f, bmp->GetSize().width, bmp->GetSize().height),
1.0f,
D2D1_BITMAP_INTERPOLATION_MODE::D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
D2D1::RectF(0.0f, 0.0f, bmp->GetSize().width, bmp->GetSize().height));
d2dg->pRT->EndDraw();
The code compiles, but whenever P3D attempts to load the gauge, it crashes. I have attached my Visual Studio debugger to P3D and ran it in Debug Mode with breakpoints, but there's nothing showing that could cause the sim to crash. Wondering if anyone has any suggestions on how they'd load a bitmap in D2D graphics?
Cheers,
hdcoder
Last edited: