Sign in to follow this  
visgotti

Renderer resolution on canvas vs webgl not the same?

Recommended Posts

In the first scenario - If I create the renderer like this

const screenWidth = window.innerWidth;
const screenHeight = window.innerHeight;
const canvas = document.getElementById('canvas');

const renderer = PIXI.autoDetectRenderer({
    forceCanvas: true,
    width: screenWidth,
    height: screenHeight,
    antialias: false,
    roundPixels: true,
    resolution: 2,
    view: canvas,
});

renderer.view.width = screenWidth;
renderer.view.height = screenHeight;
renderer.view.style.width = screenWidth + 'px';
renderer.view.style.height = screenHeight + 'px';
renderer.view.style.display = 'block';
renderer.view.style.position = 'absolute';
renderer.view.style.top = '0';
renderer.view.style.left = '0';
renderer.view.style.zIndex = '-1';
renderer.backgroundColor = 0x000000;

 

then I do 

const playerSpine = new PIXI.spine.Spine(r.player.spineData);
playerSpine.skeleton.setSkinByName('base');
playerSpine.x = window.innerWidth / 4;
playerSpine.y = window.innerHeight / 4;

The player is in the middle of the webpage like I'd expect.

 

But with the same exact code - if I create the renderer with the option - 

forceCanvas: false,

I no longer see the player in the middle of the screen. I can't seem to figure out how webgl is positioning it. It seems like the webgl and canvas act differently when setting the resolution. No errors or anything. 

Anyone have an idea as to why this is happening?

 

edit: here's the most simple code snippet to reproduce the problems

https://github.com/visgotti/pixi-res-problem/

Share this post


Link to post
Share on other sites

Note: if you use "gh-pages" branch  (sometimes people use it by default), your demo will be accessible at visgotti.github.io/pixi-res-problem/

renderer = ... { resolution: 2} )

renderer.resize(600,400); 
// that makes canvas.width = 600 * 2 
// renderer.screen is a rectangle (0,0, 600, 400) 
// renderer.view is canvas of size (1200, 800)

People always have problem with "resolution" definition. Even if I explain everything in a few paragraphs - you'll get it only after you make an app or two that uses it. You have to look for "screen", "view", and how "autoDensity" works. You actually dont need it if you set "view.style.width" manually but look it anyway :)

As for why webgl is different - its updating inner fields when you call "resize"

Share this post


Link to post
Share on other sites
9 hours ago, ivan.popelyshev said:

Note: if you use "gh-pages" branch  (sometimes people use it by default), your demo will be accessible at visgotti.github.io/pixi-res-problem/


renderer = ... { resolution: 2} )

renderer.resize(600,400); 
// that makes canvas.width = 600 * 2 
// renderer.screen is a rectangle (0,0, 600, 400) 
// renderer.view is canvas of size (1200, 800)

People always have problem with "resolution" definition. Even if I explain everything in a few paragraphs - you'll get it only after you make an app or two that uses it. You have to look for "screen", "view", and how "autoDensity" works. You actually dont need it if you set "view.style.width" manually but look it anyway :)

As for why webgl is different - its updating inner fields when you call "resize"

Awesome thanks again ivan 

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.