0

I am creating textures using cairo and saving, the issue is if i use the surface directly with opengl its flipped vertically.

if i save and load i can use pil and im.tostring() to flip it.

is there a good way to flip it the cairo surface, perhaps saving my png then flipping for use or saving the images upside down.

alternatively can i create a PIL Image and share the buffer with ciaro so i can then use PIL tostring method to orient the texture.

open to suggestions, not much info on mixing cairo and opengl with python.

Oly
  • 370
  • 5
  • 16

1 Answers1

0

One solution is to adjust your texture coordinate or apply a scaling matrix (1,-1) to the texture matrix if old matrix stack is in use.

Another way is to invert pixel (texcoord.y = 1.0 -texcoord.y) in a shader yourself rendering to a new texture via a FBO. (that's a good option)

uniform sampler2D diffuseTexture;

void main (void)  
{
    vec2 t = gl_TexCoord[0].st;
    t.y = 1.0 - t.y;
    vec4 c = texture2D(diffuseTexture, t);          
    gl_FragColor = c;                         
}
j-p
  • 1,622
  • 10
  • 18
  • I did come accross that as an option, seemed like a better idea to do as i edited the image, may end up using this method though. wonder if it has much impact in performance flipping i am constantly updating the textures because they contain text. – Oly Mar 26 '14 at 14:35