summaryrefslogtreecommitdiffstats
path: root/src/view/renderer
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2018-11-10 20:24:25 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2018-11-10 20:24:25 +0100
commitc9000b7c385b530bddf87cfed4b580b5d1a2d6d2 (patch)
tree7afdbdf1435c20f694c1eaeca6d7aa54c62d8e64 /src/view/renderer
parentfa3dad090c7abd8b13ad107e4dcb406012b63243 (diff)
downloadrpgedit-c9000b7c385b530bddf87cfed4b580b5d1a2d6d2.tar
rpgedit-c9000b7c385b530bddf87cfed4b580b5d1a2d6d2.zip
view: add support for non-square, non-power-of-2 sprites
Diffstat (limited to 'src/view/renderer')
-rw-r--r--src/view/renderer/renderer.ts11
1 files changed, 7 insertions, 4 deletions
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);
}
}