Jump to content
  • Advertisement
Sign in to follow this  
AvengingRage

OpenGL and stdin

This topic is 3646 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, first post here, glad to be a part of GameDev.net Anyway on to the question. I am trying to program a Rubik's Cube game. So far I have everything running. I have a tutorial explaining the controls, a functioning game page, a save/load function, and a "low" score page. The only thing I can't figure out is a problem with taking input from the user. I obviously use the keyboard for controls but this is done through windows messaging and the use of the virtual keyboard. In this small section, however, I need to take the user's initials. I have the game keep track of the number of moves to solve the cube and when it is solved it checks against the current list of low scores and if a new low score has been recorded it inserts it into the list. The list checking works perfectly, it inserts the new score correctly (pushing everything further down the list), but I can't seem to get it to take the user's initials correctly. Here is the code for this section: if(newlowscore == true) { for(int i = 9; i > lowscorepos; i--) { lsnums = lsnums[i-1]; lsnames[i*3] = lsnames[(i-1)*3]; lsnames[i*3+1] = lsnames[(i-1)*3+1]; lsnames[i*3+2] = lsnames[(i-1)*3+2]; if((i-1) == lowscorepos) lsnums[i-1] = movect; } lsnames[(lowscorepos*3)] = 'N'; lsnames[(lowscorepos*3+1)] = 'E'; lsnames[(lowscorepos*3+2)] = 'W'; LowScoresPage(fonts, lsnums, lsnames); glRasterPos2f(0.0f, 0.6f); glPrint(fonts[4], "Enter your initials..."); char initials[3]; cin >> initials[0] >> initials[1] >> initials[2]; lsnames[lowscorepos*3] = initials[0]; lsnames[lowscorepos*3+1] = initials[1]; lsnames[lowscorepos*3+2] = initials[2]; } As you can see, if a new low score has been made, it refills the list, sets the name to "NEW" although this should be temporary, and then is SUPPOSED to take in the user's initials. The cin command there is just one of the long list of failed methods I've tried to use. LowScoresPage is just a routine that draws the list of lowscores based on arrays of names (lsnames) and scores (lsnums). As I said, all of this code works perfectly except for accepting user input. It doesn't seem to take any input at all and sets the initials to " ". Is there someway to force windows to take in 3 characters? I don't want to have to use windows messaging because then I would have to loop back through the game loop. I know there must be a simple way to take 3 characters of input here, but for the life of me can't figure it out. If anyone could help, I'd really appreciate it. If you need any other information about the program, the variables or functions here, just ask! Thanks!

Share this post


Link to post
Share on other sites
Advertisement
You have to use the Windows API / DirectInput / SDL / whatever to read input.

Share this post


Link to post
Share on other sites
I realize that I cannot use the standard input, I simply left the code in there because that was the last thing I tried. I also realized I would have to somehow use the Windows API but I haven't used it that extensively and was looking for a pointer in the right direction.
Bad pun aside, my main question is which functions should I be looking for? Doing some searching I find the kbhit() function in the conio.h header file which apparently waits for keyboard input but I can't get this to work properly.

Share this post


Link to post
Share on other sites
Well, windows handles text input by sending WM_TEXT messages to your application, so that's probably how you should handle it. Or use a library like SDL, which agains deals with messages and events.

You could try the GetKeyState or GetAsyncKeyState Win32 functions to get the state of a key, but it treats keys as virtual keys, not characters, so you won't get uppercase-lowercase differentation, and there might be some problems with repeating(when the user holds down a key).

Share this post


Link to post
Share on other sites
Well, I buckled and used windows messaging. I just used a global boolean for whether a new score had been set, and then a global int to be used as a counter for how many initials had been entered. I was hoping there was a simple way to read in some input without having to loop back through my game loop (the part that translates/dispatches messages is at the beginning) but I suppose of that's the way it must be done, that's the way it must be done. Thanks guys!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!