I'm making a game using Go with the rendering library "pixel".
I am trying to get fullscreen/resizing working, but I have an issue, and that's how to deal with stretching of images
I've seen and have used the solution of a "letterbox" effect for the game.
That is, drawing the game in the same aspect ratio, so stretching wouldn't be an issue, leaving the extra space as black bars.
My issue is, when trying to do this in this rendering library, I can only scale the matrix of the "Canvas" I'm drawing on.
I'm used to SFML with C++ where I can just define a fixed size for the "View" [what's being drawn on], not scaling it.
This is how I'm getting the current scaling for the matrix, it's incorrect, but it's what I have.
camZoom is 2.0, it's in there so the screen is bigger. If the camZoom is 1.0 [normal], the images are too small.
func letterBox(win *pixelgl.Window) {
windowRatio := winWidth / winHeight
viewRatio := win.Bounds().W() / win.Bounds().H()
sizeX := 1.
sizeY := 1.
horizontalSpacing := true
if windowRatio < viewRatio {
horizontalSpacing = false
}
if horizontalSpacing {
sizeX = viewRatio / windowRatio
} else {
sizeY = windowRatio / viewRatio
}
viewMatrix = pixel.IM.
Moved(pixel.V(win.Bounds().Center().X/camZoom, win.Bounds().Center().Y/camZoom)).
ScaledXY(pixel.V(win.Bounds().Center().X/camZoom, win.Bounds().Center().Y/camZoom), pixel.V(sizeY, sizeX))
}
Here's what it currently looks like:
Normal [no resizing done, 1024x768]:
Width of window increased [shrinks] []2
Height of window increased [stretches on X, hiding most of 'Canvas'] []3
Fullscreen [just keeps it's original size, but the width of the 'canvas' is slightly shrunken] []4
I just can't really figure out the math to it.
If this is not the best way to solve the full-screen issue I have, then let me know and I can make another question, but I was told this is how you should do it.