Sign in to follow this  

[Easy] Direct2D - Bitmap not at correct x,y

Recommended Posts

Hopefully this is the right place to post. For some reason in my game, bitmaps are not being placed correctly. 


Here I'm trying to draw a Bitmap at 200, 200 (width is 16x16) but instead its being drawn at roughly 194, 186





However when I try drawing it at 0,0, it draws correctly:

I pretty much followed exactly the MSDN articles, here's the code:

D2D1_POINT_2F upperLeftCorner = D2D1::Point2F(200.f, 200.f);
D2D1_SIZE_F size = ResourceLoader::GetImageAssets().at(4).Bitmap->GetSize();
upperLeftCorner.x + size.width,
upperLeftCorner.y + size.height),


ResourceLoader is some custom class, GetImageAssets is a vector with a class called ImageAsset, ImageAsset contains the Bitmap.

I've tried with no defined transforms and with the Matrix3x4 identity transform with still the same result. 


Edit: It appears that the more it strays from 0,0, the larger the "offset". It doesn't seem to be some static x,y offset/transform.


Edit2: Same issue with DrawRectangle. Seems to be an issue with the Direct2D drawing and not the DrawBitmap method itself.


Edit3: Fixed. I was not creating my HwndRenderTarget correctly.

Edited by VQuery

Share this post

Link to post
Share on other sites

is your projection matrix the size of your screen?  this could be a problem if you are projecting to say 800x600 when your resolution is something different.


Hey I made an edit yesterday, you are correct. It was a really easy fix.

RECT rc;
GetClientRect(hWnd, &rc);

D2D1_SIZE_U size = D2D1::SizeU(
rc.right - rc.left,
rc.bottom -

Then for the HwndRenderTarget:

D2D1::HwndRenderTargetProperties(hWnd, size, D2D1_PRESENT_OPTIONS_IMMEDIATELY);

Thanks ncsu121978 for following up!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this