è¿æ¯ä¸ä¸ªæç®åç WebGL 代ç ãéè¿rendering contextè®¾ç½®å¥½ç¶æåï¼ç´æ¥å°æ´ä¸ªåºåæ¸ é¤ä¸ºç»¿è²ãè¦æ³¨æ css å·²ç»å° canvas ç»å¸è®¾ç½®ä¸ºé»è²äºï¼æä»¥å½ç»å¸åä¸ºç»¿è²æ¶ï¼æä»¬å°±ç¥éç¥å¥ç WebGL éæ³èµ·ä½ç¨äºï¼
æ¤å¤ï¼ä½ éè¦æ³¨æç¨åè²ç»å¶å¾åæ¯ä¸¤ä¸ªæ¥éª¤ï¼é¦å
ï¼éè¿ä½¿ç¨clearColor()
设置æ¸
é¤è²ä¸ºç»¿è²ãè¿åªä¼æ¹å Webgl å
é¨çä¸ä¸ªç¶æï¼ä½å¹¶ä¸ä¼ç»å¶ä»»ä½ä¸è¥¿ãæ¥ä¸æ¥ï¼æä»¬å°±ççå¼å§ç»å¶äºï¼ä½¿ç¨clear()
æ¹æ³ï¼è¿æ¯ä¸ä¸ªå
¸åçç¨ webgl ç»å¶çæ¹æ³ï¼webgl å®é
ä¸åªæå°æ°çå 个ç»å¶æ¹æ³ (clear() å°±æ¯å
¶ä¸ä¹ä¸)ãå
¶ä»æ¹æ³å¤§å¤é½æ¯ç±»ä¼¼è®¾ç½®ææ¹å WebGl ç¶æååéçï¼ä¾å¦è®¾ç½® clearcolorï¼ã
è¿éæè®¸å¤å±æ§åæ¹æ³ä½ç¨äº Webglï¼æ¸ 餿¹æ³åªæ¯ä½ 第ä¸ä¸ªææ¡çï¼è¿ä¹å°±æ¯ä¸ºä»ä¹ WebGLï¼OpenGl ç»å¸¸è¢«å«åç¶ææºï¼éè¿è°æ´è¿äºå±æ§åæ¹æ³å¯ä»¥ä¿®æ¹ WebGL å é¨çç¶æï¼ä»èè¿è¡è¾åºï¼ä¾å¦å 设置好绿è²ï¼å¨æ¸ é¤ç»å¸çæ¶ååç´ ç¹é½åæäºç»¿è²ï¼
æåï¼æä»¬ç¥éå¨ WebGl ä¸é¢è²æ ¼å¼æ¯ç± RGBAï¼çº¢ï¼ç»¿ï¼èï¼éæåº¦ï¼ç»æçï¼å æ¤ clearColor() æ¹æ³æ¥ååä¸ªåæ°
<p>A very simple WebGL program that shows some color.</p>
<!-- Text within a canvas element is displayed
only if canvas is not supported. -->
<canvas>Your browser does not seem to support HTML5 canvas.</canvas>
body {
text-align: center;
}
canvas {
display: block;
width: 280px;
height: 210px;
margin: auto;
padding: 0;
border: none;
background-color: black;
}
// Run everything inside window load event handler, to make sure
// DOM is fully loaded and styled before trying to manipulate it,
// and to not mess up the global scope. We are giving the event
// handler a name (setupWebGL) so that we can refer to the
// function object within the function itself.
window.addEventListener(
"load",
function setupWebGL(evt) {
"use strict";
// Cleaning after ourselves. The event handler removes
// itself, because it only needs to run once.
window.removeEventListener(evt.type, setupWebGL, false);
// References to the document elements.
var paragraph = document.querySelector("p"),
canvas = document.querySelector("canvas");
// Getting the WebGL rendering context.
var gl =
canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
// If failed, inform user of failure. Otherwise, initialize
// the drawing buffer (the viewport) and clear the context
// with a solid color.
if (!gl) {
paragraph.innerHTML =
"Failed to get WebGL context. " +
"Your browser or device may not support WebGL.";
return;
}
paragraph.innerHTML = "Congratulations! Your browser supports WebGL. ";
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
// Set the clear color to darkish green.
gl.clearColor(0.0, 0.5, 0.0, 1.0);
// Clear the context with the newly set color. This is
// the function call that actually does the drawing.
gl.clear(gl.COLOR_BUFFER_BIT);
},
false,
);
è¿ä¸ªä¾åç代ç å¯ä»¥å¨ GitHub ä¸ä¸è½½ã
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