Jump to content
  • Advertisement
Sign in to follow this  
VQuery

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

This topic is 673 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

 

17ff5a529854ea99f532143b9f02e49b.png

 

 

However when I try drawing it at 0,0, it draws correctly:
672e952c80ddd91d29b492281c4434ca.png
 

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

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


1.0f
);

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
Advertisement

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.

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 - rc.top
);

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!