ビューポートのサイズを指定する

説明

ビューポートのサイズを指定するにはコンテキストのviewportWidthに横のサイズを、viewportHeightに縦のサイズを指定します。
以下のサンプルはGoogle Chrome 9で動作します。

サンプルプログラム

window.onload = function(){
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("experimental-webgl");
if (!context){
alert("WebGLが使えません!");
return;
}
// ビューポートの設定
context.viewportWidth = 640; // 横のビューポートサイズ
context.viewportHeight = 480; // 縦のビューポートサイズ
}
サンプルを実行
[戻る]