Text marquee using ID3DXFont and Sprites

Started by
6 comments, last by odyodyodys 15 years, 5 months ago
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??
Advertisement
Does anybody have a clue on this subject?
I'm really desperate
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).
Just draw normal scrolling text and use a scissor rect to clip the edges.

http://msdn.microsoft.com/en-us/library/bb147354(VS.85).aspx
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!!

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!!

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.
I Just LOVE gamedev!!!

Scissors worked great!!

My actual code:
// On device initializationdevice->SetRenderState(D3DRS_SCISSORTESTENABLE, true);// while rendering inside the Begin-End SceneRECT 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...!!!

This topic is closed to new replies.

Advertisement