Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by REGATTA · Oct 27, 2016 at 09:34 PM · webglzoominput.mousepositioncss

Correction of input position after scaling of WebGL canvas in css

I already saw this issue described on this forum, but unfortunately did not find an answer yet (especially here question from @Charles-Van-Norman)

The final rendering of my WebGL canvas in windowed mode is quite blurry and the final graphics quality of the build is really poor. One of the option would be to rescale canvas width and height and force the zoom at a value smaller than 1. For instance with an initial canvas width of 1000px, we would do in the css something like:

 #canvas{zoom: 0.5;width: 2000px;}

It enhanced perfectly the graphics BUT the input location of mouse events are offset by the zoom value.

Is there any way to scale the canvas in the browser while correcting the mouse inputs in the correct position for the game?

Thanks a lot for your help

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Microblast-Games · Mar 28, 2020 at 06:20 AM

Help please, I have the same problem, now in 2020.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image iluvsnowlc · Aug 05, 2020 at 10:40 PM 0
Share

Same, anyone got a way to fix this?

avatar image
0

Answer by Dev-Unity02 · Oct 29, 2016 at 08:14 PM

Hello,

I have the same problem than you. I tried to understand why the mouse inputs were wrong. Unity seems to send the rights values for mouse positions but wrong for width and height because of zoom value. I read a bit the build js file. I found fillMouseEventData method and I replaced

 e.screenX   by   e.screenX * 2.0
 e.screenY   by   e.screenY * 2.0
 
 and
 
 e.clientX - rect.left   by   (e.clientX - rect.left) * 2.0
 e.clientY - rect.top   by   (e.clientY - rect.top) * 2.0

The value depends on your zoom (1 / 0.5) I think the devicePixelRatio can be added in the calculations.

As the zoom property is not supported on firefox, I used -moz-transform. The problem is:

  • for chrome, it seems the canvas be rendered first then be scaled by zoom value

  • for firefox, it seems the canvas be scaled by transform value then be renderer. To fix it, I had to double width and height values than normally.

Tell me if it works for you.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Scale WebGL cavas to browser window size 0 Answers

WEBGL Loading bar not showing on Microsoft Edge Unity 2020.1 0 Answers

WebGL zoom messing up 0 Answers

In WebGL, is it possible to make UI Coordinate scale with CSS style? 1 Answer

Communication between WebGL and .jslib 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges