Advertisement

DirectDraw Display Text

Started by January 14, 2003 07:20 PM
6 comments, last by Turt99 21 years, 10 months ago
Okay I''m trying to learn DirectDraw and trying to create my own game, so what I want to do now is just display some text on the scree, just so that I could maybe use it for testing or something... anyways I''m using DirectDraw 7 so is there an easy way to display text on the screen? any help would be great I''ve looked all over the internet but nothing I fix will work Please visit Turt99 Productions
FOLLOW ME ON TWITTER OR MY BLOG
PAINTSTRUCT ps;
HDC hdc;
char buffer[80];
//Text goes here



I think this is right?? someone correct me if im wrong
And this is what ur askin for right?
Advertisement
quote: Original post by Bakingsoda36
PAINTSTRUCT ps;
HDC hdc;
char buffer[80];
//Text goes here



I think this is right?? someone correct me if im wrong
And this is what ur askin for right?


All that will do is set up 3 Variables and then not use them...
What I want to do is place a string of text on the screen in DirectDraw... What you gave me maybe leading to something, but it doesn''t seem to be complete.

Please visit Turt99 Productions
FOLLOW ME ON TWITTER OR MY BLOG
there has to be a way to do this... for example how do you normally output the framerate of a program so that you can see it at all times..

Alot of people do this so its can''t be that hard to do

Please visit Turt99 Productions
FOLLOW ME ON TWITTER OR MY BLOG
look into using GDI with directx. Tricks of the Windows Game Programming gurus has a section on doing so, so there must be more information out there.

A popular way to do text with directX is to make a bitmap with the alphabet on it and just blit the letter you want at any moment. I haven''t actually done this yet, but I imagine this would work

First, create a bitmap with all the characters you wish to display. Make them all the same size, you don''t need a variable width text display. Make each character around 16*16 and make the whole bitmap 16 pixels on the y and 4096 on the x(16 pixels for 256 characters) You''ll have a long bitmap with 256 spots to put characters. You don''t have to use them all, this will just be so you can do this(:
char message = "This is a message";int i = 0;while(message != ''\0'') {    blitLetter(message, i);<br>    i++;<br>}<br><br>…<br>blitLetter(char letter, int i) {<br>// rectarray stores coordinates of each letter, destinationRect stores destination coordinates<br>// for the screen to put the letters.  <br>bltRectToRect(rectArray[letter], destinationRect);<br>} </pre> See how this would work?  </i>   
Yup, I see what you mean, I guess I was just hoping there was an easier way to do the whole text thing... thanks for your help..

I got the Guru''s book so I''ll look into that GDI stuff.. maybe I can figure it out..

Please visit Turt99 Productions
FOLLOW ME ON TWITTER OR MY BLOG
Advertisement
Get a valid device context, getdc() i think

Then look into the TextOut function, pretty sure thats how I did it in my dx5 programs, can't check cos I'm not at home.

[edited by - error on January 15, 2003 11:06:00 AM]
_____________________________error: does not compute!

The function below is what I use to draw text onto a directdraw surface (directx 6).
m_pDDSurface (inside the function) is the backbuffer. You could add this as a parameter to the function. This way you can draw text onto ALL your surfaces if you wanted to (probably useless, just a thought).

As you can see the first parameter is something called a logfont.
A logfont is a description of the font you want to use.
It is just a struct. You fill it with as much info about your desired font as possible and windows will choose the nearest font it can find.

Before calling the type function you should create and init a logfont like this:



IN YOUR .h file:

		LOGFONT MyLogFont;		HFONT hFont;		HDC hdc; 

IN YOUR INIT FUNCTION OR CONSTRUCTOR:

		ZeroMemory(&MyLogFont, sizeof(MyLogFont));		strcpy(MyLogFont.lfFaceName, "Arial");	   //choose your font..		MyLogFont.lfQuality = ANTIALIASED_QUALITY; //it does not always antialiase. Don´t know why not..? 


void Type(LOGFONT *lgf, int x, int y, int Size, char *szText, byte r, byte g, byte b){	lgf->lfHeight = Size;				//Size of font...You can use negative numbers as well..	m_pDDSurface->GetDC(&hdc);			//Get GDI Device Context	hFont = CreateFontIndirect(lgf);		//Create font based on our logfont	SelectObject(hdc, hFont);			//Select font just created.	SetBkMode(hdc, TRANSPARENT);			//No borders around text please.	SetTextColor(hdc, RGB(r,g,b) );			//Set color based on RGB values	TextOut(hdc, x,y, szText, lstrlen(szText));	//Write text to our DirectDrawSurface.	DeleteObject(hFont);				//Delete font after use.	m_pDDSurface->ReleaseDC(hdc);			//Release Device Context.} 




You may have to include some of these files:

#include <windows.h>
#include <ddraw.h>
#include <stdio.h>
#include <string.h>


-granat, GameDev.net
-------------Ban KalvinB !

This topic is closed to new replies.

Advertisement