1

I am writing something that is a bit "photoshoppy" in the sense there are image layers that render on top of each other.

Each layer renders to an FBO and fbos can be ran through effects etc.

Although the user can distort images I want the images to initially render in their own aspect ratio.

Currently each image is drawn to an FBO like so:

 //fbo is created at the size of the texture
 if (fboRenderTarget == null)
        {
            fboRenderTarget = new RenderTarget(gl);
            fboRenderTarget.ChangeRenderTarget(new RenderTargetState(textureInfo.Width, textureInfo.Height, TextureType.LowPrecisionIsNorm));
        }


       //viewport is set to size of texture
        gl.Viewport(0, 0, textureInfo.Width, textureInfo.Height);
        gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, fboRenderTarget.Name);

        //draw the texture

and when I am blending:

 //fbo is created at the size of the destination texture
 if (fboRenderTarget == null)
        {
            fboRenderTarget = new RenderTarget(gl);
            fboRenderTarget.ChangeRenderTarget(new RenderTargetState(dstTextureInfo.Width, dstTextureInfo.Height, TextureType.LowPrecisionIsNorm));
        }


       //viewport is set to size of texture
        gl.Viewport(0, 0, dstTextureInfo.Width, dstTextureInfo.Height);
        gl.BindFramebufferEXT(OpenGL.GL_FRAMEBUFFER_EXT, 
       ....

       //SET MATRIX
            ShaderPropertySetter.SetUniformMat4(gl, "uModelMatrix_m4", modelMatrix);
            if (srcMatrix != null)
                ShaderPropertySetter.SetUniformMat4(gl, "uSrcTextureMatrix_m4", srcMatrix.GetAsMat4());
            if (dstMatrix != null)
                ShaderPropertySetter.SetUniformMat4(gl, "uDstTextureMatrix_m4", dstMatrix.GetAsMat4());

Currently all texture distortion ect happens through the src texture matrix, currently the model and the dst is always set to identity and there is no projection matrix. Which just feels all wrong.

The final composite texture is rendered to the screen using a screen size surface and view port.

How can I ensure that each image's aspect ratio is preserved?

p.s. I am aware this may require a large re-factor.

chrispepper1989
  • 2,100
  • 2
  • 23
  • 48

0 Answers0