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

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.

主站蜘蛛池模板: 永兴县| 阿鲁科尔沁旗| 蓬莱市| 凌云县| 金华市| 郁南县| 东辽县| 新津县| 嘉定区| 安仁县| 南涧| 隆回县| 鲁甸县| 五峰| 牙克石市| 通许县| 中山市| 焉耆| 新兴县| 临高县| 泽普县| 遵义县| 嵩明县| 东方市| 临颍县| 郑州市| 阳朔县| 诏安县| 连江县| 北辰区| 永宁县| 德保县| 军事| 大姚县| 夏河县| 浠水县| 沁水县| 南岸区| 家居| 普安县| 万年县|