官术网_书友最值得收藏!

WebGL and JavaScript

As we learned in the previous chapter, working with the 2D canvas was pretty straightforward. To draw an image, you just need to translate the context to the pixel coordinates where you want to draw the image, and call the drawImage context function by passing in the image, its width, and its height. You could make this even simpler and forget about the translation passing the x and y coordinates directly into the drawImage function if you prefer. With the 2D canvas, you are working with images, but with WebGL, you are always working with 3D geometry, even when you are coding a 2D game. With WebGL, you will need to render textures onto geometry. You need to work with vertex buffers and texture coordinates. The vertex shader we wrote earlier takes 3D coordinate data and texture coordinates and passes those values onto a fragment shader that will interpolate between the geometry, and use a texture sampling function to retrieve the proper texture data to render pixels to the canvas.

主站蜘蛛池模板: 太仆寺旗| 博乐市| 揭西县| 商南县| 花莲县| 望都县| 岢岚县| 榕江县| 青神县| 封丘县| 武城县| 阳城县| 呈贡县| 商河县| 南汇区| 资阳市| 象山县| 略阳县| 寿光市| 军事| 宜春市| 平潭县| 洛扎县| 鸡西市| 郁南县| 隆安县| 石渠县| 门源| 万载县| 内乡县| 闽侯县| 仪征市| 邮箱| 芮城县| 左权县| 曲周县| 清徐县| 秦皇岛市| 乐都县| 疏勒县| 紫阳县|