Slashdot Mirror


OpenGL ES 2.0 Programming Guide

Martin Ecker writes "Mobile phones and other embedded devices are getting more and more powerful each year. The availability of dedicated hardware for 3D rendering is becoming increasingly ubiquitous, and the latest mobile phones come with 3D hardware acceleration that rivals the power of desktop graphics hardware. OpenGL ES 2.0 is the latest version of a cross-platform, low-level graphics API to utilize these new resources available in embedded devices. The OpenGL ES 2.0 Programming Guide published by Addison-Wesley Publishing aims to help the reader make use of the full power of OpenGL ES 2.0 to create interesting 3D applications." Keep reading for the rest of Martin's review. OpenGL ES 2.0 Programming Guide author Aaftab Munshi, Dan Ginsburg, Dave Shreiner pages 417 publisher Addison-Wesley Publishing rating 7/10 reviewer Martin Ecker ISBN 0-321-50279-5 summary All you need to know to develop mobile phone 3D applications in OpenGL ES 2.0 The book is intended for an audience with experience in the C programming language and a solid foundation in computer graphics. No experience with the desktop version of OpenGL is necessary, however. The book starts out with a basic introduction of OpenGL ES and explains the differences between OpenGL ES 1.x and 2.0. The main difference is that 2.0 has completely dropped support for the fixed-function pipeline and is now completely shader-based. The book then immediately gets the reader's feet wet by discussing a first simple example program that renders a triangle on the screen. This is also where the downsides of dropping fixed-function support in OpenGL ES 2.0 become apparent. It takes almost 4 pages of code to render a simple triangle. The reason for this is that you need to write a vertex and fragment shader (albeit really simple ones) to transform vertices to device coordinates and to assign a color to each pixel of the triangle. Of course, in "real-life" applications this isn't much of a problem. The increased possibilities that programmable shaders have to offer outweigh the inconvenience of having a bit more setup code.

The book continues to discuss EGL, which is like WGL on Windows or GLX on Unix, i.e. the interface between OpenGL and the underlying operating system. The next few chapters give a basic introduction to the OpenGL Shading Language. As mentioned above, with OpenGL ES 2.0 using shaders is the only way to get something on the screen. So having a good grasp of the OpenGL Shading Language is essential. The discussion at this point is fairly dry and might overwhelm readers that haven't used a shading language before. Later chapters, however, delve more deeply into developing vertex and fragment shaders.

The subsequent chapters present how to specify vertices and primitives in OpenGL ES. OpenGL ES 2.0 only supports generic vertex attributes (since there is no fixed-function pipeline anymore) and vertex data can only be specified using vertex arrays or vertex buffer objects. Immediate mode as known from desktop OpenGL is not available.

Now that the reader is familiar with sending vertices and triangles to the 3D hardware, the book describes vertex and fragment shaders in more detail. There is also a pretty long chapter on texture mapping, going into the specifics of the API calls to define and upload textures to the hardware. There are numerous examples in these chapters that demonstrate how to do lighting, generate texture coordinates, perform vertex skinning, multitexturing. These are all essential examples because the fixed-function pipeline that used to do these things is not available in OpenGL ES 2.0.

The next two chapters deal with the backend of the pipeline discussing the various per-fragment operations following the fragment shader, such as stencil test, scissor test, depth test, and framebuffer blending. Also framebuffer and renderbuffer objects (FBOs) used to efficiently implement render-to-texture in OpenGL are discussed. FBOs are thankfully fully supported in OpenGL ES 2.0. It's nice to see a whole chapter on this topic since this particular feature took a long time to make its way into OpenGL.

Chapter 13 on advanced programming with OpenGL ES is probably the best part of the book for me. It is one of the longest chapters of the book and contains numerous examples of advanced shader techniques, such as per-pixel lighting, point sprite particle systems, 3D noise, procedural textures, and some others. The provided examples are a good starting point for experimentation.

The book concludes with a chapter on state queries, which are used to obtain various parameters about the OpenGL render state, and a chapter on the interesting topic of using OpenGL ES on handheld platforms, which briefly goes into OpenKODE. OpenKODE is a standard set of APIs that provides a unified interface to the system OS of handheld devices.

Overall, the OpenGL ES 2.0 Programming Guide is an excellent book if you want to start developing 3D graphics applications for today's embedded devices and bleeding-edge mobile phones. The book also does a good job of pointing out the differences and similarities with desktop OpenGL. So if you're already familiar with OpenGL the book can help you identify the limitations of OpenGL ES compared to its big cousin.

