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

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.

主站蜘蛛池模板: 湖口县| 曲阳县| 古浪县| 临高县| 祁连县| 方城县| 四川省| 安徽省| 定陶县| 广东省| 钦州市| 田林县| 章丘市| 柘城县| 大化| 兴隆县| 区。| 宁陕县| 株洲市| 抚顺市| 黄大仙区| 库尔勒市| 海晏县| 黎川县| 天祝| 福贡县| 泌阳县| 铜川市| 定南县| 蒙自县| 新昌县| 留坝县| 蚌埠市| 平远县| 灵丘县| 射洪县| 本溪| 株洲市| 达州市| 天峻县| 中超|