From c9000b7c385b530bddf87cfed4b580b5d1a2d6d2 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 10 Nov 2018 20:24:25 +0100 Subject: view: add support for non-square, non-power-of-2 sprites --- src/view/renderer/renderer.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/view/renderer') diff --git a/src/view/renderer/renderer.ts b/src/view/renderer/renderer.ts index 062c868..93f8589 100644 --- a/src/view/renderer/renderer.ts +++ b/src/view/renderer/renderer.ts @@ -3,7 +3,8 @@ import { Shaders } from './shaders'; import { mat4, vec2 } from 'gl-matrix'; export class Renderer { - private readonly viewScale = 64; + public readonly coordScale = 32; + private readonly viewScale = 2; private readonly gl: WebGLRenderingContext; private readonly shaders: Shaders; @@ -67,9 +68,9 @@ export class Renderer { } public snapToGrid(out: vec2, a: vec2|number[]): void { - vec2.scale(out, a, this.viewScale); + vec2.scale(out, a, this.coordScale); vec2.round(out, out); - vec2.scale(out, out, 1 / this.viewScale); + vec2.scale(out, out, 1 / this.coordScale); } private mkContext(): WebGLRenderingContext { @@ -89,8 +90,10 @@ export class Renderer { this.gl.viewport(0, 0, w, h); this.clear(); + const scale = this.viewScale * this.coordScale; + mat4.identity(this.viewport); - mat4.scale(this.viewport, this.viewport, [2 * this.viewScale / w, -2 * this.viewScale / h, 1.0]); + mat4.scale(this.viewport, this.viewport, [2 * scale / w, -2 * scale / h, 1.0]); this.gl.uniformMatrix4fv(this.shaders.viewportLoc, false, this.viewport); } } -- cgit v1.2.3