pymunk
pymunk copied to clipboard
AttributeError: module 'pyglet.gl' has no attribute 'glColor3f'
- Run this code: https://github.com/viblo/pymunk/blob/master/examples/spiderweb.py
- Getting error:
Traceback (most recent call last):
File "C:/pymunk_proj/spiderweb.py", line 184, in <module>
pyglet.app.run()
File "C:\Program Files\Python38\lib\site-packages\pyglet\app\__init__.py", line 107, in run
event_loop.run(interval)
File "C:\Program Files\Python38\lib\site-packages\pyglet\app\base.py", line 183, in run
timeout = self.idle()
File "C:\Program Files\Python38\lib\site-packages\pyglet\app\base.py", line 244, in idle
self.clock.call_scheduled_functions(dt)
File "C:\Program Files\Python38\lib\site-packages\pyglet\clock.py", line 274, in call_scheduled_functions
item.func(now - item.last_ts, *item.args, **item.kwargs)
File "C:\Program Files\Python38\lib\site-packages\pyglet\app\base.py", line 154, in _redraw_windows
window.dispatch_event('on_draw')
File "C:\Program Files\Python38\lib\site-packages\pyglet\window\__init__.py", line 1327, in dispatch_event
super().dispatch_event(*args)
File "C:\Program Files\Python38\lib\site-packages\pyglet\event.py", line 415, in dispatch_event
if handler(*args):
File "C:/pymunk_proj/spiderweb.py", line 158, in on_draw
pyglet.gl.glColor3f(1, 0, 1)
AttributeError: module 'pyglet.gl' has no attribute 'glColor3f'
Error in sys.excepthook:
Original exception was:
OS: Win 10 Python: 3.8 Pymunk: 6.2.0 Pyglet: 2.0.dev9
Thanks for the report.
It seems like glColor3f
is no longer available in pyglet 2.0. If you want to run it you will have to use pyglet 1.5 until its fixed. I will have to investigate a bit how to do it instead.
Definitely stick to pyglet 1.5.x if you are planning to use the fixed pipeline. There's nothing wrong with that and 1.5 will be maintained for a long time. Pyglet 2.0 relies on 3.3 core contexts were the fixed pipeline is deprecated.
The old enums and functions can still be accessed in the pyglet.gl_compat
module, but using those means your application won't work in environments only supporting core context. This includes MacOS and possibly some drivers on windows and linux.
There are only pre-release of pyglet 2, so I don't know why this version was installed.
Note to self: Just now pyglet 2 was released. Should update pymunk to use that instead of 1.5
Note that pyglet 2 requires GL3.1+ (preferable 3.3 core) so it can be a good idea to have two separate systems (pyglet
and pyglet2
) for debug drawing.
Yes, this is something Ive been thinking about how to handle. On one side I think its very nice that several different drawing libraries are included with pymunk out of the box. At the same time I dont want to have too much maintenance work on them or ship broken code.
Right now Im thinking about renaming the existing implementation to pyglet_15_util or pyglet_legacy_util or something similar, and then upgrade pyglet_util to pyglet2. At least then I wont be stuck with a pyglet2 forever even when 1.5 is out of support, and it will be easier to remove pyglet_legacy_util at that time. Since this is in a way a breaking change I think I will also have to bump the pymunk version to 7.0.
pyglet_legacy_util
and pyglet_util
is definitely a bit more future proof. It could also be possible to do some import magic based on the installed pyglet version to make it transparent?
Ah, there you said something. That could be a nice solution, let pyglet_util check for pyglet >=2, and if not load the legacy stuff instead. I will try it out.
This is now fixed in Pymunk 6.4 just released.
Thanks a lot for this. We can finally use debug drawing in arcade now that pyglet 2 is supported/released 😄