Hi everybody, it's me again with another question.
In my spare time, I like to write little pieces of code that could help me in the future, this time I was working on a "vertical game renderer" (I made this thing), you might be asking "what the hell is that?" well, a little time ago I played "Bird climb" (a game that's available on the Microsoft store) on my pc and noticed something really cool, despite that the game is in portrait mode (cause it was first made for mobile phones), the developers found a cool workaround to play this gem on landscape mode, and this by just adding bars to the sides of the game itself but that's not the cool part, the cool part is that you can scale the window and the game scales keeping its aspect ratio, ok I'm not explaining my self as I would like to, take a look at the attachments.
my idea to recreate this is to create a bitmap, render everything there and then render this bitmap scaled in the middle of the window, this seemed fine until I realized that if I create a bitmap with higher resolutions (for scale purposes)and then scale this bitmap down to fit the screen, the bitmap (let's call this "game buffer")for some reason turns transparent.
here is my code
any idea of what could be causing this?
My guess would be MIP mapping. Try disabling that flag before creating gameBuffer.
Todd likely hit the nail on the head. If you want to keep mipmaps on, then after you finish creating your new bitmap, create a clone and use that. The clone will have the mipmaps generated on its creation. Remember to delete the original!
It seems that mipmapping is causing this as you both mentioned, but why mipmapping causes this? well, maybe I'll never understand, thank you so much for your fast response guys, you are the best.
Now all I need to do is to translate my mouse position to the gameBuffer but I guess that's not gonna be a problem.
but why mipmapping causes this?
Mipmapping is when the graphics system creates multiple smaller resized versions of the bitmap for performance (and aesthetics) and cross-fades between them as they transition between the differently needed versions.
When a mipmap is not correctly working (because it wasn't setup correctly for whatever reason), then it will sometimes crossfade into a blank bitmap, thus appearing transparent.
This is a known bug as referenced by Mark Oates and myself and SiegeLord. I just opened an issue on github for it.
It seems that is indeed a well-known issue and it's really nice that you, people that work on the source code of Allegro are working to fix this, I really appreciate this community and the support from you to new developers and adventurers that love to work with Allegro, thank you <3.
If it isn't clear, you can refresh the mip maps by using al_clone_bitmap.
An example :
The issue is on Github here :
https://github.com/liballeg/allegro5/issues/559
The "why" is fairly simple. When you load a bitmap from the disk, for instance, the mipmaps get generated then, because it makes sense to do so: there's actually content to create a mipmap with, and chances are you're not going to toy with it any more. So it's the perfect time to both load the bitmap into memory as well as generate and store its mipmaps.
When you create a new bitmap, the mipmaps are generated too, but they're empty. Creating a new bitmap is mostly useless unless you're going to make changes. But then how would the system know that it's time to generate the mipmaps based on the changes you've made? It can't generate them every time you make a change to the bitmap, otherwise you'd be kissing your performance goodbye. So... it just never does.
I guess the ideal way would be to, after you're done editing the new bitmap, tell Allegro that you're finished, and that it should do cleanup and preparations on the bitmap, like mipmap generation. Since we don't have that, you have to do it manually: cloning the bitmap counts as creating a new one, which triggers the mipmap generation.
So many thanks for the code Edgar, it helped me a lot and thanks to you André for the explanation, it seems that this "issue" is something that everybody knew except by me .