11

Edit: Summarizing what I want to do, more concise:

Render a texture of size wi,hi to an output texture wo,ho, so that the aspect ratio of input texture is maintained, and it fits inside the output texture, eventually with black borders if aspect ratio is different. For this I want to use a perspective projection, as I may rotate or apply other transforms to the input texture.

Then I want this output texture to be displayed on screen, with size ws, hs, where hs may be larger than ws. Again, maintaining aspect ratio and fitting with black borders. Here an orthogonal projection should be enough, as only rendering to screen is required, no further processing.

I want to do it without hacks, in order to make my life easier in case I want later to rotate, scale the original texture. I can figure by trial and error how to modify the parameters to get what I want now, but would rather use each matrix in the way it is intended.

user1592546
  • 1,480
  • 1
  • 14
  • 30
  • Possible to post some images of what you are getting? – solidpixel Jan 25 '17 at 10:58
  • My 2cents; it is very uncommon to scale objects in a non uniform way to adapt to the target texture/display ratio, the usual way to deal with ratio is to only play with the frustumM's left/right/bottom/up parameters (actually most 3d games will use perspectiveM instead, which needs only one parameter to handle the ratio: aspect) – VB_overflow Jan 26 '17 at 14:11
  • @VB_overflow: Agreed. I read some literature about these matrices, but cannot figure how to apply it to this specific situation (so that I use the matrices according to their roles). – user1592546 Feb 01 '17 at 13:51
  • I have trouble to understand the question after the edit. The usual process is like this: you render something (a 3d model, a sprite ...) into a texture `Ti` of size `wi,hi`, now you want to render `Ti` into another texture `To` (or the screen) of dimension `wo, ho`, preserving aspect and centering; for that you need to render a _quad_ mapped with `Ti` inside `To`, using a classic 2D orthographic matrix. The problem is then to find the position `x, y`and the size `w, h`of the quad. Is it what you want to do ? – VB_overflow Feb 01 '17 at 21:01
  • @VB_overflow: The steps are shifted in your description. In my question I consider first texture (an image) as i (input), the rendered texture as output (o) and the screen size ws, hs. Don't think of it in terms of games but rather general processing. Fit by scaling a rectangle with original dimensions wi, hi inside a rectangle wo, ho. Then fit wo, ho, again by scaling without modifying aspect ratio, inside rectangle ws, hs. I want to do this with OpenGL matrices. I actually have a solution, but since I already offered a bounty, I'll let it open, and maybe improve my solution. – user1592546 Feb 03 '17 at 07:31

0 Answers0