Posts Tagged 'OpenGL'

OpenGL ES 2.0

So, like us, chances you’re probably aware that the 3GS brought OpenGL ES 2.0 to the iPhone SDK world … but just haven’t got around to sorting out just how different it is from 1.1, aside from the vague impression that the correct magnitude is “very different indeed”. Well, here’s a tutorial at Mobile Orchard to start getting you up to speed:

… They don’t even provide a barebones sample or XCode template to get your started with OpenGL ES 2.0. If you want to take advantage of the new graphics capabilities, apparently it’s up to you to figure out how to use it. Don’t be fooled into thinking that OpenGL ES 2.0 is a minor upgrade over OpenGL ES 1.1 with only a couple new available functions. It’s a whole new beast! The fixed-function pipeline is gone, and it requires you to use shaders and be more familiar with the basics of computer graphics before you can even get a triangle on screen.

Given the total lack of documentation, I set out to create the most barebones app using OpenGL ES 2.0 on the iPhone. Something that could be used as a starting point by other developers in their own apps…

Yes, very thoughtful, indeed. We don’t have anything planned that it makes any sense to make 3GS-dependent in the foreseeable future; but hey, if you’re that hardcore, there you go.

And whilst we’re talking about ‘hardcore’ and ‘OpenGL’ … if you’re really hardcore, have we got a video for you:

In depth analysis of iPhone 2G/3G rendering pipeline – not at the level of OpenGL ES, but looking deeper. Understanding what driver actually does, how communication between CPU and GPU is implemented and what data is sent – can help you not only to write a faster and probably better code for iPhone, but also provides an insight in what happens behind the scenes with modern GPUs.

Yeah, we’re more the “ooh, shiny!” level on that stuff. But if GPU-level minutiae get your geek on — there you go!

Continue Reading →

Snippet: Texture Sizes

Here’s a cute little snippet for automatically transmogrifying your OpenGL textures into iPhone-acceptable dimensions at runtime if you don’t want to go to the trouble of sorting out the source assets, because maybe you’re porting existing assets from another platform, or your artists can’t follow directions, or whatever:

First off, figure out power-of-two dimensions:

  1. //     Adjust the width and height to be a power of two
  2. if( (_width != 1) && (_width & (_width – 1)) )
  3. {
  4. i = 1;
  5. while((sizeToFit ? 2 * i : i) < _width)
  6. i *= 2;
  7. _width = i;
  8. }
  9. if( (_height != 1) && (_height & (_height – 1)) )
  10. {
  11. i = 1;
  12. while((sizeToFit ? 2 * i : i) < _height)
  13. i *= 2;
  14. _height = i;
  15. }

You could figure that out on your own no doubt, but you might miss this; if it turns out that the image is too big, your friend CGAffineTransform can sort that out for you!

  1. //      scale down an image greater than the max texture size
  2. while((_width > kMaxTextureSize) || (_height > kMaxTextureSize))
  3. {
  4. _width /= 2;
  5. _height /= 2;
  6. transform = CGAffineTransformScale(transform, 0.5, 0.5);
  7. imageSize.x *= 0.5;
  8. imageSize.y *= 0.5;
  9. }

That’s quicker than going through and canonizing a large asset base yourself, indeed. Read the rest of the article for further explanation; and this is part of the D’Jinn Engine for the iPhone which can be found on Google Code. Enjoy!

h/t: iPhoneDevelopmentBits!

Continue Reading →

Library: Oolong Engine

