Skip to content
Advertisement

PyOpenGL Taking keyboard input

I’m trying to make a raycaster in Python with PyOpenGL and i accomplished to make a little yellow square. Main thing is that i need keyboard input to move my square and i made something but it is not working. Here is the code:

JavaScript

Why this code is not working?

Advertisement

Answer

Define px and py in global namespace:

JavaScript

Use the global statement to change the variables in the global namespace within the button callback. Use the bytesprefix to compare the key to a letter (e.g. key == b'a'). Invoke glutPostRedisplay to mark the current window as needing to be redisplayed:

JavaScript

Complete example

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement