Jump to content

Change ratio before render


Nico
 Share

Recommended Posts

Hi guys,

I need some help (once again :rolleyes: ), I would like to know if it is possible to change the ratio just before making a render ? I would like to use this with a renderTargetTexture, I can easily save previous values, stopRenderLoop, make my render on my texture, restore previous values, and runRenderLoop again.

 

Thanks for reading and helping !

Nico.

Link to comment
Share on other sites

I've found something, but it's more a hack than a solution :

canvas.style.width = "auto";canvas.style.height = "auto";canvas.width = newWidthValue;canvas.height = newHeightValue;scene.render(); //To get immediately the right ratio and display//Do what I want to do//Restore previous valuescanvas.style.width = previousSavedWidth;canvas.style.height = previousSavedHeight;engine.resize();

If someone have a better way to do that, please share ^_^

 

Edit:

Assuming there is no inline styling on renderingCanvas on width and height, an easier way could be :

canvas.style.width = "auto";canvas.style.height = "auto";canvas.width = newWidthValue;canvas.height = newHeightValue;scene.render(); //To get immediately the right ratio and display//Do what I want to do//Restore previous valuescanvas.style.width = "";canvas.style.height = "";engine.resize();
Link to comment
Share on other sites

Thanks for answering !

With that it will be working, but not for my (special) case, because I call the render method from my renderTargetTexture manually (outside the renderLoop), so if I change the canvas size, call engine.resize(), and render my texture, sometime the renderLoop haven't yet call the scene.render(). 

And I'm not sure, but I think that is not very good to call engine.resize() inside the renderLoop since it will be called a lot, and in most case, it just do the same calculation with the same result for each frame.

Link to comment
Share on other sites

It will be easier to understand with some screenshots :

What I get inside the rendering canvas

ourownbaby.jpg

 

And here is what I get with a render target texture (size = 1024) :

screenshot.jpg

 

If I execute the code I have posted before, I get this :

screenaqa.jpg

 

I don't know if there is a bug, or if I did something wrong.

Link to comment
Share on other sites

Thanks for the bug fix !

I have just remembered one thing, for my createScreenshot method, I have to flip my picture on Y axis to get the right picture, is it normal ? (Because of WebGL ?)

Link to comment
Share on other sites

The mian change is in renderTarettexture.js:

 if (!this._doNotChangeAspectratio) {                scene.updateTransformMatrix(true);            }            if (this.onBeforeRender) {                this.onBeforeRender();            }            // Render            this._renderingManager.render(this.customRenderFunction, this.renderList, this.renderParticles, this.renderSprites);            if (this.onAfterRender) {                this.onAfterRender();            }            // Unbind            engine.unBindFramebuffer(this._texture);            if (!this._doNotChangeAspectratio) {                scene.updateTransformMatrix(true);            }

Then also into engine.js:

 public getAspectRatio(camera: Camera): number {     var viewport = camera.viewport;     return (this.getRenderWidth() * viewport.width) / (this.getRenderHeight() * viewport.height); } public getRenderWidth(): number {     if (this._currentRenderTarget) {         return this._currentRenderTarget._width;     }     return this._renderingCanvas.width; } public getRenderHeight(): number {     if (this._currentRenderTarget) {         return this._currentRenderTarget._height;     }     return this._renderingCanvas.height; }
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...