Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Measurements from MeasureString #34

Closed
char1estan opened this issue May 22, 2016 · 19 comments
Closed

Wrong Measurements from MeasureString #34

char1estan opened this issue May 22, 2016 · 19 comments
Assignees
Labels

Comments

@char1estan
Copy link

char1estan commented May 22, 2016

Hi Developers,

I have notice that the MeasureString returns a wrong size. The string "W" is used to measure the string size. The spritefont file is generated using MakeSpriteFont tool. The font setting is

  • FontName: Arial
  • FontStyle: Bold
  • FontSize: 185

The returned result for the width and the height are 233 and 283.642578 respectively. "W" is placed at (0,0) I have edited Image 1 to include a black dotted line and marked a red circle to indicate the position where my mouse positioned which reflects the values shown in the Window Title. Clearly, there is a big difference between the Vector2 returned and the size which I had measured.

Image 1:
image 1

In addition, when I used SpriteBatch to draw "W" on the screen (0,0) using origin (0,0), it does not draw at the correct place. Instead, there is some sort of spacing as shown in Image 2.

Image 2:
image 2

To test it further, I have used SpriteBatch to draw "W" on the screen at the bottom left (i.e. making it right justified) of the screen using the origin calculated via MeasureString, but it does not draw at the correct place as shown in Image 3. Instead, it is lifted and cut off.

Image 3:
image 3

@walbourn
Copy link
Member

Which version of DirectX Tool Kit are you using? There was a bug with MeasureString that was fixed in the Febraury 2016 release.

@char1estan
Copy link
Author

I am using:
Id: directxtk_windowsstore_8_1
Version: 2016.2.23.1

For your additional information:
I am developing Win32 application using Visual Studio 2013, but instead I am using directxtk_windows_8_1 (Version: 2016.2.23.1) as using the directxtk_desktop_2013 (Version: 2016.4.26.1) gives me error LNK1104:cannot open file 'x3daudio.lib'

@walbourn
Copy link
Member

walbourn commented May 23, 2016

The different NuGet packages for DirectX Tool Kit are built for specific platforms, and make different assumptions. If you are writing a "classic" Win32 desktop application, you should not use the directxtk_windowsstore_8_1 NuGet package.

For Windows Store 8.1, the application requires Windows 8.1 or later, and so directxtk_windowsstore_8_1 makes use of XAudio 2.8 in the Windows 8.1 SDK. Similarly for UWP, the application requires Windows 10, and so directxtk_uwp makes use of XAudio 2.9 in the Windows 10 SDK. If you are making a Win32 classic desktop application, then I assume you are wanting Windows 7 compatibility. Therefore, if you use the directxtk_desktop_201x NuGet package, any use of DirectX Tool Kit for Audio requires the legacy DirectX SDK for XAudio 2.7. If you want specifically to write a Win32 classic desktop application that requires Windows 8 or later and thus uses XAudio 2.8, you can do so but you should use project-to-project references--this is a rare scenario, so I don't have a NuGet package specifically for this one. This is covered in detail on the wiki.

@walbourn
Copy link
Member

In any case I'm able to repro your issue and I'm investigating.

@walbourn walbourn added the bug label May 23, 2016
@walbourn
Copy link
Member

I think this was a bad fix, but I need to go back and figure out why I needed this change to make other things work.

@char1estan
Copy link
Author

char1estan commented May 23, 2016

Chuck Walbourn, thanks for the explanations. Actually, I am shifting from DirectX9 to DirectX11 and happened to found DirectXTK. At the same time, I am not going to use the legacy SDK (June 2010) to support my game engine even though it is only used for building very simple 2D games. Using DirectXTK makes the conversion easier as I am not very technical or familiar with the Pipeline related knowledge/experience.

I do have the intention of converting it to Windows Store App style instead of Win32. However, based on my research, I found that I may also have to pick up C++/CX. So currently, I decided to convert it from DirectX9 (Win32) to DirectX11 (Win32) using DirectXTK first before I further my research on Windows Store App and the Pipeline. This may explains why my 2D Game Engine (Win32) uses directxtk_windowsstore_8_1 instead of directxtk_desktop_2013 for DirectXTK's Audio as it happens to works for this code snippet.

Another question aside from Audioand Spritefontis: Do you have the intention of making DirectXTK's documentation similar to the MSDN style or is it advisable for us to cross reference DirectXTK with XNA?

As for the SpriteFont, I will wait for you to fix it.

@char1estan
Copy link
Author

Hi Chuck,

Has the said issue been resolve?

@walbourn
Copy link
Member

walbourn commented Jun 4, 2016

I'm wrapping a robust fix this weekend. You can download the library and make the source edit yourself as well.

@char1estan
Copy link
Author

Ok noted, in that case, i will wait for you to release all the fix at one go. Thanks,

@walbourn
Copy link
Member

walbourn commented Jun 6, 2016

Sync to the master branch to pick up the fixes. Reverted MeasureString to old behavior, and added MeasureDrawString.

RECT MeasureDrawBounds(_In_z_ wchar_t const* text, XMFLOAT2 const& position) const;
RECT XM_CALLCONV MeasureDrawBounds(_In_z_ wchar_t const* text, FXMVECTOR position) const;

Documented on wiki

@walbourn walbourn closed this as completed Jun 6, 2016
@char1estan
Copy link
Author

Can you roughly estimate when will this fix be pushed to the NuGet Package?

@walbourn
Copy link
Member

I generally wait until enough work has accumulated to justify a full release, but I can accelerate a publish to NuGet if that's required. I'll look at doing one this week.

@walbourn walbourn self-assigned this Jun 14, 2016
@char1estan
Copy link
Author

alright, noted with thanks.

@char1estan
Copy link
Author

reminder for NuGet release. Thanks.

@walbourn
Copy link
Member

walbourn commented Jul 1, 2016

Now that June 2016 is done, I'll be doing all the NuGet publishing for it tomorrow.

@walbourn
Copy link
Member

walbourn commented Jul 1, 2016

@char1estan
Copy link
Author

yes thanks!

@char1estan
Copy link
Author

char1estan commented Jul 2, 2016

Hi Chuck,

I am getting this error message: "This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is packages\directxtk_windowsstore_8_1.2016.4.26.1\build\native\directxtk_windowsstore_8_1.targets."

The solution I had discovered is to remove the lines that contains the April NuGet release. This is what is being removed:

<Import Project="packages\directxtk_windowsstore_8_1.2016.4.26.1\build\native\directxtk_windowsstore_8_1.targets" Condition="Exists('packages\directxtk_windowsstore_8_1.2016.4.26.1\build\native\directxtk_windowsstore_8_1.targets')" />
<Error Condition="!Exists('packages\directxtk_windowsstore_8_1.2016.4.26.1\build\native\directxtk_windowsstore_8_1.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\directxtk_windowsstore_8_1.2016.4.26.1\build\native\directxtk_windowsstore_8_1.props'))" />
<Error Condition="!Exists('packages\directxtk_windowsstore_8_1.2016.4.26.1\build\native\directxtk_windowsstore_8_1.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\directxtk_windowsstore_8_1.2016.4.26.1\build\native\directxtk_windowsstore_8_1.targets'))" />

Removing the 200MB package folder (previous releases).

Is there a better way to do it rather than editing it manually in the *****.vcxproj?

***EDIT
I think the above is a weird situation as I do already have NuGet Packages installed, but it doesn't allow me to update. This is shown here:
image

(Other similar issues faced: Some project files do not even mentioned that the DirectXTK NuGet Package was installed. In fact, it was actually installed.)

I decided to proceed on to download the NuGet Package again then compile the project. However, it just tells me that the April release was missing. So if anyone faces this problem, you may go ahead and edit out at your own risk.

Note: There are some projects files that can be updated successfully without the popup window shown in the above image.

@walbourn
Copy link
Member

walbourn commented Jul 2, 2016

As I said earlier in this thread, you shouldn't be using directxtk_windowsstore_8_1 for a Windows desktop project. In my experience, the NuGet Manager is able to do the Update as long you have restored the old package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants