[cairo] PyCairo + OpenGL = Segmentation Fault? I need a hand
stevech1097 at yahoo.com.au
Tue Oct 2 06:48:16 PDT 2007
On Tue, 2007-10-02 at 10:43 +0200, Clemens Nylandsted Klokmose wrote:
> I have for some time now tried to generate a texture through cairo and
> plaster onto an OpenGL surface via python, but I think I am missing
> some memory subtlety.
> I define a surface like this:
> surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 1024, 1024)
> ctx = cairo.Context(surface)
> //I do some drawing//
> Then some OpenGL texture setup:
> glBindTexture(GL_TEXTURE_2D, 1)
> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
> glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
> glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
> And now the call that leads to a segmentation fault:
> glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, int( surface.get_width()),
> int(surface.get_height()), 0, GL_BGRA, GL_UNSIGNED_BYTE,
> Is there any of you who have had luck using PyCairo with OpenGL and
> can see what I do wrong?
I think calling surface.finish() is an error, removing that may fix the
Also, surface.get_data() returns a Python buffer object.
My guess is that glTextImage2D may not work with Python buffers, or may
not understand the cairo image format.
The PyOpenGL documentation says that the glTextImage2D last argument is
Specifies a pointer to the image data in memory."
Which does not make sense to me since Python is not C and does not use
pointers to memory, it uses references to objects.
More information about the cairo