Interesting error! So I played around with your source code (by the way in the future you should probably just add the code directly to your question instead of as a separate link), and the issue is actually just one of variable scope, not glut or opengl usage. The problem is your texture_background
variable does not exist within the scope of the _draw_scene()
function. To verify this, simply try calling print texture_background
in your _draw_scene()
function and you will find it returns None
rather than the desired integer texture identifier.
The simple hack-y solution is to just call global texture_background
before using it within your _handle_input()
function. You will also need to define texture_background = None
in the main scope of your program (underneath your ##FOR CUBE FROM OPENGL
comment). The same global comment applies for x_axis
and z_axis
.
That being said, that solution is not really that great. The rigid structure required by GLUT with all of these predefined glut*
functions makes it hard to structure code the way you might want to in terms of initializing your app. I would suggest, if you are not forced to use GLUT, to use a more flexible alternative, such as pygame, pysdl2 or pyqt, to create your context instead.