Posts tagged as:

OpenGL

Some folks have asked me for examples of how my Cheetah3D -> iPhone header converter works. To help you out, I’m posting an Xcode project that I’m using to test the converter.

You can get it here: C3DConverterTest.tgz

This project renders four different shapes generated in Cheetah3D. It’s pretty simple; a lot of the code is from the Xcode’s standard OpenGL ES project template. I’ve added lighting to show that the normals work properly, though.

Some notable files:

  • 4 shapes.jas — the Cheetah3D project
  • 4 shapes.h — the header file exported from Cheetah3D. You can run this through the converter yourself if you like.
  • 4 shapes_iphone.h — the header file made by my converter
  • pure_colors.jpg — A simple texture. Replace this with your own for a different look.

I hope this helps!  Let me know if you have questions or comments.

0 comments

I’ve updated the Cheetah3D -> iPhone header file converter to version 2.0.1.  This version corrects object names from Cheetah3D that aren’t valid in Objective-C.  (Example: “Box.1″ is renamed to “Box_1″).  Thanks to reader Scott for pointing out the problem and a solution.

Download version 2.0.1 here: c3d_to_iphone.pl (zipped)

Please comment or contact me with any feedback!

0 comments

Cheetah3D header file converter for iPhone

by Rob Bajorek on May 9, 2009

[Update 2009/06/04: Version 2.0.1 released.  Bug fix release, see here for more information.]

It’s ready!  The promised Cheetah3D -> iPhone header converter is right here:

c3d_to_iphone_h.pl (zipped)

With this program you can convert exported Cheetah3D OpenGL .h files to an iPhone-compatible format.

Please read the comments at the top of the program file for usage information.  I tested this on Mac OS X 10.5.6, but it should work on any system with Perl 5.  I purposely did not use any external modules (no messing with CPAN here.)

The software is free, licensed under GPL 3.  If you try it, please send feedback or respond in the comments.  Thanks!

9 comments

My Start with OpenGL ES for iPhone

by Rob Bajorek on May 6, 2009

This post is about my start at OpenGL programming on the iPhone.

I have an iPhone project that needs animation.  After considering using 2D vs. 3D objects, OpenGL looked like the best option.  Once I made that decision, I needed to start learning OpenGL. And how did that go? Let’s just say learning OpenGL is a non-trivial exercise.

First stop, the Apple Docs

The natural place to start learning OpenGl for iPhone is Apple. The iPhone Developer site has a lot of information about iPhone programming. In particular, the iPhone Application Programming Guide has a section on OpenGL ES. The information starts with setting up a drawing context and view for OpenGL. There are a number of suggestions, lists of supported features, and comparisons between the simulator and the device. But, it doesn’t really talk about programming in OpenGL. In short, it’s a great list of tips, but it assumes you already know what you’re doing. Surely I’ll come back to this page, but it’s not the place to start.

Apple did include some links, though. That’s where I went next.

OpenGL ES, the standard

I said before that iPhone OpenGL is not the full spec. It’s a special system designed for embedded devices and consoles called OpenGL ES, specifically version 1.1. The keepers of the standard are the Khronos Group.

The main document that I used from Khronos was the OpenGL ES 1.1.12 Full Specification (PDF). This document describes the specification, although the target audience is the OpenGL ES implementor, not the application programmer. Still, I picked up core concepts like matrix modes and building polygons. I couldn’t actually do anything with that knowledge since it didn’t tell me how to build an app.

At this point, I decided to ask Google.

The Red Book

I looked through some forums and tutorials, and the suggestion I tried next was to learn from the “official” guide to OpenGL, AKA the Red Book. By far, the official guide was the best introduction I found to OpenGL. This guide is an actual introduction, teaching you how to program from scratch.

This reminds me of an important point; OpenGL is a C API, not an Objective-C one. No classes or methods here. It’s globals and functions. There’s not much difference, but it may confuse you a bit if you started with Objective-C.

After digging into this book, I started to understand how OpenGL works and I could actually write code! It didn’t translate one-to-one to the iPhone because this is an OpenGL book, not an OpenGL ES one. However, it wasn’t difficult to apply the book to the iPhone. If I did get stuck, someone else did too and I found an answer from Google.

Also, Apple’s OpenGL ES examples made more sense. I started with those and built on them while going through the Red Book.

The Recommendation

I feel comfortable with OpenGL ES now. In fact, I already have a working 3D app integrated with the Bullet Physics library (a topic for another day.) My recommendation if you’re starting from scratch is to use the Red Book and the OpenGL examples from Apple. Play with the example projects until you feel comfortable, then go from there.

2 comments