Jump to content
  • Advertisement
Sign in to follow this  
np2100

OpenGL handling key presses

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

Hello, I am very new to OpenGL and SDL and I've been playing around with it. I have been able so far to change the background color by pressing different keys. Now I am wondering how I can move a shape up or down by hitting a key. For example: case SDLK_1: glTranslatef( -1.5f, 0.0f, -6.0f ); break; This doesn't work. I expected it to move the shape in the drawGLScene but it didn't. Does anyone know another way of doing this?

Share this post


Link to post
Share on other sites
Advertisement
It might be better to put the glTranslate in your draw code and use a variable to communicate the amount of translation. In other words, your draw code (which is elsewhere) might look like this:

glPushMatrix();
glTranslatef(-1.5f, 0.0f, ztrans);
DrawStuff();
glPopMatrix();

and then in your SDL code:
case SDLK_1:
ztrans=-6.0f;
break;

This way you don't have to wonder where in the OGL stream the translate comes.

Share this post


Link to post
Share on other sites
I tried doing that but since they are in different functions it says ztrans is undeclared. So how do I get the key handling into the draw function to change it.

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!