Sign in to follow this  

Writing text in Dx9(c++)

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

Howdy, I know how to write text, but so far I only know how to write it to SCREEN coordinates, and not to world coordinates. Is there a way it can be drawn to world coordinates similar to normal textures? Or is my best bet to just find the position it WOULD be relative to the person by finding the distance from the center and such?

Share this post


Link to post
Share on other sites
You have two options really:

1) Render the text as you are probably doing it now, with ID3DXFont, but render it to an offscreen render target and then texture a quad that lies somewhere in your world.

2) Create a mesh of text using, D3DXCreateText(), i believe it is.

Share this post


Link to post
Share on other sites
Awesome, thank you very much - and I am going to be attempting number 1 first, because I am just in need of some simple font usage.

Edit: is there a term that sums up what I should be looking for? I am trying a combination of words, but it seems must of it is coming up using sprites rather than textures.

Edit2: I realized I will be using sprites to keep the perspective always visible to the user. Leaving edit1 for completeness.

Share this post


Link to post
Share on other sites
Ok, so I am going to render the text to a sprite and then draw the sprite in the appropriate position that way if a player moves around, the text stays in the same spot.

Anywho, before I attempt this, I am trying to figure out the best road to take. I use textures (not sprites) for pretty much everything but the GUI, so I figure I am going to have to create a new sprite, draw the text, then add it to a collection of other text related sprites, and include them in the render() routine.

Does this sound like a plausible layout?

Share this post


Link to post
Share on other sites
Well first of all can you briefly describe what you are trying to do? What will the text be for? Are you trying to place the name of a player over their heads, for example? Like online FPSs do?

Share this post


Link to post
Share on other sites
Quote:
Original post by Crazyfool
Ok, so I am going to render the text to a sprite and then draw the sprite in the appropriate position that way if a player moves around, the text stays in the same spot.


The term you are looking for is called billboarding, seems like you know what you need to do but I thought you might want a new keyword to search for some tips :) I'm sure theres some billboarding samples in with the DXSDK too.

Share this post


Link to post
Share on other sites
after a bit of searching and playing around with it, it seems I am unaware how to draw sprites in world space (i.e., when I draw a texture, its in a different coordinate system than that of my mouse) and I can only get sprites to draw from mouse coordinates.

Is there an easy/painless way of drawing sprites in world space?

Share this post


Link to post
Share on other sites
Quote:
Original post by Dave
Well first of all can you briefly describe what you are trying to do? What will the text be for? Are you trying to place the name of a player over their heads, for example? Like online FPSs do?


Its for displaying information based on objects/entities in 3d space (like floating attack damage in World of Warcraft)

A player attacks a monster, the damage floats upwards over the monsters head.

Edit: Yes, the names above the head is similar in that sense, I will be wanting to do that as well.

Share this post


Link to post
Share on other sites
Try ID3DXSprite. It allows you to avoid a lot of boilerplate code. When you call Begin(), you should be able to pass in a flag specifying object space for your billboards. From there, you can generate a transform matrix and set it to ID3DXSprite, which will apply it to your sprite.

Share this post


Link to post
Share on other sites
Ah really? However, Billboarding isnt the proper term, at least it can mean other things. I tried searching billboarding and consistently found pages referring to 2d objects that constantly appear facing you. Microsofts example of billboarding is actually a tree that constantly faces you.

I will try tranforming the sprite, I thought you could ONLY draw it in mouse coords - silly me.

Thanks.

Share this post


Link to post
Share on other sites
Not having any luck on this either.

If anyone knows a way to add a sort of floating text above players names that either stands still (i.e. a player name), or floats upwards and fades away (a message alert).

Edit: I have a working sprite (for my gui) and I tried transforming some stuff that previously only drew to the bottom of the screen via screen coordinates.

Original:

d3dspt->Begin(D3DXSPRITE_ALPHABLEND);

D3DXVECTOR3 position(0.0f, 768 - 256, 0.0f);
d3dspt->Draw(guiBotBase, NULL, NULL, &position, D3DCOLOR_ARGB(guiAlpha, 127, 127, 127));

d3dspt->End();


And then I add these lines in:

D3DXMATRIX matText;
D3DXMatrixRotationX(&matText, D3DXToRadian(3.0f));
d3dspt->SetTransform(&matText);


And everything goes poof(cant see it anymore). I though all it should do is merely rotate the sprite by 3 degrees?

Edit2: I've been trying using D3DXMatrixTranslation and setTransform but I cant get that to work either. My world coordinates, which would be at 11,11 when drawing my tiles with the d3device, apparently has nothing to do with this sprite.

When I wanted to draw a texture at 11,11, I'd simply use D3DXMatrixTranslation to get it where I wanted it, then draw it.

[Edited by - Crazyfool on February 17, 2008 2:36:30 PM]

Share this post


Link to post
Share on other sites

This topic is 3586 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.

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