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

2D canvas to WebGL

Let's begin by copying out canvas code from the Chapter02 directory into the Chapter03 directory. Next, we are going to rename the canvas_shell.html file to webgl_shell.html. We will rename canvas.css to webgl.css. Lastly, we will rename the canvas.c file webgl.c. We will also need to make sure that we copy over the spaceship.png file. We are not going to be changing the webgl.css file at all. We will make the most significant changes to the webgl_shell.html file. There is a lot of code that must be added to make the switch from 2D canvas to WebGL; almost all of it is additional JavaScript code. We will need to make some minor tweaks to webgl.c so that the ship's position in the MoveShip function reflects the WebGL coordinate system with its origin in the center of the canvas.

Before we begin, I would like to mention that this WebGL code is not meant to be production ready. The game we will be creating will not use WebGL in the way that I am demonstrating here. That is not the most efficient or scalable code. What we are writing will not be able to render more than one sprite at a time without significant changes. The reason I am walking you through what it takes to render 2D images using WebGL is to give you an idea of what is going on behind the scenes when you are using a library like SDL. If you do not care how things work behind the scenes, no one will fault you for skipping ahead. Personally, I always prefer knowing a little more.

主站蜘蛛池模板: 湄潭县| 大悟县| 循化| 德令哈市| 宁城县| 卫辉市| 浦北县| 监利县| 涟水县| 达拉特旗| 镇宁| 清河县| 白水县| 格尔木市| 察隅县| 莱阳市| 芦溪县| 朝阳区| 铜梁县| 郯城县| 阿瓦提县| 内黄县| 托克逊县| 武城县| 元阳县| 密云县| 嵊泗县| 曲靖市| 乌兰察布市| 山阳县| 靖边县| 泗洪县| 安阳市| 海南省| 图片| 泰宁县| 沂源县| 凤山县| 沈丘县| 翁源县| 上栗县|