Jump to content
  • Advertisement
Sign in to follow this  
stdiotayler

How can I get effects from KeyboardFunc() immediately?

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

First, I draw a rectanglar, and I want the rectanglar to move up when I press "w". But the rectanglar doesn't move up immediately, it will move up when I resize the window only. How can I make the rectanglar to move up as soon as I press 'w'. Thank you very much. Here is my code: #include <GL/glut.h> #include <stdlib.h> #include <stdio.h> static GLuint a=390; static GLuint b=20; static GLuint c=410; static GLuint d=44; void display() { glEnable(GL_LINE_SMOOTH); glEnable(GL_POINT_SMOOTH); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0,0,.9); glRectd(a,b,c,d); glFlush(); } void init() { glClearColor(1, 1, 1, 1); glShadeModel(GL_SMOOTH); } void reshape(int w, int h) { glViewport(0,0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, (GLdouble)w, 0, (GLdouble)h); } void keyboard(unsigned char key, int x, int y) { switch(key){ case 'w':/*go up*/ b+=100; d+=100; break; default: break; } } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(800, 600); glutInitWindowPosition(100,100); glutCreateWindow("War of Tanks"); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }

Share this post


Link to post
Share on other sites
Advertisement
Since you are using GLUT, call glutPostRedisplay() to cause a refresh
Put it in your keyboard function.

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!