on master help sign in
first pass at doing canvas resizing and redrawing
commita8a4f79f19df0eabb2db92f3f4b20ff68404825d authorJohn P Mayer Jr <john.p.mayer.jr@gmail.com> dateFri 13 Dec 2013, 23:33 (13 years ago) parentbe90dd6
1 file changed+24−5
libraries/Native/Graphics/WebGL.js+24−5
libraries/Native/Graphics/WebGL.js+24−5
@@ -151,6 +151,7 @@ Elm.Native.Graphics.WebGL.make = function(elm) {
151151
152152 var gl = model.cache.gl;
153153
154+ gl.viewport(0, 0, model.w, model.h);
154155 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
155156 console.log("Drawing");
156157
@@ -226,24 +227,40 @@ Elm.Native.Graphics.WebGL.make = function(elm) {
226227
227228 function render(model) {
228229
229− var node = newNode('canvas');
230− var gl = node.getContext('webgl') || node.getContext('experimental-webgl');
230+ var div = newNode('div');
231+ div.style.overflow = 'hidden';
232+ var canvas = newNode('canvas');
233+ var gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
231234 gl.enable(gl.DEPTH_TEST);
232235
233236 model.cache.gl = gl;
237+ model.cache.canvas = canvas;
234238 model.cache.programs = [];
235239 model.cache.buffers = [];
236240
237− drawGL(model);
238− return node;
241+ update(div, model, model);
242+
243+ return div;
239244
240245 }
241246
242− function update(_node, oldModel, newModel) {
247+ function update(div, oldModel, newModel) {
243248
244249 newModel.cache = oldModel.cache;
250+
251+ var canvas = newModel.cache.canvas;
252+
253+ canvas.style.width = oldModel.w + 'px';
254+ canvas.style.height = oldModel.h + 'px';
255+ canvas.style.display = "block";
256+ canvas.style.position = "absolute";
257+ canvas.width = oldModel.w;
258+ canvas.height = oldModel.h;
259+
245260 drawGL(newModel);
246261
262+ div.appendChild(canvas);
263+
247264 }
248265
249266 var elem = {
@@ -254,6 +271,8 @@ Elm.Native.Graphics.WebGL.make = function(elm) {
254271 model: {
255272 models: models,
256273 cache: {},
274+ w: w,
275+ h: h,
257276 }
258277 };
259278