• Advertisement

Archived

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

Text in DirectDraw

This topic is 6053 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 was wondering if anyone had any text blitter functions that they wouldn''t mind sharing using DirectDraw, and if not, any pointers as to how to go about writing one. Thanks. --Vic--

Share this post


Link to post
Share on other sites
Advertisement
There''s a great tutorial here on GD about just this, but I don''t remember the URL. It''s in VB, but I''ll show you the one I wrote in C++. If you''ve had any experience with tile engines, this will be a whole lot easier.

NOTE: This only works right if your letters are fixed-width.

The main thing is to create your bitmapped fonts in ASCII order.
Look up the ASCII Character tables on MSDN.

Then when you recieve a WM_CHAR message (not sure on how to do it with direct input, but this is actually quite fast) just use the scancode as a tile index.


  
#define CHAR_WIDTH 16
#define CHAR_HEIGHT 16
#define CHARS_PER_ROW 16;

// This code assumes you have a globab backbuffer created named

// BackBuffer


void DrawFont(char* Text, int x, int y)
{

//---------------------------------------------------


int CharCode; // ASCII value of the current letter

RECT rcFont; // the Location of the Letter on the Bitmap

RECT rcDest; // The Location onscreen to Blt the tile to


//---------------------------------------------------



rcDest.left = x;
rcDest.top = y;


// NOTE: i is a UINT because I got sick of the signed/unsigned

// mismatch warning in MSVC++


// Blt each letter in the Text string onto the backbuffer

for (UINT i = 0; i < (strlen(Text) + 1); i++)
{
// Select the CharCode;

CharCode = (int)Text[i];

if (CharCode == (int)''\n'')
{
rcDest.top += CHAR_HEIGHT;
rcDest.left = x;

rcDest.right = rcDest.left + CHAR_WIDTH;
rcDest.bottom = rcDest.top + CHAR_HEIGHT;

continue;
}

rcDest.right = rcDest.left + CHAR_WIDTH;
rcDest.bottom = rcDest.top + CHAR_HEIGHT;

// Initialize each tile''s locations on the Tileset

rcFont.left = ((CharCode % CHARS_PER_ROW) * CHAR_WIDTH);
rcFont.top = ((CharCode / CHARS_PER_ROW) * CHAR_HEIGHT);
rcFont.right = ((rcFont.left) + CHAR_WIDTH);
rcFont.bottom = ((rcFont.top) + CHAR_HEIGHT);

// Blit the letter

BackBuffer->Blt(&rcDest, FontBmp, &rcFont, DDBLT_WAIT | DDBLT_KEYSRC, NULL);

rcDest.left += CHAR_WIDTH;

}

}


This is acurate to the best of my memory.



DracosX:

Master of the General Protection Fault

Share this post


Link to post
Share on other sites

  • Advertisement