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

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.

主站蜘蛛池模板: 宜都市| 赤城县| 固镇县| 东阿县| 雷山县| 吉安市| 通榆县| 霍山县| 镇康县| 原平市| 门头沟区| 固阳县| 揭阳市| 东台市| 清水河县| 和平区| 大丰市| 潼关县| 松潘县| 中卫市| 依兰县| 南平市| 丹江口市| 中卫市| 延安市| 黄平县| 元阳县| 珲春市| 马山县| 福安市| 姜堰市| 揭阳市| 香河县| 信阳市| 容城县| 华亭县| 桓台县| 遂川县| 惠东县| 太康县| 泸西县|