Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


displaying text


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
15 replies to this topic

#1 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 26 October 2012 - 05:47 PM

I am trying to display some text using dx 9 and c++.here is the code I am using.
void DisplaySomeText()
{
D3DCOLOR fontColor = D3DCOLOR_XRGB(255,0,0);
RECT rct;
rct.left=200;
rct.right=600;
rct.top=20;
rct.bottom =40;
g_Font-> DrawText(NULL,"Hello World",-1,&rct,0,fontColor);
}


Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9674

Like
0Likes
Like

Posted 26 October 2012 - 05:57 PM

Do you have a question?

#3 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 27 October 2012 - 12:27 PM

yes in the following code, I am trying to pass in a string to be displayed on the screen.
void DisplaySomeText(string text)
{
D3DCOLOR fontColor = D3DCOLOR_XRGB(255,0,0);
RECT rct;
rct.left=200;
rct.right=600;
rct.top=20;
rct.bottom =40;
g_Font-> DrawText(NULL,text,-1,&rct,0,fontColor);
}
the text field in the drawtext line is giving me an error.

#4 SiCrane   Moderators   -  Reputation: 9674

Like
0Likes
Like

Posted 27 October 2012 - 12:38 PM

It's funny, but error messages often tell you what the problem is. While I can probably guess what your problem is from the code, you should probably examine the error message carefully and try to understand what it means. Try to break it down into pieces and see what parts you can understand and what parts you don't understand. And then ask a specific question about the parts you don't understand.

#5 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 27 October 2012 - 12:46 PM

well I did some research and found the field I am working on is a pointer to a string to draw.I will do more research.

#6 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 27 October 2012 - 01:53 PM

where is a good tutorial for displaying text on the screen using dx9 and c++

#7 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 27 October 2012 - 03:31 PM

I am getting a runtime error with this line of code.
g_font-> DrawText(NULL,"HelloWorld",-1,&rct,0,fontColor);
everything else appears ok
let me know if you need more code.

#8 BeerNutts   Crossbones+   -  Reputation: 3018

Like
1Likes
Like

Posted 27 October 2012 - 08:49 PM

I am getting a runtime error with this line of code.
g_font-> DrawText(NULL,"HelloWorld",-1,&rct,0,fontColor);
everything else appears ok
let me know if you need more code.


POST THE FRIGGING ERROR PHIL.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#9 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 27 October 2012 - 09:21 PM

I am SORRY beer let me get back to you.

#10 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 27 October 2012 - 09:29 PM

here is the error I am getting Unhandled exception at 0x00C93488 in pong.exe: 0xC0000005: Access violation reading location 0x00000000.

#11 Endurion   Crossbones+   -  Reputation: 3692

Like
0Likes
Like

Posted 27 October 2012 - 11:39 PM

Did you call D3DXCreateFont anywhere to initialize g_font? g_font seems to be NULL.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

#12 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 28 October 2012 - 03:42 PM

I tried initializing D3DXCreateFont g_font = NULL; I am still stuck.

#13 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 28 October 2012 - 07:51 PM

I have done extensive research on this topic and have done a lot of reading, I don't know what to do next.

#14 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 28 October 2012 - 08:00 PM

well I finally solved this problem thanks for all the help.

#15 NightCreature83   Crossbones+   -  Reputation: 3036

Like
0Likes
Like

Posted 29 October 2012 - 03:42 AM

The fix is .c_str() on the std::string you are passing in. DrawText wants a pointer to the first character of the string array. When documentation states that it wants a pointer to a text string and is defined as LPCSTR it means that it wants a pointer to the first element of the character array of a string. Std::string is a wrapper over a dynamically resizing character array, to get access to the raw memory you need to use the function "c_str()"

Edited by NightCreature83, 29 October 2012 - 03:42 AM.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, Mad Max

#16 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 29 October 2012 - 02:13 PM

cool thanks I solved my problem




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS