Hi Everyone,
I have an FBO that I'm using to drive an external RGB LED dot matrix display. That display has pixel (0,0) in the upper left corner, so I need to vertically flip the results I get back with glReadPixel().
The best technique I came up with is to use an EffectWidget(). So I follow the code examples that have been posted here before about creating a Texture and FBO, be instance of adding my widget's canvas to the FBO, I add the widget I need to display to an EffectWidget and then I add my widget to that widget. (And I add the EffectWidget's canvas to the FBO temporarily when I need to read the pixel data.
This is all working fine, but as I am not an OpenGL programmer, I wonder if the following makes sense? Here's the EffectWidgetBase code I'm using. Does this look right?
class FlipVertical(EffectBase):
"""GLSL effect to veritically flip a texture"""
def __init__(self):
super().__init__()
self.glsl = '''
vec4 effect(vec4 color, sampler2D texture, vec2 tex_coords, vec2 coords)
{{
return texture2D(texture, vec2(tex_coords.x, .32 - tex_coords.y));
}}
'''
Again, this code works, but I wonder if anyone can take a look at it and let me know if this is the best way to do this?
By the way, I don't completely understand the range of the tex_coords here. My display is 128x32. I realized that to flip the y-axis, I need to use a value of 0.32 - tex_coords.y. I don't know if the fact I have a height of 32 and the starting point for my calculation is 0.32 is related or just a coincidence? I would have that that my value I subtract the tex_coords.y from in the GLSL code should either be the height of the widget or 1.0. I'm kind of surprised that 0.32 works (which I found via trial and error).
Anyway, does using an EffectWidget() like this make the most sense here? And what's the deal with the tex_coords needing to be 0.32 versus 32 or 1.0?
Thanks!
Brian