Problem with projection matrix.

BlitzMax Forums/BlitzMax Programming/Problem with projection matrix.

Sokurah(Posted 2009) [#1]
I'm having a bit of problems with a projection matrix.
I'm using the one I found here; http://www.blitzbasic.com/codearcs/codearcs.php?code=2595

The projection matrix itself works just fine and scales my game to any resolution but a few days I added a couple of functions for fading the screen to black (and back up from black) but that's the thing that is giving me problems.

Things are set up like this at the top of the program;

TVirtualGraphics.Set(512, 384)
AutoMidHandle 1
Global mode:TGraphicsMode
Global OFormat:String
Global Buffer:TImage = CreateImage(512, 384, 1, MASKEDIMAGE | MASKEDIMAGE)


The buffer is for fading the screen in and out.

Normally I'd do like this to draw something;
DrawImage Level0GFX, (TVirtualGraphics.virtualWidth / 2), (TVirtualGraphics.virtualHeight / 2)

..and that works.

The fade function I wrote looks like this;

Function FadeOut()
GrabImage Buffer, 0, 0
a = 255
Repeat
Cls
SetColor a, a, a
DrawImage Buffer, (TVirtualGraphics.virtualWidth / 2), (TVirtualGraphics.virtualHeight / 2)
Flip
WaitKey
a = a - 16
Until a < 0
End Function


I draw something on the screen but don't do a flip but call the fade function instead.
Simple - but it works...as long as I'm not using the projection matrix or I'm only running at the game's original 512x384 resolution.

If I set the resolution to double the original - 1024x768 and call the fade I get this result.




I just can't figure out why I get this zoomed quarter of what I should get.

Can anyone help telling me what I'm doing wrong? ;-)


GfK(Posted 2009) [#2]
GrabImage + Projection matrix = No go.

You need to set the virtual graphics res back to match the physical graphics resolution first.

I also noticed that you have MASKEDIMAGE | MASKEDIMAGE, which is... pointless. Just one MASKEDIMAGE will do, won't it?

Also, as of version 1.35, Blitzmax has its own projection matrix code.

Oh, one more thing. Instead of grabbing a large image (which is a bit wasteful), it might work out better if you create a small, solid black image, draw the original game screen, then the black image over the top with DrawImageRect, with increasing alpha.

Same trick, different method.


Sokurah(Posted 2009) [#3]
I also noticed that you have MASKEDIMAGE | MASKEDIMAGE, which is... pointless. Just one MASKEDIMAGE will do, won't it?

Haha, good point. I hadn't noticed. D'oh! :D

Oh, one more thing. Instead of grabbing a large image (which is a bit wasteful), it might work out better if you create a small, solid black image, draw the original game screen, then the black image over the top with DrawImageRect, with increasing alpha.

Not a bad idea. I'll try that.

Thanks for the help.