pymunk icon indicating copy to clipboard operation
pymunk copied to clipboard

AttributeError: module 'pyglet.gl' has no attribute 'glColor3f'

Open alderven opened this issue 3 years ago • 2 comments

  1. Run this code: https://github.com/viblo/pymunk/blob/master/examples/spiderweb.py
  2. 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

alderven avatar Oct 18 '21 13:10 alderven

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.

viblo avatar Oct 18 '21 15:10 viblo

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.

einarf avatar Oct 31 '21 07:10 einarf

Note to self: Just now pyglet 2 was released. Should update pymunk to use that instead of 1.5

viblo avatar Nov 01 '22 08:11 viblo

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.

einarf avatar Nov 02 '22 10:11 einarf

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.

viblo avatar Nov 02 '22 14:11 viblo

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.

viblo avatar Nov 16 '22 19:11 viblo

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?

einarf avatar Nov 17 '22 09:11 einarf

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.

viblo avatar Nov 17 '22 16:11 viblo

This is now fixed in Pymunk 6.4 just released.

viblo avatar Nov 20 '22 15:11 viblo

Thanks a lot for this. We can finally use debug drawing in arcade now that pyglet 2 is supported/released 😄

einarf avatar Nov 20 '22 17:11 einarf