ASCII & DirectX9 Under C++

Questions regarding game mechanics and graphic programming should go here.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

ASCII & DirectX9 Under C++

Postby Wayne » Tue Oct 24, 2006 8:33 pm

I'm using ID3DXFont::DrawText to print ASCII chars to the screen. However, it will not print any special characters like the smiley faces (alt 1 & 2) for example. It outputs only '?' when a char like that is given to it.

Code: Select all
font->DrawText(NULL, LPCSTR("☺~"), 2, &rct, DT_NOCLIP, fontColor );
Output: "?~"


I am programming a game with ASCII graphics, so I would naturally need access to those characters. I'm sure that is another way, but how do I do it? Custom font file? I would also like to have the ability to make custom characters for the game so that I could use those along-side the ASCII characters, for, lets say, an upside down smiley face? I heard you could do something along the lines of mapping your character set to a bitmap and using that somehow, but I am not sure how to implement that.

Is there a better way to do this whole thing altogether? I will be redrawing the screen full of ASCII characters constantly so if there is a better/faster method of doing this I'm all ears.

Any help would be much appreciated,
Wayne
Wayne
 
Posts: 5
Joined: Tue Oct 24, 2006 8:13 pm

Postby MXP » Wed Oct 25, 2006 1:57 pm

You cannot simply cast a string literal to an LPCSTR. You need to use the TEXT() macro.

font->DrawText(NULL, TEXT("☺~"), 2, &rct, DT_NOCLIP, fontColor );
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby Wayne » Thu Oct 26, 2006 6:13 am

Still no dice, I get the same output.
Code: Select all
font->DrawText(NULL, TEXT("☺~"), 2, &rct, DT_NOCLIP, fontColor);

Output: "?~"


Are those special charicters a unicode extension of the 'terminal' font? :?
Wayne
 
Posts: 5
Joined: Tue Oct 24, 2006 8:13 pm

Postby Wayne » Thu Oct 26, 2006 6:27 am

WAIT, I figured it out!
The problem seems to be that my c++ file was unable to properly represent the character so instead sent it a ?. This code works:

Code: Select all
char TestString[3];
TestString[0] = char(1);
TestString[1] = char(2);
TestString[2] = char(3);

font->DrawText(NULL, TestString, 3, &rct, DT_NOCLIP, fontColor);

Output: "☺☻♥";


Ok, now what does the TEXT macro you talked about do? (I can't find a reference on the net or MSDN)
Wayne
 
Posts: 5
Joined: Tue Oct 24, 2006 8:13 pm

Postby MXP » Thu Oct 26, 2006 11:12 am

String literals are, by default, encoded in a single byte character set. Starting with VS 8.0, Unicode support is turned on by default for Microsoft APIs (such as the Win32 API and DirectX) - this requires that strings are encoded in a multibyte character set.

The TEXT() macro is sensitive to whether or not Unicode support is turned on - when it isnt the macro does nothing but when it is the macro converts the string literal into a multibyte encoding.

Casting does not do this conversion. When you cast you are telling your compiler "yes, I know that you think the variable is of type A but I actually know that it is also of type B". In your code you were trying to convince the compiler that a single byte character string was a multibyte character string but this cannot be true.
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby Wayne » Fri Oct 27, 2006 7:29 am

Ok, new question.

What would be an efficient way to output 2960 differently colored ascii chars to the screen?

Currently the only way I can think of is by calling ID3DXFont::DrawText 2960 times every frame after incrementing the 'rectangle' and setting the new color of the ascii char.

There has to be a better way! :?

EDIT: It's the color that's killing me, I can output a string 2960 chars long no problem, but if I want color, I have to recall ID3DXFont::DrawText with the new color every time...
Wayne
 
Posts: 5
Joined: Tue Oct 24, 2006 8:13 pm

Postby Wizard » Fri Oct 27, 2006 10:57 am

Just a stupid question here, but bear with me.
If you're only using ascii graphics, why are you using ID3DXFont? That's a little like smashing a walnut with a sledge hammer, isn't it?
Can I suggest something?
http://msdn.microsoft.com/library/defau ... ribute.asp
example:
http://support.microsoft.com/default.as ... -us;816179
User avatar
Wizard
Site Admin
 
Posts: 3250
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA

Postby Wayne » Sat Oct 28, 2006 1:01 am

Believe it or not that's even slower. Plus I plan on using some of the functionality that windows and d3d provide that a console would not be able to.
Wayne
 
Posts: 5
Joined: Tue Oct 24, 2006 8:13 pm


Return to Games and Graphics

Who is online

Users browsing this forum: No registered users and 2 guests