Martin has been involved in real-time graphics programming for more than 10 years and works as a professional game developer for High Moon Studios in sunny California.

You can purchase OpenGL ES 2.0 Programming Guide from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

48 comments

  1. Great! by ilovesymbian · · Score: 0

    Great! I was waiting for this book to be out. So I can write OpenGL apps for the iPhone.

    Any idea when the iPhone SDK will reflect this update?

    1. Re:Great! by egomaniac · · Score: 1

      It won't. Unless I'm mistaken the hardware in the iPhone simply doesn't support the features in question. Almost no currently-shipping device does.

      --
      ZFS: because love is never having to say fsck
    2. Re:Great! by Anonymous Coward · · Score: 4, Informative

      The iPhone doesn't have an OpenGL ES 2.0 chip, it's a simple ES 1.1 part.

    3. Re:Great! by atomicthumbs · · Score: 3, Informative

      You can write it for the Pandora, too. That supports 2.0.

      --
      http://pinopsida.com
    4. Re:Great! by s_p_oneil · · Score: 1

      When the Tegra comes out, this news will be more relevant.

  2. 3d displays? by Colin+Smith · · Score: 1

    No?

    Very disappointed. I want to be able to put on a pair of 3d glasses and look around and see all of the information superimposed on reality.

    I'm not going to shell out any cash till that's one of the features.
     

    --
    Deleted
    1. Re:3d displays? by ZeroFactorial · · Score: 2, Informative

      What you're referring to is known as Augmented Reality" and a lot of smart people are working on it.

  3. Rivalling? by nick_davison · · Score: 5, Informative

    the latest mobile phones come with 3D hardware acceleration that rivals the power of desktop graphics hardware

    If, by "desktop graphics hardware" we're comparing to the books, empty bottles and other assorted clutter, it exceeds them.

    If, however, we mean "desktop PC"... it only rivals it if we're talking about integrated chipsets from a decade ago.

    It's a cute dream. And Monkey Ball on my 480x320, ~50% of VGA resolution iPhone doesn't look half bad for a simplified version of a GameCube era title. But, even accepting there's better hardware than the iPhone for 3D... It's a LONG way from rivalling desktop graphics quality, even on a pixel for pixel comparrison where a 0.15MP phone is trying to compete with a 2.3MP 24 inch monitor that's pushing around 15x the number of pixels.

    It's kind of like saying I rival an olympic runner. It's true in so far as we both have legs and, if I limit my competing to being against small children in my own backyard, I can often win. In every other way that counts, it's just not happening though.

    1. Re:Rivalling? by Anonymous Coward · · Score: 2, Funny

      This is /. it's car analogy or nothing.

    2. Re:Rivalling? by daviddennis · · Score: 3, Insightful

      I'm trying to learn OpenGL so I can program in Open GL ES for my iPhone, and it seems like you need a book specifically for ES, because OpenGL ES eliminated most of the features used in beginning OpenGL tutorials!

      But the iPhone supports only 1.1 and so I'm wondering if this book would even work for me. I'm thinking its rival, Mobile 3D Graphics ... might be better.

      Any thoughts from those who have checked out both books? It would be nice to have good information before I blow $50.

      Thanks!

      D

    3. Re:Rivalling? by ZeroFactorial · · Score: 1

      What you're referring to is known as Augmented Reality" and a lot of smart people are already working on it.

    4. Re:Rivalling? by ZeroFactorial · · Score: 1

      Oh bugger, clicked reply on the wrong post. This reply meant to go with previous post.

    5. Re:Rivalling? by egomaniac · · Score: 2, Informative

      Just learn from the OpenGL ES spec. It's not hard at all -- I was rendering real graphics in a few hours.

      --
      ZFS: because love is never having to say fsck
    6. Re:Rivalling? by nschubach · · Score: 1

      It's like saying your Ford Focus can rival my Ferrari...(?)

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
    7. Re:Rivalling? by necro2607 · · Score: 1

      Well, if I can play Quake 1 on my iPhone at far far better framerate than I played it on my Mac at 320x200 in 1997 or whenever it first came out for Mac OS, it's definitely a freaking solid offering. There's nothing "dreamlike" about it other than that it's something people HAVE dreamed about for ages, and it's finally becoming possible. Consider that some dudes got straight-up Quake 3 running on iPod Touch/iPhone. No joke, check out the videos here. It's pretty damn surprising, honestly.

      Also it's pretty safe to say the iPhone 3d hardware acceleration rivals that of a lot of onboard graphics chips even on today's motherboards. ;)

    8. Re:Rivalling? by Anonymous Coward · · Score: 0

      While I agree that mobile graphics are behind desktop by a significant way, it's nowhere as bleak as you paint the picture to be.

      We're not talking about 480x320 rendering anymore, more and more devices are coming to market with chipsets which can reasonably push pixels for 1024x768 or higher.

      looking at http://www.arm.com/miscPDFs/21863.pdf they're making chipsets which can push 450+ Mpixels / sec, which is around 20 frags per pixel * 30fps * 1024 * 768.

      For the kinds of screens that are reasonable (max DPI worthwhile etc) for mobile devices, you have a lot of rendering power.

      There are already devices like the pandora -- http://en.wikipedia.org/wiki/Pandora_(console) -- which have these kind of processors in them.

      But are mobile platforms ever going to be able to turn out the same as the current desktop can with about 100 times less power available? No.

    9. Re:Rivalling? by Glacial+Wanderer · · Score: 1

      You don't want to use and OpenGL ES 2.0 book to learn how to program in OpenGL ES 1.1. OpenGL ES 1.1 and OpenGL ES 2.0 are very different APIs. Desktop OpenGL has much more in common with ES 1.1 than ES 2.0. ES 2.0 replaced all the fixed function shading API in ES 1.1 with programmable shaders.

      OpenGL ES 1.1 is most similar to something like desktop OpenGL 1.5. There are still significant differences, but those are the sorts of tutorials you want to look at if you can't find ES 1.1 specific tutorials.

      Below people talk about using the spec to learn OpenGL. That might work if you know a lot about computer graphics, but its not the best way in my opinion. The OpenGL specs are written for hardware implementers and not for app programmers. Heck, I'm been implementing OpenGL for over 7 years and these specs still confuse me sometimes.

    10. Re:Rivalling? by TheRaven64 · · Score: 4, Informative

      The OpenGL specs are written for hardware implementers and not for app programmers. Heck, I'm been implementing OpenGL for over 7 years and these specs still confuse me sometimes.

      Have you looked at the OpenGL ES 2.0 spec? I glanced over it a couple of days ago (a friend asked bought an OpenPandora system and asked me for advice about learning ES). It is much more readable than other versions of OpenGL, and includes some nice introductory text explaining the terminology that will be used later on. Someone capable of checking Wikipedia for general concepts when they find they don't understand what the spec is explaining (or who has already come across the general ideas in 3D computer graphics) should have no problems learning from it.

      --
      I am TheRaven on Soylent News
    11. Re:Rivalling? by grumbel · · Score: 1

      It is true that a lot of beginners OpenGL code won't work on OpenGL-ES, but the differences between the two isn't really all that big. The main difference is simply that in OpenGL-ES you have to use vertex arrays, while in OpenGL it is an optional thing. While this breaks many code examples its not hard to fix and code that uses vertex arrays will work on both OpenGL and OpenGL-ES.

    12. Re:Rivalling? by Poltras · · Score: 2, Funny

      This is /. you don't have a Ferrari.

    13. Re:Rivalling? by Anonymous Coward · · Score: 0

      Yeah, starting with regular OpenGL tutorials wouldn't do you much good.
      For some reason most of the OpenGL tutorials I've seen start with horrible legacy stuff like glBegin() and glEnd(). You don't want to be using those.
      Count yourself lucky that you're starting with OpenGL ES, where most of the stuff you shouldn't be using simply aren't there. Even if you learn ordinary OpenGL later, you'll have avoided some bad practices that's floating around.

    14. Re:Rivalling? by Anonymous Coward · · Score: 0

      Mobile Graphics HW is not that far behind the desktop counterparts (Notice that this video was posted one year ago):

      http://www.youtube.com/watch?v=UWCVZiYr1Sw

  4. Re:There's only ONE guide you need -THE BIBLE! by Anonymous Coward · · Score: 0

    With an argument like that, you've just converted me over. Just give me a moment while I call my wife to cancel the abortion and kick the two gay guys out of my bedroom.

    There. I feel so moral now. So, when do we stone the neighbors wife for sleeping with Bob?

  5. So, for an OpenGL program for max portability... by Dr.+Manhattan · · Score: 1

    ...particularly including desktops, is this really the way to go? If something is written to the OpenGL ES 2.0 API, besides 'mobile devices' what desktop systems (Linux, Mac, Windows) could it run on?

    --
    PHEM - party like it's 1997-2003!
  6. Re:So, for an OpenGL program for max portability.. by eggnoglatte · · Score: 3, Informative

    OpenGL ES is a subset of OpenGL. For 2.0, they removed much of the fixed function pipeline and replaced it with GLSL (OpenGL's shading language). As such, I would expect it to be relatively straightforward to write ES code that runs on a modern OpenGL desktop (one that supports the latest GLSL). At most you'll need a few #ifdefs.

  7. Re:So, for an OpenGL program for max portability.. by fuzzyfuzzyfungus · · Score: 1

    I'm guessing that there are a few gotchas, possibly nasty ones; but OpenGL ES is almost entirely a subset of OpenGL proper, and so should play fairly well with anything that has an OpenGL implementation.

  8. Re:There's only ONE guide you need -THE BIBLE! by Anonymous Coward · · Score: 0

    your's

    Christian or not, you're going to hell for this!

  9. OpenGL ES for Open Pandora by corsec67 · · Score: 1

    I have this book sitting in my Amazon cart, because I might get it for developing 3D stuff on the Pandora.

    I preordered the Pandora, and should get it by Christmas, so I haven't gotten this book yet.

    --
    If I have nothing to hide, don't search me
  10. Treed3D OpenGL ES2.0 Demonstration by Anonymous Coward · · Score: 1, Informative

    http://vimeo.com/1716575
    Demo was developed for Texas Instruments OMAP3 platform, but should run on most OpenGL ES 2.0 platforms out there. It was released at Assembly 2008 Real Wild demo competition.

  11. Well, I don't want any! by Chemisor · · Score: 0, Flamebait

    Get your stinkin' 3D off my cell phone! It is yet another ridiculous piece of bloatware because of which it takes ages to turn the phone on or off. Do these developers realize that most people don't want the stuff they already implemented? How about focusing on battery life, startup time, and voice clarity instead, huh? You know, the things that actually matter in a phone, instead of making 3D games, which are cool, but most certainly do not belong on a handheld device.

    1. Re:Well, I don't want any! by Anonymous Coward · · Score: 0

      I'll get 3D off your cellphone just as soon as those kids get off my lawn!

    2. Re:Well, I don't want any! by ceoyoyo · · Score: 2, Interesting

      Go buy one of those phones they advertise on the infomercials for old people.

      I like my handheld computer that happens to also make phone calls, thank you. So do a lot of other people. Besides, you turn your phone off??

    3. Re:Well, I don't want any! by SteevR · · Score: 1

      Some people work at companies that:

      1. Don't allow cell phone use, or allow them only in break areas, and

      2. Have such awful parking lot security that you're not going to leave it in your car.

      As such, its really nice to have a phone that doesn't take a minute to power on/off.

      --
      Performing sanity checks on your own beliefs is vital in avoiding poisoned koolaid.
    4. Re:Well, I don't want any! by ceoyoyo · · Score: 1

      Then buy one. A few paranoid people working for control freak companies who can't wait twenty seconds for their phones to boot once a day really isn't an excuse for crippling the rest of our handheld computers.

    5. Re:Well, I don't want any! by Jesus_666 · · Score: 1

      Seriously, why do you want to buy an iPhone if you just want a mobile telephone? If you want a no-frills mobile phone you buy something like a Nokia 1110i. If you want a semi-frilly mobile with stuff like Bluetooth you might be able to justify dropping 100 bucks on it. But an iPhone is ridiculously expensive if you don't want a smartphone that does everything anyone might ever want or not want.

      I'm not the target demographic for the iPhone but I also don't complain about it. (I do, in fact, complain about it only doing OpenGL ES 1.1 and not 2.0 - if it did I could apply the same knowledge to develop for the iPhone and the Pandora.)

      --
      USE HOT GRITS WITH STATUE OF NATALIE PORTMAN (NAKED AND PETRIFIED)
    6. Re:Well, I don't want any! by SkybuckFlying · · Score: 1

      Interesting that you mention battery life. You realize that doing UI with dedicated circuits takes less power than using generic ALU to compute color for each pixel? The UI is what takes most of the processing power. If we have low-power graphics core in there, we can keep the CPU clocked lower and have total power savings. A smooth UI is not bloatware, it makes the device easier and nicer to use. Initializing OGLES+EGL driver stack takes like 20 ms at most, that nothing. Most of this time is retrieving the driver binaries from storage.

    7. Re:Well, I don't want any! by SteevR · · Score: 1

      Well, if the companies you bought your "handheld computers" from would open up the phone part of the device, we would be assured of being able to disable that component without turning off the device, which would be nice. Also, these devices need to be available in a larger range of options, to help folks deal with all the places they need to take their device (many companies don't allow cameras, personal devices with wifi, SD slots, or things that can act like USB storage). Imho a computer is a customizable device, anything that is sold as "one size fits all" is consumer electronics; ergo I don't buy your handheld computer argument, you can't cripple gimped hardware much further.

      I also might point out that in my case, I'm a contractor who happens to be working an 8 hour per day contract with short break windows during which I can make personal calls (which in my case is calling my personal voice system to find out if I have any critical emails or voicemail from other clients) in a breakroom area.

      My Palm Treo 750 does allow me to simply turn off the network interfaces (wifi, 3g etc.), but that doesn't help with a site policy that doesn't allow camera phones or any personal device that has wifi. Therefore while I'm working my current large contract, I use an old Nokia brick, which for some reason takes 1 minute to power on, and about 30 seconds to power off.

      Thats a significant portion of a 5 minute break, and there is NO reason a device as dumb as that one (no storage outside the SIM) should take that long to boot and find a network.

      --
      Performing sanity checks on your own beliefs is vital in avoiding poisoned koolaid.
    8. Re:Well, I don't want any! by ceoyoyo · · Score: 1

      As I said, go get one of those phones with the big numbers on the display that they market to the senior crowd. No bells, no whistles. Probably starts up in about half a second flat, and requires another 30 or so to register with the network.

      The rest of us LIKE having our large screen phones (I really don't care if you "buy" the description of them as "computers") able to actually USE that screen.

    9. Re:Well, I don't want any! by SteevR · · Score: 1

      Did you miss my statement I own a Palm Treo 750? OK, its no iPhone in terms of screen size, but it is capable of any communications task my desktop is (ssh/telnet, voice, various IM protocols, email, web, etc.). I like using my smartphone, its a neato chunk of consumer electronics.

      While I haven't personally owned a smartphone until recently, that doesn't mean I haven't enjoyed their use- I've been developing custom application software for the things for about 6 years, and at times had 3 or 4 of the things given to me by different employers or through contract work.

      All I was trying to say is that there is a niche for a lightweight mobile phone that can power on and off quickly. I've no doubt that as the market expands in the US, we'll start to see some. In fact, phones that can quickly power on/off, go into a suspend, or can fake being powered off seem to be quite popular with high school and college students overseas, judging by how many I see floating around on the college campus I live next to (which caters to foreign students).

      --
      Performing sanity checks on your own beliefs is vital in avoiding poisoned koolaid.
  12. Open Pandora by InspectorGadget · · Score: 0

    It's probably worth noting that the Open Pandora PowerVR chipset is OpenGL 2.0 ES compliant. Therefore if you want a decent Linux based environment to play OGL ES with, that's the place to start. Except the first batch is sold out. Oh dear.

    1. Re:Open Pandora by hedwards · · Score: 1

      And if those videos are any indication it's going to kick some serious ass. It'll be nice to have another PowerVR accelerated device, I'm still somewhat disappointed that they sold me out on the computer.

  13. Homing in on the right dimensional matrix by HTH+NE1 · · Score: 1

    the latest mobile phones come with 3D hardware acceleration that rivals the power of desktop graphics hardware.

    For superbly rendered phone calls, of course.

    --
    Oh, say does that Star-Spangled Banner entwine / The myrtle of Venus with Bacchus's vine?
  14. Denno Coil? by Maguscrowley · · Score: 1

    Mediocre anime that was themed on this AR being integrated into an urban/suburban infrastructure accessible by equipped glasses. This accompanied by a romanticized "hacking"

    It made me think about AR and read up on the practicalities and limitations. Obviosly the reality and practicalities of AR, or at least the combination of real-world and computer-generated data in real time, fell short. The DSP that this requires is FAR out of the range of modern hand held-devices.

    Also, I can't imagine that it would be feasible to use the same DSP chip that's used for a communication devices necessary functions, to also share the load of AR processing. However, I'm way out of my field here. Expert opinion please?