Here’s an open source 3D library that we haven’t mentioned before: the Oolong Game Engine. It appears to take notable advantage of the PowerVR SDK, and provides a comprehensive feature list:

  • OpenGL ES 1.1 support
  • Math library that supports floating-point calculations with an interface very similar to the D3D math library
  • Support for numerous texture formats including the PowerVR 2-bit, 4-bit and normal map compression formats
  • Support for PowerVR’s POD (Scene and Meshes) and the 3DS files formats
  • Touch screen support
  • Accelerometer support
  • Text rendering to support a basic UI
  • Timing: several functions that can replace rdstc, QueryPerformance etc.
  • Profiler: industry proven in-game profiler
  • Resources streaming system
  • Bullet SDK support (for 3D Physics)
  • Audio engine with OpenAL support
  • Networking with the ENet library
  • Industry proven memory manager from
  • Code is up at Google Code and under the permissive MIT license, so that should definitely be on your short list of options to check out for your next 3D iPhone game!

    Continue Reading →

    OpenGL ES + CATransform3D

    Well, here’s a followup to yesterday’s post on CATransform3D: The fellow who wrote the 3D molecular visualizer Molecules that we mentioned back when it was open sourced decided to apply that work to Molecules’ rendering routines, and it worked out pretty well!

    It turns out that the CATransform3D struct provided by Core Animation for doing manipulation of CALayers is identical in structure to the model view matrix in OpenGL (ES). In fact, Apple has provided us with a number of functions for manipulating this CATransform3D struct in ways that correspond to glRotate, glScale, and glTranslate calls.

    This solves the biggest known problem I had with Molecules’ rendering routines: for me to do rotation and translation relative to the user’s touch input, I had to know the state of the model view matrix at all times. In the current version of the program, that means that I had to use a few glGetFloatv calls to query the current state of the model view matrix. Each of these calls halted the rendering pipeline, so I needed a way to get rid of them.

    CATransform3D and its supporting functions provide the means to do that. I could keep track of the current model view matrix in a CATransform3D, perform manipulations on that structure, and just replace the OpenGL model view matrix with it every time there was a change…

    …this quick set of optimizations leads to an increase of 14-25% (depending on the specific model) in the number of triangles per second that Molecules was able to push through the iPhone’s GPU. This means that on the iPhone 2.2 firmware, I’m now getting a max of 310,000 triangles per second. This is still short of the 470,000 triangles per second the iPhone is capable of under these conditions, as reported elsewhere. There’s still some room to improve, but I’m getting there.

    So there you go. If you’ve got any complicated OpenGL transformations to keep track of, look into CoreAnimation!

    h/t: iPhoneKicks!

    Continue Reading →

    OpenGL roundup

    Here’s a blog chock full of meaty programming goodness we hadn’t stumbled over before: iPhone Development. The particular post we found a reference to was a collection of OpenGL articles from December,

    These past three days have seen a flurry of postings. I thought I’d just do a quick table of contents to the various tutorials and postings I’ve done recently, in the order they should be read:

    but there’s been a good bit of updates since then. Catch them all by looking for the OpenGL ES tag, or if you’d like a bit of a refresher the OpenGL From the Ground Up series, but we’ll draw your attention particularly to this post providing an updated version of the Xcode template post above:

    Here is a new version of my OpenGL ES project template for Xcode. This version adds a class called “OpenGLCommon.h”, which contains data structures and inline functions for vertices, vectors, triangles, etc. – mostly stuff from the Wavefront OBJ class that has generic applicability, backported into the template.

    h/t: iPhoneKicks!


    And here’s another good OpenGL ES article at Dr. Dobbs written by the author of The OpenGL SuperBible, which if you don’t have we recommend you buy immediately.

    Another roundup post with some new links — and the blog it’s from has lots more OpenGL stuff!

    And here’s a very good iPhone focused series of OpenGL tutorials — up to #4 on 09.05.15!

    That no glBegin()/glEnd() bit got you stumped? Read OpenGL Vertex Buffer Objects (VBOs): A Simple Tutorial!

    Continue Reading →

    Multiple OpenGL UIViews

    Here’s a tip you definitely need to give a read if you’re of the common opinion that OpenGL is only appropriate for fullscreen applications like games: how to not only integrate OpenGL views with UIKit nicely, but use multiple OpenGL views!

    Things get more complicated when you want to have multiple views with OpenGL rendering. I don’t mean multiple viewports in the same screen, but multiple views in the sense of multiple UIViews. My current project, for example, has different views connected with a UITabBarController. Some of the are custom UIViews and some of them are OpenGL views.

    My first thought was to try to have different OpenGL contexts for each view, but that would complicate things because I wanted to share the same textures and other resources. I know there’s a shared groups option, but that was definitely not the way to go.

    The best solution I found was to use multiple frame buffers, binding each of them to the correct OpenGL view. That way, when I switch views, I switch frame buffers and everything works correctly.

    Simple once you know how, isn’t it?

    h/t: iPhoneKicks!

    Continue Reading →

    Molecules open sourced!

    Here’s some good news for anyone wanting a leg up on OpenGL for the iPhone: Brad Larson, the developer of Molecules a 3D molecular visualizer available on the App Store, has now open sourced the entire project:

    With the lifting of the Nondisclosure Agreement on the iPhone SDK, I’m pleased to finally make available the source code to Molecules. If you go to the main page for the application, you should now find a link to download the latest source tarball (for version 1.2) on the right-hand side. You can also download the source code here. I am working on migrating my personal Subversion setup so that you can check out the latest code and so that I can authorize contributors to commit fixes and additions.

    Unfortunately, I haven’t documented the current code release as well as I would like. To make up for that, I’ll attempt to describe the structure of the application and why I do things the way I do. I don’t claim that everything here is optimal, but I hope that it can be a useful resource for those interested in OpenGL ES, SQLite, multitouch, and table views on the iPhone.

    All code is released under the BSD license, so you are free to cut and paste it into your own applications without restriction…

    Sweet! Also, don’t miss Messr. Larson’s earlier blogging about OpenGL ES for non-NDA-covered lessons learned in connection with Molecules’ development. Lot of great info there too.

    h/t: MacResearch!

    Continue Reading →