Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Text output code

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

void text(char* pstring,float x,float y,DWORD c)
      vertex* pverts = 0;
      for(int x = 0; x < 2112; x++)
         pverts[x].c = c;
      int col = 0;
      int row = 0;
      int len = strlen(pstring);
      int idx = 0;
      int max = 0;
      for(int i = 0; i < len; i++)
         if(pstring[i] > 31 && pstring [i] < 127)
            idx = (pstring[i] - 32) * 4;
            if(col > max)
               max = col;
         if(pstring[i] == ''\t'')
            col += 4;
         if(pstring[i] == ''\n'')
            col = 0;
      report("Lost the device. Fix this already.");
      func = 0;

// this is the code i use to create the vertex buffer if anyone is wondering

That code works fun until the locking/unlocking gets uncommented. Why would that mess things up? There are 2112 verts in the buffer, so no overflow or anything in the loop. Can you call Lock on a vb once you''re in BeginScene? this function is called after BeginScene, and when I initialize the verts, that''s before BeginScene so that''s the only thing I can think of.

Share this post

Link to post
Share on other sites
Usually if you want text to be drawn on a texture, and then map
it to the polygon, you don''t make each of the characters a
polygon by itself. Try drawin'' text onto your own bitmap (or
whatever) usin'' Win32 DrawText() function, and then lock the
texture and copy that bitmap onto it.

Note that however if you''re usin'' DrawText() to draw on a 32-
bit bitmap, the function is gonna reset the alpha to zero for
those areas your text is coverin'' (this will effectively make
the text area totally transparent).

Hope that helps.

Share this post

Link to post
Share on other sites
In my text drawing function I use:
right before drawing the text primitives
and before rendering any text I set the states:
pdev->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
pdev->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
pdev->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TFACTOR );

Oh, and to speed things up some, you should look at putting all of your characters into one vertex buffer and rendering them in one call. (You seemed to of had the right idea in the commented out code, you just didn''t perform it correctly). This will require that you create an algorithm to create the vertex positions at runtime, but it shouldn''t be too hard. Also, you can lock / unlock buffers while drawing, just don''t do it too much, and make sure they are write only.

Share this post

Link to post
Share on other sites
Thanks for the replies. Didn''t think to draw text onto a texture... good idea.
What I''ve done (was rushed, didn''t communicate effectively (sorry)) is load a bitmap as a texture. On the bitmap I''ve drawn the whole font (8 rows of 16, haven''t drawn the other 128 characters yet (and probably won''t, i''ve got what i need)) and wrote an algorithm to generate the texture coordinates for the image. Everything was working delightfully. It displayed the white text (as I had drawn it) exactly as I was expecting. When I tried to put the lock/unlock code in to change the color, it stopped appearing.
And to hawkeye, all my verts are in a buffer (write only) created at startup. I wasn''t generating new data every frame (I''m not TOTALLY newb ) But thanks for checking.
Just tried your color method hawkeye, works like a charm (and saves me from modifying 1024 verts). Thanks for the tip. Never even knew about that render state hehe.
Thanks all

Share this post

Link to post
Share on other sites

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