Sign in to follow this  
odyodyodys

Text marquee using ID3DXFont and Sprites

Recommended Posts

Hey all, I'm trying to do a marquee for my d3d app. I want to have a rectangle that defines the area in which the text is going to be scrolling, but i'm failing.. What I do is the following:

// Initialize the font
D3DXCreateFont(device, 24 , 0, FW_DONTCARE, 0, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLEARTYPE_NATURAL_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Lucida Console"), &font);


// Draw the text
RECT sourceRect = {0};
sourceRect.Top = 0;
sourceRect.Bottom = 300;
sourceRect.Left = 0;
sourceRect.Right = 500;

font->DrawText(NULL, L"Hello World!", -1, &sourceRect, 0, D3DCOLOR_ARGB(255, 0, 0, 0) );


This allows me to draw on the monitor. But what I cannot do is move the text left or right inside the sourceRect. any ideas or where to look at??

Share this post


Link to post
Share on other sites
Quote:
Original post by odyodyodys
Does anybody have a clue on this subject?
I'm really desperate
Your best bet would probably be to use render to texture to render the string you want, then apply it to a quad which you can clip the texture coordinates of.

Alternatively, you might be able to do something with the state of the ID3DXSprite used to render to text to make it appear behind some other sprites (If there's a solid border around your text marquee).

Share this post


Link to post
Share on other sites
Thanks for your replies,

I didn't knew anything about scissors. I am going to use it.

Any ideas on how to get a texture from a text?

no such method as font->GetTexture() exists...

I am working on it for more than 2 days and I am desperate!!

Share this post


Link to post
Share on other sites
Thanks for your replies,

I didn't knew anything about scissors. I am going to use it.

Any ideas on how to get a texture from a text?

no such method as font->GetTexture() exists...

I am working on it for more than 2 days and I am desperate!!

Share this post


Link to post
Share on other sites
Quote:
Original post by odyodyodys
Thanks for your replies,

I didn't knew anything about scissors. I am going to use it.

Any ideas on how to get a texture from a text?

no such method as font->GetTexture() exists...

I am working on it for more than 2 days and I am desperate!!
I completely forgot about scissors, they'd definitely be better.

There is no way to get a texture from text. What are you trying to do? If you're trying to do a render-to-texture, take a look on Google.

Share this post


Link to post
Share on other sites
I Just LOVE gamedev!!!

Scissors worked great!!

My actual code:

// On device initialization
device->SetRenderState(D3DRS_SCISSORTESTENABLE, true);

// while rendering inside the Begin-End Scene
RECT visibleAreaOld = {0};
hr = device->GetScissorRect( &visibleAreaOld);

// Change the rectangle as desired here...

RECT visibleAreaNew = {0};
hr = device->SetScissorRect( &visibleAreaNew );

RECT textRect = {0};
//Set textRect as desired. Eg. add a step on the textRect on each frame so it advances right or left.


font->DrawTextW(NULL, messageToDisplay.c_str(), -1, &textRect, DT_NOCLIP, D3DCOLOR_ARGB(255,0,0,0));

device->SetScissorRect(&visibleAreaOld);




Thank you guys...!!!

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