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

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.

主站蜘蛛池模板: 舟曲县| 保德县| 万山特区| 莱芜市| 思南县| 革吉县| 巧家县| 庆云县| 新河县| 遵义市| 平乐县| 金溪县| 锦州市| 临夏市| 余干县| 静宁县| 池州市| 泌阳县| 行唐县| 桦南县| 康定县| 康保县| 舒城县| 廉江市| 辛集市| 新化县| 旺苍县| 宜宾县| 西盟| 吕梁市| 锦州市| 柳林县| 北碚区| 云林县| 延庆县| 曲麻莱县| 敦煌市| 黄平县| 华容县| 大竹县| 平南县|