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

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.

主站蜘蛛池模板: 高清| 正安县| 鹰潭市| 怀来县| 同德县| 临夏县| 澄江县| 屏东市| 柏乡县| 新泰市| 徐汇区| 陵水| 虞城县| 林芝县| 前郭尔| 呼伦贝尔市| 衡阳县| 英吉沙县| 焦作市| 乌兰浩特市| 罗山县| 辽源市| 山西省| 新乡市| 九台市| 根河市| 湘阴县| 曲靖市| 稷山县| 珲春市| 高密市| 神农架林区| 綦江县| 济南市| 上栗县| 滦平县| 曲松县| 秭归县| 亳州市| 丹棱县| 兖州市|