OpenGL on iPad: How to Handle Arbitrary Device Orientation.

Since there is no preferred device orientation for iPad, OpenGL rendering on the device must handle that. I have added arbitrary device orientation to my HelloiPadGLSL code to demonstrate how to handle that. It turns out to be relatively easy if you think in terms of the MVC design pattern Apple has established and implement the proper methods in your Controller and View. I include liberal doses of NSLog-ing to stare at for your pleasure:

On GitHub: http://github.com/turner/HelloiPadGLSL


Enjoy,

Doug

twitter: @dugla

3D Graphics on iPad is all about GLSL. Huh? Read on.

To fully exploit the graphics potential of iPad you need to get comfortable with the OpenGL shading language. Cool kids call it GLSL. Think Pixar RenderMan shading language in realtime. As I mentioned in a previous post on this blog and in my meetup presentations to iPhone devs, this will take your visuals (both 3D and 2D) to an entirely new level in terms of visual complexity, realism, and sheer visual expressive horsepower.

In acronymn land iPad takes us from OpenGL ES1 - the version of OpenGL running on iPod Touch and iPhones - to OpenGL ES2. Note, iPhone 3Gs actually supports OpenGL ES2 as well.

The expressive power of GLSL comes at a price. It raises the degree of difficulty significantly and is not for the faint of heart. To help ease your transition from pre iPad OpenGL I have written HelloiPadGLSL. On GitHub here: http://github.com/turner/HelloiPadGLSL. If your team is interested in unlocking the expressive beast that is GLSL you will want to get comfortable with this code.

I am also available to work with and/or train your iPad development team to get the most out of 3D graphics on iPad.

Cheers,
Doug
twitter: @dugla

NYC iPhone Meetup Talk. 3D Graphics for iPhone Developers. Presentation and Source Code

Thanks to all the NYC iPhone devs and enthusiasts that attended my talk.

Presentation deck on SlideShare:
http://bit.ly/Y1MW8


Sample code referred to in the slides is available on GitHub:
http://github.com/turner/HelloTexture
http://github.com/turner/HelloTeapot


Tweets related to this talk us hashtag: #iphone3dnycmu


Regards,
Doug Turner
I tweet as: @dugla
Email me: douglass dot turner at gmail dot com

OpenGL != Computer Graphics

Relax. My point is that OpenGL is not a particularly insightful way - a rather unpleasant way actually -  to learn about one the most enjoyable, creative, and deeply satisfying software development fields you will find. OpenGL is a specification. OpenGL is a state machine manipulation language. Coming from Mac/iPhone and the warm, and supportive embrace of Cocoa/CocoaTouch, OpenGL will seem like a rude awakening indeed.

A good coping strategy is to read all the RenderMan books, papers, and DVDs you can get your hands on. RenderMan was invented at Pixar and is the development language used for all their films.

Pixar/RenderMan is the gold standard for CG. There is Pixar and there is everyone else. Period.

Baked into RenderMan is a very specific methodology about how to approach the task of making delicious pixels. There is a reason Cars looks so ridiculously georgous when played on a Blu-Ray disc and displayed on a 52" flatscreen display. The reason is RenderMan.

It is best to think of OpenGL as your deployment language, sort of like assembly language. It's not particularly deep, you won't learn a hell of a lot about computer graphics pouring over example code, but its what we have to work with.

Here is an excellent RenderMan paper to get you started: http://bit.ly/VkYwU

 

 

 

Jeff LaMarche - Your Starting Point for iPhone/OpenGL Enlightenment

Easily the most comfortable place to begin your journey towards OpenGL for iPhone enlightenment is Jeff LaMarche's OpenGL From the Ground Up series of tutorials http://bit.ly/2ONFBJ. Jeff is a pro. He is smart and generous. This series is loaded with very approachable information, sample XCode projects and supporting 3D library code - texture and matrix - that will significantly accelerate your learning.

Jeff is author of the highly regarded Beginning iPhone 3 Development: Exploring the iPhone SDK http://bit.ly/1BfUSv

3D Graphics Lighting Tutorials From the Master - Jeremy Birn

Jeremy Birn is perhaps the most lucid, most thorough, and most talented writer on CG lighting that you will come across. Here are two particulary insightful tutorials that reveal how the pros light their scenes. While not directly applicably to iPhone/3D, these are a gold mine for interesting visual f/x hacks to integrate into your apps:


His CG Lighting Book is the best I've come across and probably the only one you will need: http://bit.ly/2a9Kj5

RenderMan Procedural Surfaces

One of the challenges learning OpenGL on iPhone is the scarcity of 3D models, and model importers from the standard modeling tools such as Blender, 3DS Max, and Maya. An alternative is to use procedural surfaces. My personal favorite procedural surfaces are the RenderMan quadric surfaces. They are simple and have extremely flexible and clever u-v parametrizations that allow moderately complex shapes to be built by combining them. Importantly, they texture map nicely: http://bit.ly/3coAGa

A 3D rendering system and shading language I built implements the standard RenderMan surfaces in C++. Feel free to use that code as a starting point for your own implementation. It is available on GitHub here: http://bit.ly/1Zi4OM

Refer to the Parametric Surface class:
http://github.com/turner/theimageengine-render/blob/master/ParametricSurface.h
http://github.com/turner/theimageengine-render/blob/master/ParametricSurface.C

 

 

OpenGL Matrix Notes

Rotation about z axis by 30 degrees with a fixed point of (1.0, 2.0, 3.0). Note matrices are pushed on the stack as we declare them so the last matrix declared is the first applied:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(1.0, 2.0, 3.0);
glRotatef(30.0, 0.0, 0.0, 1.0);
glTranslatef(-1.0, -2.0, -3.0);

Here, we load and multiply by matrices explicitly defined elsewhere in the application program:

glLoadMatrixf(m)
glMultMatrixf(m)

Matrix m is a one dimension array of 16 elements representing the components of s 4 x 4 matrix stored in column-major order. Here, we read back a matrix from the GPU:

double m[16];
glGetDoublev(GL_MODELVIEW, m);

Vertices are pre-multiplied by the transformation matrix following the format in Richard Paul's Robot Manipulators >>.

Refer to this excellent presentation of OpenGL local, object, and eye space >>