DX9 update for sswift's letterbox code?

BlitzMax Forums/BlitzMax Programming/DX9 update for sswift's letterbox code?

BlitzSupport(Posted 2011) [#1]
This is sswift's code for correcting aspect ratio/letterboxing:



Unfortunately it now fails on the default DX9 driver, since there's only code to handle DX7/OpenGL.

It just needs the matrix to be set in ProjectionMatrix.SetScale but it seem this requires more than a simple copy/replace of the D3D7Driver stuff from 7 -> 9!

Is anyone here able to add this tiny part that should make all the difference? I tried to figure it out from brl.mod/d3d9max2d.bmx but, alas, I do not have the smarts...


Yan(Posted 2011) [#2]
TBH, I can't be bothered to go through the above code. :o/

However, when I converted this to use D3d9Max2d, I initially tried something like...
...
If GetGraphicsDriver() = D3D9Max2DDriver()
  D3D9Graphics(TMax2DGraphics.Current()._graphics).GetDirect3DDevice().SetTransform(D3DTS_PROJECTION, Matrix)
...
...Unfortunately, this didn't seem to want to work so I ended up with this...
  Function SetVirtualSize(width=640, height=480)
    TViewPort.virtualWidth = width
    TViewPort.virtualHeight = height
    TViewPort.xRatio! = width / Double(GraphicsWidth())
    TViewPort.yRatio! = height / Double(GraphicsHeight())
    TViewPort.aspectRatio! = TViewPort.virtualHeight / Double(TViewPort.virtualWidth)
    
    'Mark: As the old projection matrix stuff doesn't seem to work with D3D9Max2D and I can't be arsed to investigate,
    '      I'll use the spangly new built in stuff in a half arsed manner...Hoorar for me.
      
  ?Win32
    If GetGraphicsDriver() = D3D7Max2DDriver()
      Local pMatrix#[] = [(2.0 / width),  0.0, 0.0, 0.0,..
                        0.0, -(2.0 / height), 0.0, 0.0,..
                        0.0, 0.0, 1.0, 0.0,..
                        -1 - (1.0 / width), 1 + (1.0 / height), 1.0, 1.0]
    
      D3D7GraphicsDriver().Direct3DDevice7().SetTransform(D3DTS_PROJECTION, pMatrix#)
    Else
  ?
      SetVirtualResolution(width, height)
  ?Win32  
    EndIf
  ? 
  End Function


Bear in mind that my code was playing around with the DX/GL viewport to adjust the aspect ratio too. Also, it's likely that there have been changes to D3d9Max2d in the mean time so you may have no problems integrating the above DX9 projection matrix stuff or even replacing it with SetVirtualResolution() altogether.

Last edited 2011


BlitzSupport(Posted 2011) [#3]
Ah, cool! I was able to just replace all of the matrix stuff with SetVirtualResolution -- works for DX7, DX9 and OpenGL. Thanks Yan!




BlitzSupport(Posted 2011) [#4]
I wasn't too comfortable using the above system, so finally created my own dumber version based upon SetVirtualResolution: the imaginatively named VirtualGfx.