Non-square OpenGL textures for video FX


I’m working on a video mixer with blending modes done in GLSL. What I have trouble with is how to use a rectangular (16:9) texture with JUCE and OpenGL. The OpenGLTexture class forces a square texture, deforming my video data, and the standard way (glGenTextures, bind, …) does not seem to work.

Is JUCE doing anything to prevent the standard texture get to the shader? Or does anyone have other tips to make this work?

The video is loaded, decoded etc. by ffmpeg and the code is available at

@daniel you remember your juce-ffmpeg bridge you were working on?

I’ve just now realized that the texture doesn’t have to be square, just with dimensions that are powers of two. With that in mind I’ve resolved to using this oversized texture and manipulating the texture coords in the shader, something along the lines of:

// the object 'player' contains data from ffmpeg
texture.loadARGB(player->, player->w, player->h);
texCoordsDeform->set(player->w / (float)texture.getWidth(), player->h / (float)texture.getHeight());

// fragment shader
varying vec2 texCoordOut;
uniform sampler2D tex;
uniform vec2 texCoordsDeform;
void main() {
    vec2 nCoords = vec2(texCoordOut.x, 1.0 - texCoordOut.y) * texCoordsDeform;
    gl_FragColor = vec4(texture2D(tex, nCoords).rgb, 1.0);

The texture is twice verticaly flipped (once by not using loadARGBFlipped and once in the shader), which is ok – otherwise the manipulated coords look at the bottom of the texture (which is empty). However manipulating the texture coords doesn’t feel right.

1 Like