[cairo] PyCairo + OpenGL = Segmentation Fault? I need a hand

Steven Chaplin 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:
> Hi,
> 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//
> surface.finish()
> 
>  
> Then some OpenGL texture setup:
> 
>  
> glBindTexture(GL_TEXTURE_2D, 1)
> glPixelStorei(GL_UNPACK_ALIGNMENT,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,
> surface.get_data())
> 
>  
> 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
problem.

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
"pixels
      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.

Steve




More information about the cairo mailing list