Advertisement

Outputting text while not in a console...

Started by May 14, 2001 05:25 PM
9 comments, last by Moe 23 years, 8 months ago
Is there any easy way to output text to the screen if the program is NOT a console? I say NOT because I already know about cout and the like, but they only work in consoles. I am using a fullsceen program, and I just need a way to output. I have already looked at the DirectX8 2d text things but they seem rather complicated for what I want to do. Anyone?
Well, if you are only needing it for Debuging, you could output text to a file using fstream.h or something. That is what I do. It works great. So if you don't know how you use it, here is some code:

     #include <fstream.h> // Must include this// Create the file object. The file name will be "Debug.txt"ofstream DebugFile("Debug.txt");int main() {  char Text[20];  // output to the file, just like using cout<<  for(int x = 0; x <= 10; x++) {        sprintf(Text, "%i", x);        // Write to the file        DebugFile<< Text <<"\n";  }  return 0;        }    


Now, if this is not for debuging information and you just want text on the screen. You have to eiter use GDI or write your own text engine.

Well, I hope that helps.

Later.



Edited by - JSCFaith on May 14, 2001 7:49:06 PM
Advertisement
Its for outputting the Frames Per Second, so I am not sure how well outputting it to a text file every frame will work. Thanks for the reply tho.
Well, you could use GDI. Here is some sample code.

  HDC hdc;char str[100];lpDDSBack->GetDC( &hdc);	SetBkMode( hdc, TRANSPARENT );	sprintf(str, "Frame Rate: %i", FrameRate);	TextOut(hdc, 0,0 , str, strlen(str));	lpDDSBack->ReleaseDC(hdc);	  


Well, that should work. Although it is slow, it will work for a while until you write your own text engine. Which, BTW, is not very hard to do.

Well, good luck with whatever you are working on.

Later,
James
Oh for the love of God, don''t you people ever look at disassembled Windows apps?

Console apps work just like Window apps, except their WinMainCRTStartup() calls AllocConsole() for them. So maybe you should look into that function.

I''d flywieght a GDI character set and copy the DC bitmaps into textures and billboard them onto the screen.

There''s also DrawTextA/D3DXCreateFont stuff in D3DX

Magmai Kai Holmlor
- The disgruntled & disillusioned
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
I have looked into the DirectX method that they use in the SDK programs but I have had trouble getting it to work. Could anyone explain how to use it to me?
I just switched to BlitFasting text to the screen. All you need is an offscreen surface with 256 ascii characters. I have it arranged 16x16.


  void ddTextOut(short x, short y, char string[1024], short length){	for(CurrLetter=0;CurrLetter<length;CurrLetter++)	{		LetterBox.top    =  (string[CurrLetter]/16)*15+1;		LetterBox.left   =  (string[CurrLetter]%16)*15+1;		LetterBox.right  =  LetterBox.left+LetterSize[string[CurrLetter]];		LetterBox.bottom =  LetterBox.top+15-3;		lpDDSBack->BltFast( x, y, AsciiTable,&LetterBox, DDBLTFAST_SRCCOLORKEY );		x+=1+LetterSize[string[CurrLetter]];	}}  


I may eventully switch it to use DrawPrimitive so I can scale the font.

Ben
http://therabbithole.redback.inficad.com

I did nearly have my own font engine complete but I was using DirectX7 and I have switched to DirectX8 since.
quote:
Original post by JSCFaith

Well, you could use GDI. Here is some sample code.



Could this be done in DirectX8?


Edited by - Moe on May 19, 2001 12:53:37 PM

This topic is closed to new replies.

Advertisement