Jump to content
  • Advertisement
Sign in to follow this  
bvs33

Applying a texture to text

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

I know D3DXCreateText will give me a mesh of text, but is it possible to apply a texture to the letters? If so how? Just setting the device texture before rendering doesn't appear to work.

Share this post


Link to post
Share on other sites
Advertisement
You have to apply texture coordinates to the mesh, as D3DXCreateText doesn't do that.

Share this post


Link to post
Share on other sites
ah... that makes sense. But how do I access the vertex structure to add a u,v coordinate? Isn't it locked away in a DX library somewhere?

Share this post


Link to post
Share on other sites
Hi there bvs33,
how are you doing?

[What is happening?]
Well, essentially the D3DXCreateText just creates a mesh. What you do with the mesh afterwards is up to you :)

[How can I add texture coordinates?]
Since you have a constructed mesh, you can now add texture coordinates at your leisure. What you want to do is Clone the mesh and add the texture coordinates.

Eg
[source lang = c++]
D3DVERTEXELEMENT9 elements[] =
{
{ 0, sizeof( float ) * 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, sizeof( float ) * 3, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, sizeof( float ) * 6, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};

LPD3DXMESH temp;
if ( FAILED( pMesh->CloneMesh( D3DXMESH_MANAGED, elements, pDevice, &temp ) ) )
{
pMesh = NULL;
return;
}

pMesh->Release();
pMesh = temp;



this will clone the mesh and give it the new vertex format. Now you have a mesh with the texture coordinates specified.

[How do I access the texture coordinates]
You could lock the vertex buffer and access each indivial vertex using,
ID3DXMesh::LockVertexBuffer:
"Locks a vertex buffer and obtains a pointer to the vertex buffer memory."

I hope this helps a bit.

Share this post


Link to post
Share on other sites
Quote:
Original post by Armadon
[How do I access the texture coordinates]
You could lock the vertex buffer and access each indivial vertex using,
ID3DXMesh::LockVertexBuffer:
"Locks a vertex buffer and obtains a pointer to the vertex buffer memory."


Ok, I have the mesh cloned using ID3DXMesh::CloneMeshFVF() and I used the following FVF format: D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1

So I should have a mesh that has texture coordinates now, but I'm not sure how to set values for them and I can't find any code in the samples that helps me out.

Anyone have any example code that can walk me through looping though each vertex in my text and computing the texture coords I need to set?

Share this post


Link to post
Share on other sites
hi,

I don't know what you want to see in the end, but maybe you could just blend the texture over the text after rendering it as it is?
what would you like to get as a result?

kp

Share this post


Link to post
Share on other sites
I'm looking to apply a texture to the text mesh I get back so it looks like the text is made up of the texture I apply.

For example, if my texture is brick, I want the letters to look like they are made of brick.

Share this post


Link to post
Share on other sites
Heres how I think this should be done:

1) Render the text to a texture, using an alpha only color (0xFF000000).
2) Use the texture generated to render you color texture, while using the generated texture as an alpha mask.

This would be quite quick, I think. Would this method be okay for your needs?

Share this post


Link to post
Share on other sites
I think the original advice I got about manipulating the textue coords of the cloned mesh and then simply applying the texture is the "correct" way to go about it.

I just can't figure out the equation I'll need to use to figure out the correct numbers to set for each texture coordinate within the mesh.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!