Command-line OpenGL rendering using PyOpenGL and/or OpenGLContext

I noticed that there have been quite a few Python related posts on Planet Debian lately. Here's mine.

I'm having a really hard time trying to find a good solution for rendering an OpenGL scene (e.g. from a VRML file) using PyOpenGL and/or OpenGLContext in the command line. All solutions I tried so far pop up an X11-window, which is not what I'm looking for. Instead I want to render the scene and dump it to PNG/JPG without requiring an X11 server.

Can this be done with PyOpenGL/OpenGLContext? I could probably try to use xvfb, but that's really an ugly hack. Besides the images I get using xvfb are somewhat broken, not sure why (does xvfb support OpenGL?).

Any hints are appreciated.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Wrong tool for the job

This doesnt seem to make sense to me. From an opengl render point of view what your trying to do is essentailly:

draw stuff -> render image -> get image back from renderer

Unless your rendering with mesa, rending and getting the image back require talking to the gpu, hence a need for graphics drivers, which pretty much means X11.

You could probably hack mesa to try to get software rendering to a buffer, but youll be lacking the things that make moder opengl interseting (fragment shading etc). I imageine this is basically the solution your after.

OpenGL is designed for live rendering, not offlines as you want to do here. Things like povray are built for that.


Hm, Mesa could probably work, I'll check that out. Talking to the GPU is no problem, opening an X11 window is. I really wonder why it isn't (easily) possible to do that.

Povray might be another possibility. I found vrml2pov which could probably work, but it has an obscure non Free Software license it seems...

Anyway, thanks for your suggestions.


I haven't looked into it

I haven't looked into it yet, but you need to have an opengl context before anything glish works, normally, you need to have a window open and associated context, which SDL/pygame do in one go for you (which explains white textures if you glTexImage2D before having done a pygame.display.set_mode). So, what you are likely looking for is a way to get an opengl context without an attached X11 window, and then some kind of offscreen rendering. If this doesn't help, I'll certainly dive into it, since I might need something similiar myself.

OpenGL Context

Yeah, I think an OpenGL context without an attached window would be what I'm looking for, but there doesn't seem to exist one, right? Not sure why there's none, maybe I just didn't find it or it's just not yet implemented. Or are there any conceptual problems for creating it?

Thanks, Uwe.