Screen Scaling + applyRGBFilter
Hi Olivier
If I start the engine with scaling, like:
me.video.init("jsapp", 400, 300, true, 0.8);
or with auto scaling (in the branch for ticket-4):
me.video.init("jsapp", 400, 300, true, "auto", true);
When I use the function applyRGBFilter for a black and white copy of screen:
var background = me.video.applyRGBFilter(me.video.getScreenCanvas(), "b&w");
The background var has a image with dimensions smaller or larger than the current canvas.
I add the code below for tests in the engine:
api.getBackBufferCanvas = function() { return backBufferCanvas; };
And with the code below, the background image have the right size of the scaled screen:
var background = me.video.applyRGBFilter(me.video.getBackBufferCanvas(), "b&w");
Thanks!
Yep that’s a valid point, but I think that there is some confusion as well around the functions name themselves.
First thing to know is that in melonJS there are 2 “different” canvas
• What I call The backBufferCanvas where all drawings are actually done
• What I call the displayCanvas which is used when blitting the previous one to the screen.
Now, when scaling is not used, nor double-buffering,displayCanvas===backBufferCanvas, however when scaling or using double-buffering, everything is first rendered into the backBufferCanvas and then properly blit with the right scaling into the displayCanvas.
Then we have these functions :
• getScreenCanvas() returns a reference to the canvas being actually displayed, this one is mainly used by the engine for mouse/touch events
• By default there is no getBackBufferCanvas(), which for sure is missing here
• getScreenFrameBuffer() return a reference to the backBufferCanvas corresponding context2d (which does not make sense, as it should by its name return the displayCanvas corresponding context2d)
So before adding a getBackBufferCanvas(), would anyone have any recommendation on how to call these functions properly ?
What about :
• getFrontBufferCanvas()
• getBackBufferCanvas()
• getFrontBufferContext()
• getBackBufferContext()
OR
Since the “Front Canvas” is in theory not be use by the end user, we could remove it from the API, and keep :
• getSystemCanvas()
• getSystemContext()
That would then return the previously called “backBuffer Canvas and Context.
Hi Olivier
If the function getScreenCanvas has adjusted so as to return the backBufferCanvas when using scaling screen? That does not break the current api...
Thanks!
The point is that having getScreenCanvas() returning the backBuffer one does not make any sense :(
My intention (I was planning to do that earlier this week, but my job kept me busy since then) is actually to rename these to getSystemCanvas/Context, and make the “display” canvas a private variable. This last one is only used internally, and any context manipulation/drawing should anyway be done on the “backbuffer” or system one.
I know that this breaks API, but me.video is a mess right now and needs some clean-up !
closing this one :)
Hi Olivier
I tested and it works perfectly!
Thanks!