Skip to content

Commit 999393d

Browse files
xiangzezphemavax
authored andcommitted
Add query parameters to control canvas size
1 parent 8629b92 commit 999393d

File tree

5 files changed

+67
-6
lines changed

5 files changed

+67
-6
lines changed

aquarium-vr/aquarium-vr.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@
119119
<body>
120120
<div id="info"><a href="http://threedlibrary.googlecode.com" target="_blank">tdl.js</a> - aquarium</div>
121121
<div class="fpsContainer">
122-
<div class="fps">fps: <span id="fps"></div>
122+
<div class="fps">fps: <span id="fps"></span></div>
123+
<div class="fps">canvas width: <span id="canvasWidth"></span></div>
124+
<div class="fps">canvas height: <span id="canvasHeight"></span></div>
123125
<div id="topUI">
124126
<div>Number of Fish</div>
125127
<div class="clickable" id="setSettingChangeView">Change View</div>

aquarium-vr/aquarium-vr.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,17 @@ function initialize() {
849849
if (g_query.numFish) {
850850
g_numFish[0] = parseInt(g_query.numFish);
851851
}
852+
if (g_query.canvasWidth) {
853+
g.globals.width = parseInt(g_query.canvasWidth);
854+
}
855+
if (g_query.canvasHeight) {
856+
g.globals.height = parseInt(g_query.canvasHeight);
857+
}
858+
if (g_query.fitWindow == "true") {
859+
g.globals.fitWindow = true;
860+
} else if (g_query.fitWindow == "false") {
861+
g.globals.fitWindow = false;
862+
}
852863

853864
gl.enable(gl.DEPTH_TEST);
854865
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
@@ -1115,6 +1126,11 @@ function initialize() {
11151126
tdl.log("new canvas height:", newHeight);
11161127
}
11171128
if (changed) {
1129+
var widthElem = document.getElementById("canvasWidth");
1130+
widthElem.innerHTML = canvas.width;
1131+
var heightElem = document.getElementById("canvasHeight");
1132+
heightElem.innerHTML = canvas.height;
1133+
11181134
//tdl.log("drawingBufferDimensions:" + gl.drawingBufferWidth + ", " + gl.drawingBufferHeight);
11191135
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
11201136
}
@@ -1214,6 +1230,10 @@ function initialize() {
12141230
}
12151231
}
12161232

1233+
if (g.globals.fitWindow) {
1234+
setCanvasSize(canvas, canvas.clientWidth, canvas.clientHeight);
1235+
}
1236+
12171237
if (g.net.sync) {
12181238
clock = now * g.globals.speed;
12191239
eyeClock = now * g.globals.eyeSpeed;
@@ -1814,6 +1834,11 @@ function setupCountButtons() {
18141834
}
18151835

18161836
function initUIStuff() {
1837+
var widthElem = document.getElementById("canvasWidth");
1838+
widthElem.innerHTML = canvas.width;
1839+
var heightElem = document.getElementById("canvasHeight");
1840+
heightElem.innerHTML = canvas.height;
1841+
18171842
setupCountButtons();
18181843
var elem = document.getElementById("setSettingChangeView");
18191844
elem.onclick = function() {

aquarium/README.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,17 @@ <h2>Options</h2>
3434
<li>
3535
<h3>numFish</h3>
3636
<p>set the number of fish</p>
37-
<pre>
38-
<a href="aquarium.html?numFish=1234">https://webglsamples.github.io/aquarium/aquarium.html?numFish=1234</a>
39-
</pre>
37+
<pre><a href="aquarium.html?numFish=1234">https://webglsamples.github.io/aquarium/aquarium.html?numFish=1234</a></pre>
38+
</li>
39+
<li>
40+
<h3>canvasWidth, canvasHeight</h3>
41+
<p>set the canvas size, default value: 1024 * 1024</p>
42+
<pre><a href="aquarium.html?canvasWidth=1920&canvasHeight=1080">https://webglsamples.github.io/aquarium/aquarium.html?canvasWidth=1920&canvasHeight=1080</a></pre>
43+
</li>
44+
<li>
45+
<h3>fillWindow</h3>
46+
<p>set the canvas size to always fit the window, default value: false</p>
47+
<pre><a href="aquarium.html?fitWindow=true">https://webglsamples.github.io/aquarium/aquarium.html?fitWindow=true</a></pre>
4048
</li>
4149
</ul>
4250
<h2>Running across multiple machines</h2>

aquarium/aquarium-common.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ var g = {
147147
globals: {
148148
fishSetting: 2,
149149
drawLasers: false,
150-
width: 1024,
151-
height: 1024
150+
width: 1024,
151+
height: 1024,
152+
fitWindow: false
152153
},
153154
net: {
154155
timeout: 3000,

aquarium/aquarium.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,17 @@ function initialize() {
966966
if (g_query.numFish) {
967967
g_numFish[0] = parseInt(g_query.numFish);
968968
}
969+
if (g_query.canvasWidth) {
970+
g.globals.width = parseInt(g_query.canvasWidth);
971+
}
972+
if (g_query.canvasHeight) {
973+
g.globals.height = parseInt(g_query.canvasHeight);
974+
}
975+
if (g_query.fitWindow == "true") {
976+
g.globals.fitWindow = true;
977+
} else if (g_query.fitWindow == "false") {
978+
g.globals.fitWindow = false;
979+
}
969980

970981
gl.enable(gl.DEPTH_TEST);
971982
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
@@ -1243,6 +1254,11 @@ function initialize() {
12431254
tdl.log("new canvas height:", newHeight);
12441255
}
12451256
if (changed) {
1257+
var widthElem = document.getElementById("canvasWidth");
1258+
widthElem.innerHTML = canvas.width;
1259+
var heightElem = document.getElementById("canvasHeight");
1260+
heightElem.innerHTML = canvas.height;
1261+
12461262
//tdl.log("drawingBufferDimensions:" + gl.drawingBufferWidth + ", " + gl.drawingBufferHeight);
12471263
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
12481264

@@ -1347,6 +1363,10 @@ function initialize() {
13471363
g_fishTable.length = 0;
13481364
}
13491365

1366+
if (g.globals.fitWindow) {
1367+
setCanvasSize(canvas, canvas.clientWidth, canvas.clientHeight);
1368+
}
1369+
13501370
if (g.net.sync) {
13511371
clock = now * g.globals.speed;
13521372
eyeClock = now * g.globals.eyeSpeed;
@@ -1829,6 +1849,11 @@ function setupCountButtons() {
18291849
}
18301850

18311851
function initUIStuff() {
1852+
var widthElem = document.getElementById("canvasWidth");
1853+
widthElem.innerHTML = canvas.width;
1854+
var heightElem = document.getElementById("canvasHeight");
1855+
heightElem.innerHTML = canvas.height;
1856+
18321857
setupCountButtons();
18331858
var elem = document.getElementById("setSettingChangeView");
18341859
elem.onclick = function() {

0 commit comments

Comments
 (0)