ID3DXFont - Begin / End

Started by
7 comments, last by devlaxe 20 years ago
I was playing around with ID3DXFont (I''m using DX8) and found it boring, so I made my own font system that works from a bmp. Basically it loads a bmp containing the characters and stores it on a surface. When ever I draw text it copies rects from the surface to a texture and draws a quad with the texture on it. Its pretty simple and probably not that efficient, but I can rotate, scale and multi-texture so I''m happy(er). My problem is that the characters lose all of their color (ie they end up black) unless I perform the draw method between the ID3DXFont::Begin / End. I can''t figure out why this is because I don''t have anything in my code that references the the font interface and all my other graphics end up showing up normally. Is there something I''m missing that is happening between the Begin/End methods? Thanks in advance..
Advertisement
if your font is white, you can change the color with if you simply modulate the end quad (either through diffuse color, tfactor or something else)
Thanks, thats a good idea.. and it works well. Only its the same problem.. the texture ends up black unless I put the draw statement between a Begin/End.

..after a bit more playing...

If I do this before the draw:

SetTextureStageState(1, D3DTSS_COLORARG1 , D3DTA_CURRENT);

it works fine.. I get the color of the original bmp (or the diffuse color I set). Then after the draw I disable it using:

SetTextureStageState(1, D3DTSS_COLORARG1 , D3DTA_TEXTURE);


I suspect that you might have problems with lighting. Try diabling lighting.

Also, why do you transfer it to a surface and then to a texture? Why not just read the whole thing directly into a texture? If you''re doing this so you can grab a rectangle then I would say you could do that simply by adjusting the UV coordinates of your quad. I think this would improve performance, but I could be wrong. I''m fairly new to all this.

"Good code will come and go, but bad code sticks around."
"Good code will come and go, but bad code sticks around."
Well its not the lighting because I have disabled it or at least I think I have.

Is this all I have to do to disable it?
m_pkD3DDevice->SetRenderState ( D3DRS_LIGHTING , FALSE ) ;


I''m not sure how I would implement what you''re suggesting regarding the UV coords unless I draw multiple quads (one for each character). I''m pretty new at this stuff too so maybe I''m just not understanding what you mean..
I was suggesting one quad for each character but I see your point that this might not be faster. Still, you could render it all with a single call to DrawPrimitive if you stored them as a triangle strip or triangle list so I think it would still be fast. However it could be more difficult to rotate this than your way of doing it. On the other hand you could rotate each character separately and do "word art" (like bending a word, etc.) but that's probably not something that's very useful anyway.

"Good code will come and go, but bad code sticks around."

p.s. You might want to make sure your doing your transparency (alpha stuff) correctly. Do you have alpha test enabled? etc.

[edited by - TreborZehn on March 25, 2004 12:57:18 PM]
"Good code will come and go, but bad code sticks around."
I see what you mean now about how just using a texture could be faster.. and certainly more flexible from the point of view that as you said you would be able to rotate each character.

As for the alpha stuff I think I've got it setup right..
m_pkD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE );
m_pkD3DDevice->SetRenderState(D3DRS_ALPHAREF, 0x01);
m_pkD3DDevice->SetRenderState(D3DRS_ALPHAFUNC,D3DCMP_GREATEREQUAL);

When I load a bmp, I specify the transparent color and set all pixels of that color to have an alpha of 0.

[edited by - devlaxe on March 25, 2004 4:23:27 PM]
Looks reasonable. A few more debug ideas...

1) Try using the D3DDEVTYPT_REF if you haven''t already.

2) By-pass loading your texture into a surface and just load a small texture onto your quad and run your render code.

3) turn off all alpha test/transparency, etc.

"Good code will come and go, but bad code sticks around."
"Good code will come and go, but bad code sticks around."
Sounds good, I''ll give it a try.

Thanks again for all the help.

This topic is closed to new replies.

Advertisement