Sign in to follow this  
DirkDaring

A Simple Text Problem

Recommended Posts

DirkDaring    148
A simple text problem Hello. I’ve been creating a 2d ORPG in Windows/Directx, and I need to solve a simple problem of drawing text on the screen based on user input. Basically I just need the program to check to see if any character between A to Z has been pressed, and if so store it as the next character in a char array or buffer. Printing the array onto screen after that should be a no-brainer, but I got a question about that too, afterwards. So the pseudo code should be like this: If (character between A to Z (or space) is pressed) Then (find out which character was pressed and store it as the NEXT character in the buffer) Print Buffer onto (window) screen. Seems real simple, but the game must continue to loop at all times, so basic input like CIN, CIN.GET, CIN.GETLINE, is out of the question because they pause until input is received. Using windows VK code messages has done me well in the past, for simple input, but I can’t imagine putting, say 255 possible character/VK code checks every loop just to see if a key was pressed and if so which key it was, plus, I’d like to put this routine outside of the Winproc function anyway. I HAVE done research, it’s just that I have a weekend deadline, so I kinda need a quick and easy answer if anyone has one. As for printing text to a window, so far I have been using the trusty ole’ Draw_Text_GDI() function, but I’ve seen people use Directx functions to draw text too. I DO use Directx in my game. Which function would you recommend for fasted execution and most features? Thanks in advance for any help, you guy’s have done me we’ll in the past!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Sounds good so far, now does the wParam give you the actual character, or just another character code (which again would need translation(bad)). In the mean time I'll try to write a quick program to test if it works. Anyone still have an answer to the best way to draw text onto a Window? (Directx, GDI, other)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Quote:
Original post by Anonymous Poster
Sounds good so far, now does the wParam give you the actual character, or just another character code (which again would need translation(bad)). In the mean time I'll try to write a quick program to test if it works.


It gives you the acsii value of the key. Just cast to a char if its in the range you want to handle, ie upper/lowercase and number else handle it however you want.


Share this post


Link to post
Share on other sites
DirkDaring    148
Sounds good! I think it should work just fine! Thanks a bunch! Other then that if anyone could recommend the best text drawing function for windows (directx function, windows GDI) that would great! Other then that, I think I'm on my way. Thanks again!

Share this post


Link to post
Share on other sites
Bob Janova    769
Just to throw a spanner in the works, going back to the keyboard thing, you can use GetAsyncKeyboardState to find out if any keys have been pressed since you last checked. It will fill a boolean array so you get information for all 100+ keys in one call.

If your game is in DirectX you should probably use a DirectX drawing function to write the text. I can't help you there, unfortunately, as I'm an OpenGL guy (when I even write 3D code).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this