# HTML5 build full screen pixelated on HiDPI displays (DEF-2396)(SOLVED)

**URL:** <https://forum.defold.com/t/html5-build-full-screen-pixelated-on-hidpi-displays-def-2396-solved/4948>\
**Category:** Bugs\
**Created:** [February 7, 2017, 12:06pm UTC](https://forum.defold.com/t/html5-build-full-screen-pixelated-on-hidpi-displays-def-2396-solved/4948 "2017-02-07T12:06:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dapetcu21](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dapetcu21/32/25120_2.png) [@dapetcu21](https://forum.defold.com/u/dapetcu21)\
**Post date:** [February 7, 2017, 12:06pm UTC](https://forum.defold.com/t/html5-build-full-screen-pixelated-on-hidpi-displays-def-2396-solved/4948/1 "2017-02-07T12:06:24Z")

</div>

Hi!

Calling `Module.toggleFullscreen()` in the HTML5 build correctly enters full screen on hidpi devices (Android Chrome), but doesn’t multiply `canvas.width` and `canvas.height` with `window.devicePixelRatio || 1`.

The change needs to be operated in `_glfwSwapBuffers()` and `onFullScreenEventChange()`.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 8, 2017, 6:49am UTC](https://forum.defold.com/t/html5-build-full-screen-pixelated-on-hidpi-displays-def-2396-solved/4948/2 "2017-02-08T06:49:07Z")

</div>

Thank you for reporting this. I believe this is the same issue as this one right? [How to get better quality web render? - #9 by Flemming](https://forum.defold.com/t/how-to-get-better-quality-web-render/3889/9)

---

<div class="post-metadata">

**Author:** ![dapetcu21](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dapetcu21/32/25120_2.png) [@dapetcu21](https://forum.defold.com/u/dapetcu21)\
**Post date:** [February 8, 2017, 7:32am UTC](https://forum.defold.com/t/html5-build-full-screen-pixelated-on-hidpi-displays-def-2396-solved/4948/3 "2017-02-08T07:32:48Z")

</div>

Not really. You can get good results in windowed mode if you do what that issue recommends (set the canvas size with css and the canvas’s backing size with Module.setCanvasSize), but specifically in full screen mode you don’t have good control and the engine needs to accomodate for that.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 8, 2017, 7:35am UTC](https://forum.defold.com/t/html5-build-full-screen-pixelated-on-hidpi-displays-def-2396-solved/4948/4 "2017-02-08T07:35:15Z")

</div>

I’ve added your info to the same ticket as I believe they should be solved together. If @sven doesn’t agree with me we’ll split it into two issues and update this post.

---

<div class="post-metadata">

**Author:** ![def.ent.777](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/d/e47c2d/32.png) [@def.ent.777](https://forum.defold.com/u/def.ent.777)\
**Post date:** [July 6, 2017, 3:13pm UTC](https://forum.defold.com/t/html5-build-full-screen-pixelated-on-hidpi-displays-def-2396-solved/4948/5 "2017-07-06T15:13:37Z")

</div>

@dapetcu21 did you find a work around?

–\>The change needs to be operated in \_glfwSwapBuffers() and onFullScreenEventChange().

can you plse expand on this?

Thanks!

---

<div class="post-metadata">

**Author:** ![Dragosha](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dragosha/32/5103_2.png) [@Dragosha](https://forum.defold.com/u/Dragosha)\
**Post date:** [July 6, 2017, 4:13pm UTC](https://forum.defold.com/t/html5-build-full-screen-pixelated-on-hidpi-displays-def-2396-solved/4948/6 "2017-07-06T16:13:36Z")

</div>

My template for resizable HTML5 canvas for mobile and PC:

```lua
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no,width=device-width,minimal-ui" />
        <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->

		<title>Hamster 0.2 beta</title>
        <style>
			.canvas-app-container {
			  /* A positioned parent for loading visuals */
                width: 100%;
                height: 100%;
                position: absolute;
                align-items: center;
                justify-content: center;
                overflow: hidden;
                background: #0e1618;
			}

			.canvas-app-progress {
			  position: absolute;
			  background-color: rgb(245, 245, 245);
			  height: 20px;
			  /* Progress same width as canvas. */
			  width: 100%;
			  bottom: 0px;
			}

			.canvas-app-progress-bar {
			  font-size: 12px;
			  height: 20px;
			  color: rgb(255, 255, 255);
			  background-color: rgb(30, 100, 234);
			  text-align: center;
			  line-height: 20px;
			}

			* { margin:0; padding:0; }

			#canvas {
			  outline: none;
			  border: 0;
                          width: 100%;
			}
			canvas:focus, canvas:active {
			  outline: none;
			  border: 0;
			  ie-dummy: expression(this.hideFocus=true);
			  -moz-outline-style: none;
			}
			div {
			  -webkit-tap-highlight-color: rgba(0,0,0,0);
			}

		</style>
	</head>

	<body oncontextmenu="return false;">
    <div id="fb-root"></div>
	<div id="app-container" class="canvas-app-container">
	    <canvas id="canvas" class="canvas-app-canvas" tabindex="1" width="720" height="720"></canvas>
	</div>

	<!-- -->
	  <script type='text/javascript' src="dmloader.js"></script>
	  <script type='text/javascript' src="Hamster.js" async onload=""></script>
	<!-- -->

	<script type='text/javascript'>
		var extra_params = {
			archive_location_filter: function( path ) {
				return ("archive" + path + "");
			},
            engine_arguments: ["--verify-graphics-calls=false"],
			splash_image: "splash_image.png",
			custom_heap_size: 268435456
		}

        Module.runApp("canvas", extra_params);

        function resize_game_canvas() {
            var dpi=window.devicePixelRatio || 1
            //var dpi =1
            var width=window.innerWidth;
            var height=window.innerHeight;
            var aspect=width/height
    		var app_container = document.getElementById('app-container');
    		app_container.style.width = width+"px";
    		app_container.style.height = height+"px";

    		var game_canvas = document.getElementById('canvas');

            game_canvas.width = width*dpi;
            game_canvas.height = height*dpi;

            window.console.log("width: " + game_canvas.width + " > "+ game_canvas.style.width)
            window.console.log("height:" + game_canvas.height + " > "+ game_canvas.style.height)
		}

		resize_game_canvas();

		window.addEventListener('resize', resize_game_canvas, false);
		window.addEventListener('orientationchange', resize_game_canvas, false);

	</script>
</body>
</html>

```

Because on mobile devices browser logical width == 320..480px we need write some trick.  
And this trick is set canvas. **style**.width to 100% but canvas.width to window.innerWidth\*devicePixelRatio;  
I set Canvas style.width in css (see header).

If you can’t set canvas style properly then mobile browser setup wrong size of page.  
Also your defold render script should react to changing app resolution: render.get\_window\_width() and render.get\_window\_height()

Example with this html template: [http://dragosha.com/hamster/](http://dragosha.com/hamster/)

Another good solution is using maximize-canvas script: [GitHub - sergebat/maximize-canvas: Make canvas occupy entire browser window within provided resolution constraints · GitHub](https://github.com/sergebat/maximize-canvas) (for properly working this script required to creating canvas in code, not preset in html)

---

<div class="post-metadata">

**Author:** ![dapetcu21](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dapetcu21/32/25120_2.png) [@dapetcu21](https://forum.defold.com/u/dapetcu21)\
**Post date:** [July 6, 2017, 4:36pm UTC](https://forum.defold.com/t/html5-build-full-screen-pixelated-on-hidpi-displays-def-2396-solved/4948/7 "2017-07-06T16:36:54Z")

</div>

Well, the workaround for me at the time was prettyfying the main JS file, patching the above two functions manually, then minifying it back together.

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [August 19, 2019, 12:56pm UTC](https://forum.defold.com/t/html5-build-full-screen-pixelated-on-hidpi-displays-def-2396-solved/4948/8 "2019-08-19T12:56:46Z")

</div>

Solved in [Defold 1.2.160 has been released](https://forum.defold.com/t/defold-1-2-160-has-been-released/60637)

---

<div class="post-metadata">

**Author:** ![bryanrieger](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/bryanrieger/32/26778_2.png) [@bryanrieger](https://forum.defold.com/u/bryanrieger)\
**Post date:** [October 31, 2021, 3:19pm UTC](https://forum.defold.com/t/html5-build-full-screen-pixelated-on-hidpi-displays-def-2396-solved/4948/9 "2021-10-31T15:19:37Z")

</div>

I’m running Defold 1.2.188 and I’m still getting blurry HTML5 exports (fonts, images, etc) on hi-dpi displays.

In looking at /builtins/manifests/web/engine\_template.html I noticed that there is no code dealing with window.devicePixelRatio (as @Dragosha) illustrates in his HTML5 template above.

I added the following at line 130:  
var dpi=window.devicePixelRatio || 1

And added ‘\* dpi’ to lines 197 and 198:  
game\_canvas.width = width \* dpi;  
game\_canvas.height = height \* dpi;

The default template now renders to hi-dpi displays. 🙂

I also didn’t see any {{#DEFOLD pragma}} statement for hi-dpi displays, just in-case that was not being picked up from the game.project file.

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [October 31, 2021, 5:44pm UTC](https://forum.defold.com/t/html5-build-full-screen-pixelated-on-hidpi-displays-def-2396-solved/4948/10 "2021-10-31T17:44:07Z")

</div>

Defold applies DPI is in the engine code not in template: [defold/engine/glfw/js/library\_glfw.js at b240830f87dca44c5af242afa531cb7a50160908 · defold/defold · GitHub](https://github.com/defold/defold/blob/b240830f87dca44c5af242afa531cb7a50160908/engine/glfw/js/library_glfw.js#L672)

I’ve just tested it using 1.2.188 and it works just fine:  
option is on

 ![image](https://forum-defold.b-cdn.net/uploads/default/original/3X/5/6/5687dfd0eb49e1afb0b2e8bd945f907e718ba1e5.png)  
 ![image](https://forum-defold.b-cdn.net/uploads/default/original/3X/1/c/1cfe433bcc87f7f13753c61552ea48ba02908474.jpeg)  
 ![image](https://forum-defold-uploads.b-cdn.net/optimized/3X/5/f/5fd7cb9757096b68ddfcc297bdca691e5af0b15e_2_690x34.png)

option is off

 ![image](https://forum-defold.b-cdn.net/uploads/default/original/3X/8/d/8dd45a072a2e4089c7d7e9d5ee6d06b29f2cf2e5.png)  
 ![image](https://forum-defold.b-cdn.net/uploads/default/original/3X/5/8/5838956af5775ee20649a50e273bb17579e2ae19.jpeg)  
 ![image](https://forum-defold-uploads.b-cdn.net/optimized/3X/1/5/15643f2d33e06d501c2a800bae634252393a4590_2_690x46.png)

---

<div class="post-metadata">

**Author:** ![bryanrieger](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/bryanrieger/32/26778_2.png) [@bryanrieger](https://forum.defold.com/u/bryanrieger)\
**Post date:** [October 31, 2021, 6:09pm UTC](https://forum.defold.com/t/html5-build-full-screen-pixelated-on-hidpi-displays-def-2396-solved/4948/11 "2021-10-31T18:09:56Z")

</div>

Never mind, I just realized that the Display \> High Dpi option had been unchecked. 🤦‍♀️
