Jump to content
  • Advertisement
Sign in to follow this  
CodaKiller

How to get the HDC of a DirectX 10 texture and how to use GDI DrawText?

This topic is 3661 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

Well the font interface does not work how I'd like it to so I want to create my own, I just want to render GDI text to a DirectX texture and then create a sprite from it, This would actually work much faster for my plans then the font interface. So how do I render GDI text to a texture? Edit: Also I'm having problems getting DrawText to work, read below for more details. [Edited by - CodaKiller on November 30, 2008 2:18:03 PM]

Share this post


Link to post
Share on other sites
Advertisement
You can use IDirect3DTexture9::GetSurfaceLevel to get the relevant surface, then IDirect3DSurface9::GetDC to get a device context.

The normal GDI DrawText, TextOut etc can then be used with the DC. Call IDirect3DSurface9::ReleaseDC when you're done.

Share this post


Link to post
Share on other sites
Quote:
Original post by EasilyConfused
You can use IDirect3DTexture9::GetSurfaceLevel to get the relevant surface, then IDirect3DSurface9::GetDC to get a device context.

The normal GDI DrawText, TextOut etc can then be used with the DC. Call IDirect3DSurface9::ReleaseDC when you're done.


Forgot to add that I'm using DirectX 10 =/

Share this post


Link to post
Share on other sites
Also What command should I use to draw the text, I'm a bit confused as to which would be best. I just want nice clean text that uses standard font and can fit in to a rect though if one of the options offer some way to use a bitmap for the surface of the text that would be even better.

So what should I use?

[Edited by - CodaKiller on November 30, 2008 10:53:18 AM]

Share this post


Link to post
Share on other sites
So I've been trying to draw text with the DrawText function since it uses a rect but it wont work. The TextOut function does though, is there a way to set a rect with TextOut? If not then what am I doing wrong with the DrawText command? Here is my source code:


case WM_PAINT:
{
RECT rect;
rect.bottom = 0;
rect.left = 0;
rect.right = 100;
rect.top = 100;
HDC hDC = GetDC(hWnd);
HFONT NewFont = CreateFont( 100, 0, 0, 0, FW_BOLD, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, 0, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial" );
HBRUSH NewBrush = CreateSolidBrush(RGB(255, 0, 0));
SelectObject(hDC, NewFont);
SelectObject(hDC, NewBrush);
DrawText(hDC, "See?", 4, &rect, DT_LEFT | DT_WORDBREAK);
// TextOut(hDC, 10, 200, "SEE?", 4);
DeleteObject(NewBrush);
DeleteObject(NewFont);
ReleaseDC(hWnd, hDC);
break;
}





[Edited by - CodaKiller on November 30, 2008 4:28:59 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by yewbie
it doesn't look like your releasing your dc?, what does drawtext do when you run it?


Nothing and I changed the code to release it, still nothing.

Share this post


Link to post
Share on other sites
Set parameter 3 in draw text to -1 so it auto determines what the text length is that might fix it

edit: maybe try to add DT_NOCLIP

Share this post


Link to post
Share on other sites
Quote:
Original post by yewbie
Set parameter 3 in draw text to -1 so it auto determines what the text length is that might fix it

edit: maybe try to add DT_NOCLIP


Oh I had bad dominions on the rect because I copied it from a sample and didn't even notice.

Now there is only one more problem I need to solve, someone on another forum said I can't get a hDC from a directx10 texture and I have to use a DIB section. But I don't know what a DIB section is and I can't find any info on it... Anyone know of a good tutorial on them?

Share this post


Link to post
Share on other sites
Hey I looked and looked and for some reason the internet does not have a solution to that problem =), may wanna check in the directx forum.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!