WebGL ã«ãããã¦ã§ãã³ã³ãã³ãã§ OpenGL ES 2.0 ãã¼ã¹ã® API ãç¨ãã¦ã対å¿ãã¦ãããã©ã¦ã¶ã¼ã§ã¯ãã©ã°ã¤ã³ã使ããã«ã 2D ããã³ 3D ã®æç»ã HTML ã® canvas
ã«ããã¦è¡ããã¨ãã§ãã¾ãã
WebGL ã®ããã°ã©ã 㯠JavaScript ã§è¨è¿°ããå¶å¾¡ã³ã¼ãã¨ãã³ã³ãã¥ã¼ã¿ã¼ã® Graphics Processing Unit (GPU) ã§å®è¡ããã·ã§ã¼ãã¼ã³ã¼ã (GLSL) ã§æ§æããã¾ãã WebGL è¦ç´ ã¯ä»ã® HTML è¦ç´ ã¨æ··ããããä»ã®ãã¼ã¸é¨åããã¼ã¸ã®èæ¯ã¨åæããã¾ãã
ãã®è¨äºã§ã¯ã WebGL ã®åºç¤ãç´¹ä»ãã¾ããããã§ã¯ã 3D ã°ã©ãã£ãã¯ã«é¢ãã¦æ°å¦çã«çè§£ãã¦ãããã¨ãåæã¨ãã 3D ã°ã©ãã£ãã¯ã®æ¦å¿µèªä½ã®èª¬æã¯è¡ãã¾ããã
ãã®ãã¥ã¼ããªã¢ã«ã§ä½¿ç¨ããã³ã¼ãä¾ã¯ãGitHub ã® webgl-examples ãªãã¸ããªã¼ã§ç¢ºèªã§ãã¾ãã
ãã®ä¸é£ã®è¨äºã¯ WebGL èªä½ãç´¹ä»ãã¦ãããã¨ã«æ³¨æãã¦ãã ããããã ã THREE.js ãªã©ã WebGL ã®æ©è½ãã«ãã»ã«åããæ°å¤ãã®ãã¬ã¼ã ã¯ã¼ã¯ãå©ç¨ãã¦ã 3D ã¢ããªã±ã¼ã·ã§ã³ã¨ã²ã¼ã ãããç°¡åã«æ§ç¯ãããã¨ãå¯è½ã§ãã
3D æç»ã®æºåæåã«ã次㮠2 ã¤ã®ãã¡ã¤ã«ã使ãã¦ãã ããã
"index.html" ãã¡ã¤ã«ã«ã¯ã以ä¸ã®ãããªå 容ãå ¥ãã¦ãã ããã
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<title>WebGL ãã¢</title>
<script src="webgl-demo.js" type="module"></script>
</head>
<body>
<canvas id="glcanvas" width="640" height="480"></canvas>
</body>
</html>
ããã¯ããµã³ãã«ãæç»ãããã£ã³ãã¹ã宣è¨ãã¦ãã¾ãã
WebGL ã³ã³ããã¹ãã®æºå以ä¸ã®ã³ã¼ãã "webgl-demo.js" ãã¡ã¤ã«ã«è¿½å ãã¦ãã ããã
main();
//
// ããããéå§
//
function main() {
const canvas = document.querySelector("#glcanvas");
// GL ã³ã³ããã¹ããåæå
const gl = canvas.getContext("webgl");
// WebGL ã使ç¨å¯è½ã§åä½ãã¦ããå ´åã«ã®ã¿ç¶è¡
if (gl === null) {
alert(
"WebGL ãåæåã§ãã¾ããããã©ã¦ã¶ã¼ã¾ãã¯ãã·ã³ã対å¿ãã¦ããªãå¯è½æ§ãããã¾ãã",
);
return;
}
// ã¯ãªã¢ã«ã©ã¼ãé»ã«è¨å®ããå®å
¨ã«ä¸éæãã
gl.clearColor(0.0, 0.0, 0.0, 1.0);
// æå®ãããã¯ãªã¢ã«ã©ã¼ã§ã«ã©ã¼ãããã¡ã¼ãã¯ãªã¢ãã
gl.clear(gl.COLOR_BUFFER_BIT);
}
ã¹ã¯ãªãããèªã¿è¾¼ã¾ãã㨠main()
颿°ãå¼ã³åºããã¾ãããã®é¢æ°ã®ç®ç㯠WebGL ã³ã³ããã¹ããã»ããã¢ããããã³ã³ãã³ãã®ã¬ã³ããªã³ã°ãå§ãããã¨ã§ãã
ããã§æåã«è¡ããã¨ã¯ãã£ã³ãã¹ã¸ã®åç
§ãåå¾ããããã canvas
ã¨ããååã®å¤æ°ã«å²ãå½ã¦ããã¨ã§ãã
ãã£ã³ãã¹ãåå¾ãããããã£ã³ãã¹ã® WebGLRenderingContext
ãåå¾ããããã« getContext()
ãå¼ã³åºãã¦æåå "webgl"
ãæ¸¡ãã¾ãããã©ã¦ã¶ã¼ã WebGL ã«å¯¾å¿ãã¦ããªãå ´åã getContext()
㯠null
ãè¿ãã¾ãããã®å ´åã¯ã¦ã¼ã¶ã¼ã«ã¡ãã»ã¼ã¸ã表示ãã¦çµäºãã¾ãã
ã³ã³ããã¹ããæ£å¸¸ã«åæåãããå ´åã夿° gl
ã¯ãã®åç
§ã«ãªãã¾ãããã®å ´åãã¯ãªã¢ã«ã©ã¼ãé»ã«è¨å®ãããã®ã«ã©ã¼ã®ã³ã³ããã¹ããã¯ãªã¢ï¼èæ¯è²ã§ãã£ã³ãã¹ãåæç»ï¼ãã¾ãã
ãã®æç¹ã§ã WebGL ã³ã³ããã¹ããæ£å¸¸ã«åæåãããã®ã«ååãªã³ã¼ãããããã³ã³ãã³ããåä¿¡ããæºåãã§ãã¦å¾ æ©ãã¦ãã大ããªé»ã空ã®ããã¯ã¹ã«ãªãã¾ãã
ã³ã¼ãã確èªãã | æ°ãããã¼ã¸ã§ãã¢ãéã
é¢é£æ å ±RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4