Jump to content
  • Advertisement
Sign in to follow this  
h3ro

Multi input?

This topic is 3968 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!