OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 |
| 3 /* |
| 4 ** Copyright (c) 2012 The Khronos Group Inc. |
| 5 ** |
| 6 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 7 ** copy of this software and/or associated documentation files (the |
| 8 ** "Materials"), to deal in the Materials without restriction, including |
| 9 ** without limitation the rights to use, copy, modify, merge, publish, |
| 10 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 11 ** permit persons to whom the Materials are furnished to do so, subject to |
| 12 ** the following conditions: |
| 13 ** |
| 14 ** The above copyright notice and this permission notice shall be included |
| 15 ** in all copies or substantial portions of the Materials. |
| 16 ** |
| 17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 24 */ |
| 25 |
| 26 --> |
| 27 <!DOCTYPE html> |
| 28 <html> |
| 29 <head> |
| 30 <meta charset="utf-8"> |
| 31 <!-- This is a visual test that programs must have both a vertex and |
| 32 fragment shader attached; the fixed function pipeline on the |
| 33 desktop must remain disabled. --> |
| 34 <script type="text/javascript"> |
| 35 function log() { |
| 36 var s = ""; |
| 37 for (var i = 0; i < arguments.length; ++i) { |
| 38 s += arguments[i] + " "; |
| 39 } |
| 40 |
| 41 document.getElementById("log").innerHTML += s + "<br>"; |
| 42 } |
| 43 |
| 44 function go() { |
| 45 var gl = document.getElementById("c").getContext("experimental-webgl"); |
| 46 |
| 47 gl.clearColor(0.0, 0.0, 0.0, 0.0); |
| 48 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 49 |
| 50 var vs = gl.createShader(gl.VERTEX_SHADER); |
| 51 gl.shaderSource(vs, "attribute vec4 aVertex; attribute vec4 aColor; vary
ing vec4 vColor; void main() { vColor = aColor; gl_Position = aVertex; }"); |
| 52 gl.compileShader(vs); |
| 53 |
| 54 var fs = gl.createShader(gl.FRAGMENT_SHADER); |
| 55 gl.shaderSource(fs, "precision mediump float; varying vec4 vColor; void
main() { gl_FragColor = vColor; }"); |
| 56 gl.compileShader(fs); |
| 57 |
| 58 var prog = gl.createProgram(); |
| 59 gl.attachShader(prog, vs); |
| 60 // don't attach a fragment shader -- may use fixed pipeline on desktop i
f the implementation doesn't check! |
| 61 //gl.attachShader(prog, fs); |
| 62 |
| 63 gl.bindAttribLocation(prog, 0, "aVertex"); |
| 64 gl.bindAttribLocation(prog, 1, "aColor"); |
| 65 |
| 66 gl.linkProgram(prog); |
| 67 |
| 68 var vbuf = gl.createBuffer(); |
| 69 gl.bindBuffer(gl.ARRAY_BUFFER, vbuf); |
| 70 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ |
| 71 -1.0, -1.0, 0.0, 1.0, |
| 72 -1.0, 1.0, 0.0, 1.0, |
| 73 1.0, -1.0, 0.0, 1.0, |
| 74 1.0, 1.0, 0.0, 1.0])
, gl.STATIC_DRAW); |
| 75 gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 0, 0); |
| 76 |
| 77 var cbuf = gl.createBuffer(); |
| 78 gl.bindBuffer(gl.ARRAY_BUFFER, cbuf); |
| 79 gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array([255, 0, 0, |
| 80 0, 255, 0, |
| 81 0, 0, 255, |
| 82 255, 255, 0])
, gl.STATIC_DRAW); |
| 83 gl.vertexAttribPointer(1, 3, gl.UNSIGNED_BYTE, false, 0, 0); |
| 84 |
| 85 gl.enableVertexAttribArray(0); |
| 86 gl.enableVertexAttribArray(1); |
| 87 |
| 88 gl.useProgram(prog); |
| 89 |
| 90 gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); |
| 91 |
| 92 log("glError", "0x" + gl.getError().toString(16)); |
| 93 } |
| 94 </script> |
| 95 </head> |
| 96 |
| 97 <body onload="go()"> |
| 98 <p>Should be green in the rectangle below:</p> |
| 99 <canvas style="background: green;" id="c"></canvas> |
| 100 <div id="log"></div> |
| 101 </body> |
| 102 </html> |
OLD | NEW |