Sign in to follow this  

Multi input?

This topic is 3723 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

Hallo, I am looking for a command or library which lets me input several things at the same time. Say move right and move forward. Right now im using glut, and I cant get it to work, maybe I am doing something wrong?
switch (key) 
{
   case GLUT_KEY_LEFT : 
     // stuff
     break;

   case GLUT_KEY_RIGHT : 
     // stuff
     break;	
	
   case GLUT_KEY_UP : 
     // stuff
     break;

   case GLUT_KEY_DOWN : 
   // stuff
   break;
}

Share this post


Link to post
Share on other sites
Declare a boolean array, then in the function which goes to glutSpecialFunc set key to the array access point, like "keyArray[key]". Then:

For glutSpecialFunc you would have "keyArray[key] = true".

For glutSpecialUpFunc you would have "keyArray[key] = false".

Then just make a function for glutIdleFunc and make a series of checks like:

if (keyArray[GLUT_KEY_UP]){//Move up}
if (keyArray[GLUT_KEY_RIGHT]){//Move right}

That said, I would highly recommend that you try using SDL if you plan on making games, because GLUT (as simple as it seems) is not that well suited for game functions. SDL and OpenGL work great together, as you can see in this tutorial:

http://lazyfoo.net/SDL_tutorials/lesson36/index.php

Full source code is at the bottom of the page.

Share this post


Link to post
Share on other sites

This topic is 3723 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.

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