-1
\$\begingroup\$

How do I debug OpenGL apps written in python? I tried but I was unable to use standard tools like nvidia nsight or glsl-debugger or renderDoc on python code.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

It's hard to tell without knowing more about the python code you are trying to debug and with what library. All the tools you listed will be able to capture OpenGL calls in python the same way it would in C++, C#, rust etc.

They work by intercepting the underlying library calls to the library (.dll, .so, etc) which happen no matter what language you are using.

Some common issues on RenderDoc you can avoid are:

  • Bad executable path: The executable you enter has to be the interpreter python. It cannot be the script, this has to go in the command-line arguments section:
    • Executable path: /usr/bin/python
    • Command-line Arguments: /tmp/hello_world.py
  • Your script could be quitting due to some error during runtime. Check the log in this case.
  • The library you are using could be rendering in a forked process. Check "Capture Child Process" in RenderDoc or the equivalent option in NSight or glsl-debugger. Make sure you try capturing all the child processes.
  • If your application is a static image, it's possible that you cannot capture because that image was submitted to OpenGL only once. For example, pyglet will only draw once unless it is given an update function with pyglet.clock.schedule. If that's the case, you tell RenderDoc to capture the first frame with Actions: Queue Capture Frame 0.
  • Finally, make sure your library is using a compatible OpenGL profile. RenderDoc will warn you if a profile is too old. If that's the case, either find a way to use at least 3.2 profile or you can use apitrace.

For example, here are the safest options you can have in RenderDoc. Capture Child Process is enabled in case it forks, Queue Capture is enabled in case only one frame is submitted and python is set as the executable.

enter image description here

And this is the code

import pyglet

window = pyglet.window.Window()
label = pyglet.text.Label('Hello, world!',
                          font_name='Arial',
                          font_size=36,
                          x=window.width // 2,
                          y=window.height // 2,
                          anchor_x='center',
                          anchor_y='center')


@window.event
def on_draw():
    window.clear()
    label.draw()


def update(dt):
    pass

# Update function to make sure pyglet re-draws periodically
pyglet.clock.schedule(update)
pyglet.app.run()
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .