OpenGL ES 2 for Android: A Quick-Start Guide

0
(0)

OpenGL ES 2 for Android: A Quick-Start Guide
 

  • Author:Kevin Brothaler
  • Length: 325 pages
  • Edition: 1
  • Publisher: Pragmatic Bookshelf
  • Publication Date: 2013-07-03
  • ISBN-10: 1937785343
  • ISBN-13: 9781937785345
  • Sales Rank: #1175601 (See Top 100 Books)
  • Download:Register/Login to Download
  • Buy Print:Buy from amazon


    Book Description

    Android is booming like never before, with millions of devices shipping every day. It’s never been a better time to learn how to create your own 3D games and live wallpaper for Android. You’ll find out all about shaders and the OpenGL pipeline, and discover the power of OpenGL ES 2.0, which is much more feature-rich than its predecessor. If you can program in Java and you have a creative vision that you’d like to share with the world, then this is the book for you.

    This book will teach you everything you need to know to create compelling graphics on Android. You’ll learn the basics of OpenGL by building a simple game of air hockey, and along the way, you’ll see how to initialize OpenGL and program the graphics pipeline using shaders. Each lesson builds upon the one before it, as you add colors, shading, 3D projections, touch interaction, and more.

    Then, you’ll find out how to turn your idea into a live wallpaper that can run on the home screen. You’ll learn about more advanced effects involving particles, lighting models, and the depth buffer. You’ll understand what to look for when debugging your program, and what to watch out for when deploying to the market.

    OpenGL can be somewhat of a dark art to the uninitiated. As you read this book, you’ll learn each new concept from first principles. You won’t just learn about a feature; you’ll also understand how it works, and why it works the way it does. Everything you learn is forward-compatible with the just-released OpenGL ES 3, and you can even apply these techniques to other platforms, such as iOS or HTML5 WebGL.

    Printed in full color.

    Top Five OpenGL ES Tips

    1. Avoid expensive operations on the UI and rendering threads.

    To avoid frame rate stutters or the dreaded “Application not responding” dialog from appearing, expensive operations should be run asynchronously in a background thread. This is especially important when it comes to the rendering thread, as rendering at 30 frames per second means that each frame has to complete in about 33 milliseconds to avoid frame stutters.

    Garbage collection is an expensive operation that happens non-deterministically and can cause rendering stalls, so to avoid this, you’ll also want to minimize object allocation during a frame to reduce pressure on the garbage collector. You may even see benefits to doing a manual GC at certain points in the application.

    2. Do expensive texture and shader loads during intermissions.

    Some expensive operations need to be done on the rendering thread, such as texture loads and shader compilations. These operations can cause noticeable stuttering if they happen in the middle of rendering, so to avoid this, preload these resources at opportune times, such as when the game / application is loaded, or at the beginning of each level.

    3. Take advantage of the libraries out there.

    There are many libraries out there that support OpenGL ES 2.0 development without boxing you into a framework or a closed-source middleware solution. Libgdx is one of these libraries, and by using a library like libgdx, you can more easily port your code to other platforms, as well as take advantage of the library’s math classes and asset loading management.

    4. Read the documentation.

    The OpenGL specs and manuals are available for free from Khronos.org. Each GPU vendor also shares a wealth of free information on how to use their GPUs, and as you read the documentation, you’ll find that they generally share a lot of advice in common, such as “minimize state switches” and “avoid discard in a fragment shader.” Reading these documents and specs will give you a lot more insight into how the GPUs work at a lower level, and will help you understand what the pitfalls are, and how to avoid premature pessimization when writing your OpenGL code.

    5. Focus on what will impress the end user.

    Sometimes it’s easy to lose sight of the end goal, and to become focused on optimizing areas that won’t make much of a difference to the end user. Does it matter if we get this shader to execute 2% faster? Or will we make much more of a visual impact by finding a better artist? Find out what the most important areas are, and then focus on improving those first.

    Table of Contents

    Chapter 1. Getting Started

    Part I: A Simple Game of Air Hockey
    Chapter 2. Defining Vertices and Shaders
    Chapter 3. Compiling Shaders and Drawing to the Screen
    Chapter 4. Adding Color and Shade
    Chapter 5. Adjusting to the Screen’s Aspect Ratio
    Chapter 6. Entering the Third Dimension
    Chapter 7. Adding Detail with Textures
    Chapter 8. Building Simple Objects
    Chapter 9. Adding Touch Feedback: Interacting with Our Air Hockey Game

    Part II: Building a 3D World
    Chapter 10. Spicing Things Up with Particles
    Chapter 11. Adding a Skybox
    Chapter 12. Adding Terrain
    Chapter 13. Lighting Up the World
    Chapter 14. Creating a Live Wallpaper
    Chapter 15. Taking the Next Step

    Appendix A1. The Matrix Math Behind the Projections
    Appendix A2. Debugging

    中文:

    书名:OpenGL ES 2 for Android:快速入门指南

    Android正在以前所未有的速度蓬勃发展,每天都有数百万台设备出货。现在是学习如何为Android创建自己的3D游戏和实时墙纸的最佳时机。您将了解所有有关着色器和OpenGL管道的信息,并发现OpenGL ES 2.0的强大功能,它比其前身功能更加丰富。如果你能用Java编程,并且你有一个创造性的愿景想要与世界分享,那么这本书就是为你而写的。

    这本书将教你所有你需要知道的在Android上创建引人注目的图形。您将通过构建一个简单的空中曲棍球游戏来学习OpenGL的基础知识,在此过程中,您将了解如何初始化OpenGL并使用着色器对图形管道进行编程。每一课都建立在前一课的基础上,因为您添加了颜色、阴影、3D投影、触摸交互等。

    然后,你就会知道如何把你的想法变成一张可以在主屏幕上运行的活动墙纸。您将了解更高级的效果,包括粒子、照明模型和深度缓冲区。您将了解在调试程序时要注意什么,以及在部署到市场上时要注意什么。

    对于外行来说,OpenGL在某种程度上是一门黑暗艺术。当你读这本书的时候,你将从基本原理中学到每一个新概念。您将不仅仅了解一项功能;您还将了解它是如何工作的,以及它为什么以这种方式工作。你学到的所有东西都与刚刚发布的OpenGL ES 3向前兼容,你甚至可以将这些技术应用到其他平台,如iOS或HTML5 WebGL。

    Printed in full color.

    Top Five OpenGL ES Tips

    1.避免在UI和渲染线程上执行代价高昂的操作。

    为了避免出现帧速率卡顿或可怕的应用程序不响应对话框,开销较大的操作应该在后台线程中异步运行。当涉及到渲染线程时,这一点尤其重要,因为以每秒30帧的速度渲染意味着每个帧必须在大约33毫秒内完成,以避免帧卡顿。

    垃圾收集是一项代价高昂的非确定性操作,可能会导致呈现停顿,因此要避免这种情况,您还需要在帧期间尽量减少对象分配,以减轻垃圾收集器的压力。您甚至可以在应用程序中的某些点上看到手动GC的好处。

    2.在中场休息时加载昂贵的纹理和着色器。

    需要在渲染线程上执行一些开销较大的操作,例如纹理加载和着色器编译。如果这些操作发生在渲染过程中,可能会导致明显的卡顿,因此要避免这种情况,请在适当的时间预加载这些资源,例如在加载游戏/应用程序时,或在每个关卡的开始时。

    3.充分利用现有的图书馆。

    有许多库支持OpenGL ES 2.0开发,而无需将您捆绑到框架或封闭源代码的中间件解决方案中。Libgdx就是其中之一,通过使用像libgdx这样的库,您可以更轻松地将代码移植到其他平台,并利用该库的数学类和资产加载管理。

    4. Read the documentation.

    OpenGL规范和手册可从Khronos.org免费获得。每个GPU供应商还分享了大量关于如何使用他们的GPU的免费信息,当你阅读文档时,你会发现他们通常都有很多共同的建议,例如最小化状态开关和避免在片段着色器中丢弃。阅读这些文档和规范将使你更深入地了解GPU在较低级别上是如何工作的,并将帮助你理解陷阱是什么,以及如何在编写OpenGL代码时避免过早悲观。

    5. Focus on what will impress the end user.

    有时很容易忽视最终目标,而专注于优化那些对最终用户没有太大影响的领域。如果我们让这个着色器的执行速度快2%,这有关系吗?或者我们会通过寻找一位更好的艺术家来产生更大的视觉影响吗?找出最重要的领域是什么,然后首先专注于改进这些领域。

    目录表

    Chapter 1. Getting Started

    第一部分:空中曲棍球的简单游戏
    第2章.定义顶点和着色器
    第3章.编译着色器并绘制到屏幕
    第4章:添加颜色和阴影
    第五章.调整屏幕的纵横比
    第六章:进入第三维度
    第7章:使用纹理添加细节
    Chapter 8. Building Simple Objects
    第九章添加触摸反馈:与我们的空中曲棍球游戏互动

    第二部分:构建3D世界
    第十章.使用粒子使事物更有趣
    第11章:添加Skybox
    Chapter 12. Adding Terrain
    第十三章.点亮世界
    第14章:创建活动墙纸
    第十五章.采取下一步行动

    附录A1。投影背后的矩阵数学
    附录A2。除错

  • 下载电子版:下载地址
  • 购买纸质版:亚马逊商城

    点击星号评分!

    平均分 0 / 5. 投票数: 0

    还没有投票!请为他投一票。

  • 推荐阅读

    评论 抢沙发

    评论前必须登录!

     

    登录

    找回密码

    注册