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 |
| 28 <!DOCTYPE html> |
| 29 <html> |
| 30 <head> |
| 31 <meta charset="utf-8"> |
| 32 <title>Canvas Compositing Test</title> |
| 33 <link rel="stylesheet" href="../resources/js-test-style.css"/> |
| 34 <script src="../resources/js-test-pre.js"></script> |
| 35 <script src="../conformance/resources/webgl-test.js"> </script> |
| 36 </head> |
| 37 <body> |
| 38 Below are 2 50x50 pixel canvas but using CSS to display them at 100x100 pixels.
<br/> |
| 39 They are solid black with a red triangle<br/> |
| 40 They each have a 10px CSS solid black border around them.<br/> |
| 41 Depending on how the browser composites the canvas with the page they will get |
| 42 a white outline<hr/> |
| 43 <div> |
| 44 2d canvas<br/> |
| 45 <canvas id="example2" width="50" height="50" style="width: 100px; height: 100px;
border: 10px solid black;"></canvas> |
| 46 </div> |
| 47 <hr/> |
| 48 3d canvas<br/> |
| 49 <div> |
| 50 <canvas id="example" width="50" height="50" style="width: 100px; height: 100px;
border: 10px solid black;"></canvas> |
| 51 </div> |
| 52 <hr/> |
| 53 img tag<br/> |
| 54 <img src="50x50pixel-black-with-red-triangle.png" style="width: 100px; height: 1
00px; border: 10px solid black;"/> |
| 55 <div id="description"></div> |
| 56 <div id="console"></div> |
| 57 <script id="vshader" type="x-shader/x-vertex"> |
| 58 attribute vec4 vPosition; |
| 59 void main() |
| 60 { |
| 61 gl_Position = vPosition; |
| 62 } |
| 63 </script> |
| 64 |
| 65 <script id="fshader" type="x-shader/x-fragment"> |
| 66 void main() |
| 67 { |
| 68 gl_FragColor = vec4(1.0,0.0,0.0,1.0); |
| 69 } |
| 70 </script> |
| 71 |
| 72 <script> |
| 73 function fail(x,y, buf, shouldBe) |
| 74 { |
| 75 var i = (y*50+x) * 4; |
| 76 var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+b
uf[i+2]+","+buf[i+3]+"), should be "+shouldBe; |
| 77 testFailed(reason); |
| 78 } |
| 79 |
| 80 function pass() |
| 81 { |
| 82 testPassed("drawing is correct"); |
| 83 } |
| 84 |
| 85 function init() |
| 86 { |
| 87 var canvas2d = document.getElementById("example2"); |
| 88 var ctx2d = canvas2d.getContext("2d"); |
| 89 ctx2d.fillStyle = "rgba(0, 0, 0, 255)" |
| 90 ctx2d.fillRect(0, 0, 50, 50); |
| 91 ctx2d.fillStyle = "rgba(255, 0, 0, 255)" |
| 92 ctx2d.beginPath(); |
| 93 ctx2d.moveTo(25, 12.5); |
| 94 ctx2d.lineTo(12.5, 37.5); |
| 95 ctx2d.lineTo(37.5, 37.5); |
| 96 ctx2d.lineTo(25, 12.5); |
| 97 ctx2d.fill(); |
| 98 |
| 99 |
| 100 if (window.initNonKhronosFramework) { |
| 101 window.initNonKhronosFramework(false); |
| 102 } |
| 103 |
| 104 gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0,
0, 0, 1 ], 1); |
| 105 gl.viewport(0, 0, 50, 50); |
| 106 |
| 107 var vertexObject = gl.createBuffer(); |
| 108 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); |
| 109 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5
,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW); |
| 110 gl.enableVertexAttribArray(0); |
| 111 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); |
| 112 |
| 113 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 114 gl.drawArrays(gl.TRIANGLES, 0, 3); |
| 115 } |
| 116 |
| 117 init(); |
| 118 successfullyParsed = true; |
| 119 </script> |
| 120 </body> |
| 121 <script src="../resources/js-test-post.js"></script> |
| 122 |
| 123 <script> |
| 124 </script> |
| 125 |
| 126 </body> |
| 127 </html> |
OLD | NEW |