Text in DirectDraw

Started by
0 comments, last by Roof Top Pew Wee 22 years, 8 months ago
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--
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// BackBuffervoid DrawFont(char* Text, int x, int y){//---------------------------------------------------int CharCode;	// ASCII value of the current letterRECT rcFont;	// the Location of the Letter on the BitmapRECT 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 backbufferfor (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
DracosX:Master of the General Protection Fault

This topic is closed to new replies.

Advertisement