webgl-tools

changeset 5:7b3ed284e4bb

added glass_fullscreen
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 18 Jun 2011 05:29:39 +0300
parents 06d05a65bd77
children 3c42ff114e49 b215a8d38818
files glass.js
diffstat 1 files changed, 42 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/glass.js	Sat Jun 18 05:13:48 2011 +0300
     1.2 +++ b/glass.js	Sat Jun 18 05:29:39 2011 +0300
     1.3 @@ -49,9 +49,11 @@
     1.4  
     1.5  var gl;
     1.6  var canvas, console;
     1.7 +var glass_orig_width, glass_orig_height;
     1.8  var glass_data_loaded, glass_data_count;
     1.9  var glass_progr_prog;
    1.10  var glass_start_time = 0;
    1.11 +var glass_fullscr = false;
    1.12  
    1.13  var glass_cb_disp = null;
    1.14  var glass_cb_reshape = null;
    1.15 @@ -76,6 +78,9 @@
    1.16  		return false;
    1.17  	}
    1.18  
    1.19 +	glass_orig_width = canvas.width;
    1.20 +	glass_orig_height = canvas.height;
    1.21 +
    1.22  	var vs = create_shader(glass_progr_vs_src, gl.VERTEX_SHADER);
    1.23  	var ps = create_shader(glass_progr_ps_src, gl.FRAGMENT_SHADER);
    1.24  	if(!vs || !ps || !(glass_progr_prog = create_program(vs, ps))) {
    1.25 @@ -134,14 +139,49 @@
    1.26  
    1.27  function glass_resize(x, y)
    1.28  {
    1.29 -	canvas.width = x;
    1.30 -	canvas.height = y;
    1.31 +	canvas.width = glass_orig_width = x;
    1.32 +	canvas.height = glass_orig_height = y;
    1.33  
    1.34  	if(glass_cb_reshape) {
    1.35  		glass_cb_reshape(x, y);
    1.36  	}
    1.37  }
    1.38  
    1.39 +function glass_fullscreen(state)
    1.40 +{
    1.41 +	if(state == null) {
    1.42 +		glass_fullscr = !glass_fullscr;
    1.43 +	} else {
    1.44 +		glass_fullscr = state;
    1.45 +	}
    1.46 +
    1.47 +	if(glass_fullscr) {
    1.48 +		canvas.style.position = "absolute";
    1.49 +		canvas.style.left = 0;
    1.50 +		canvas.style.top = 0;
    1.51 +		canvas.width = window.innerWidth;
    1.52 +		canvas.height = window.innerHeight;
    1.53 +
    1.54 +		window.onresize = function() {
    1.55 +			canvas.width = window.innerWidth;
    1.56 +			canvas.height = window.innerHeight;
    1.57 +			if(glass_cb_reshape) {
    1.58 +				glass_cb_reshape(canvas.width, canvas.height);
    1.59 +			}
    1.60 +		}
    1.61 +	} else {
    1.62 +		canvas.style.position = "static";
    1.63 +		canvas.width = glass_orig_width;
    1.64 +		canvas.height = glass_orig_height;
    1.65 +
    1.66 +		window.onresize = null;
    1.67 +	}
    1.68 +
    1.69 +	if(glass_cb_reshape) {
    1.70 +		glass_cb_reshape(canvas.width, canvas.height);
    1.71 +	}
    1.72 +}
    1.73 +
    1.74  
    1.75  function glass_redraw()
    1.76  {