Tuesday, December 30, 2008

Updated OpenGL ES Xcode Project Template

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.

As before, to use this, unzip the archive and then drag the resulting folder to the following location (you may need administrator privileges to do this):
/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application/




35 comments:

Eric Busch said...

Perfect, thanks again!!!

nom_sans_interet said...

Thanks, good work.
I'm working on VBO's currently, but reverted to vertex arrays to try textures. I'm stuck with the same problem as you had, my texture is correctly shown only on the front and back faces of the cube. Worse, if i only leave the coordinates for these faces, the wrong ones still show up.

Can you tell us how you fixe this?

Jeff LaMarche said...

nom_sans_internet:

I think this posting: http://iphonedevelopment.blogspot.com/2008/12/texture-coordinate-arrays-or-things.html

will explain the problem you're having. Open GL uses on set of texture coordinates per vertex, but if you have one vertex that has different texture coordinates in different polygons, then you have to duplicate the vertices, which can get a bit gnarley - my Wavefront OBJ loader has code to look through vertex and texture indices for all the distinct pairs. it's fun stuff...

nom_sans_interet said...

Thanks for the answer.
Actually i read the post you mentionned. I got back to my VBO way, and managed to get the same incorrectly textured cube.

I tried to take each triangle , vertex by vertex, and find (with paper and pen) which texture indices to use, but the ones that seem logical to me does not work at all. And if i put "random" numbers, i get sometimes better results, don't know why. I can't figure out the logic behind all this.

I'm still working with VBOs so i don't have repeated vertices coordinates, and i have one VBO for texture coordinates also. What you say is i should duplicate all vertices appearing in more than one triangle (all of them actually). Even if the VBO is stored in the hardare, it seems sad and inefficient to me to have to repeat all this information. What will it be for complex geometry??

Ok i'll try to duplicate anyway, and change my indices and texture coordinates accordingly. Hope it'll help.

Btw, thanks for sharing your investigations with us all, it helps a lot !

Jeff LaMarche said...

nom_sans_interet

Unfortunately, I haven't gotten to working with VBOs yet, so I can't really offer much more than I have. I'm still having problems myself with UV mapped textures.

nom_sans_interet said...

Just an update to say that it's working now. I'm not satisfied completely because i don't like the repeating of some vertices definitions. But i must admit you were right, it's working perfectly. Once we define our vertices (4 for each of the faces, hence 24 vertices instead of just 8), the index buffer and texture coordinates buffer are easy to setup and give a nicely textured cube.

I'm going to work on lights now, to have a break with this subject, but i'd like to know if you have information about a way to use an optimized vertex buffer (8 vertices total) for the same textured cube.

If you want that i send you my code for a textured cube with vbos, you can write to me : esnault (dot) frederic (at) gmail (dot) com

And i must add thank you, your advice helped me, it's working now, even i'd like a more efficient solution, and a happy new year !

nom_sans_interet said...

Me again, i just read the answer from someone in the iphone dev program forum answering me and saying that a vertex is actually the composition of position, texture coordinates and normal, etc... If any of these info is different then a new vertex is needed. He added that there is no way to share a position with two texture coordinates, explaining why it didn't work. So, to conlude, he said that this redefinition usually occurs on very simple geometry like cubes, and that we end up with a total of 24 (i figured this part by myself ;) ) vertices for a whole cube, which is not a worry.

So my code should be quite efficient, basically now, i'm more satisfied and i learned something tonight !

matthew said...

This is great and your book is awesome too. My question is is there an easy way to import 3ds max files into opengl es for the iphone?

Matthew Chung said...

Hey Jeff,

I love the template however when I load it onto a phone, it loads as the GLGravity app. When I change the products\app name, it gives me cfbundle errors. Do you know how to fix this?

Vaempuli said...

Hi, can you post a version of the template compatible with SDK 3.0? If not please suggest the modifications to be made.

kimptoc said...

Probably everyone knows this , but you could also save it as a user template, in this location:

~/Library/Application Support/Developer/Shared/Xcode/Project Templates/Application

Hopefully it will survive Xcode upgrades then :)

It then appears under "User Templates"

HTH,
Chris

reyt said...

There are wow gold 3 men in a plane. wow gold A priest, a baseball player world of warcraft power leveling and a soldier. the pilot goes into dog clothes the cabin and 2moons gold tells them that there Atlantica gold is a weight overload 2moons power leveling on the plane and they would each have to throw world of warcraft gold one personalworld of warcraft power leveling belonging out aoc power leveling the window to safely land. Power Leveling the priest throws flyff money out a bible and says,"forgive me lord, i will last chaos gold get another one.archlord power leveling The baseball player world of warcraft gold throws a baseball out and says, aoc gold "i play professional baseball, i can get thesearchlord gold whenever i want." Now

Mariano Abdala said...

Hi Jeff!

A really nice article! Thanks...

I added a "fps UILabel" to GLView on the template you wrote, it gets created automatically and it's really easy to turn off, besides you can chose to show fps frame by frame or an average. I just wanted to share what I've done, it's here:

http://zerously.com/Empty%20OpenGL%20ES%20Application.zip

I hope you, and the readers find it useful or at least nice!!!

By the way, maybe it's my mistake but I keep seeing that the avg FPS is 60, when the kRenderingFrequency is set to 30. Would you check it out?


Thanks again for this article and Beginning iPhone Development!!

Sara Reid said...

In the last installment we spent a lot of time going into the drawView method. We learned how OpenGL ES uses various matrices to control how things are drawn as well as the things that are drawn.

carte sd 2gb

Dave Viner said...

This is a great compliment to the OpenGL Project that ships with the default Xcode.

One question tho. How is the OpenGLTexture3D class different from Apple's default Texture2D class? Both appear to wrap the complexity of loading an image into an OpenGL texture and then draw that texture.

I'm sure there's a reason to use one or the other. I just can't discern what the distinctions might be.

Kaspar said...

Hey !
thank you for this template !
Is it possible to make an Update for iPhone+iPad?

thanx a lot !!

boroughs said...

Thanks for the template, however I have one question.
When I try and compile even just the basic triangle example for iPad (OS 3.2) using the template the triangle, which is now centred around the origin point (0, 0), is rendered in the lower right hand corner of the screen rather than the centre.
Is there a way I can sort this so that the origin point is back in the centre of the screen when I compile for iPad?

thanks again

shashank said...

Looks like a life-saver tutorial , but when I try to run the template project in the iphone sdk 3.0 and above , I just see a black screen on the simulator and nothing else. Any pointers why this is happening ? Thanks

mrcalonso said...
This comment has been removed by the author.
mrcalonso said...

I can't download the template as the innerloop.biz server looks unreachable. Please solve this or upload to another server!!

allisone said...

Thanks for your tutorials and this template.
Still I have big problems with one thing...

Switching/Overlaying/Blending GLViews
How do you do that?
I even can't manage to get the default glview switched with another default view.
it tells me "failed to make complete framebuffer object 8cd6" when loading the second view

Can you provide a tutorial where you show us how to have a second view on top of a first one and blending away the top one, so that the lower one get's revealed... or similar ?

Edwin said...

scrub m65 kamagra attorney lawyer body scrub field jacket lovegra marijuana attorney injury lawyer

richard said...

i wanted to use c++ so i changed glviewcontroller from .m to .mm and included my own .h file with a class declaration. its causing build errors, something about .../OpenGLCommon.h:210: error: invalid conversion from 'void*' to 'VertexTextureIndex*'

any ideas how i can solve this? id rather use this template as the one that comes with xcode leaves in support for multiple frame buffers and shaders, things im not going to use.

alkeno said...

@mrcalonso Spanish? Using Telefónica? I'm Spanish and I can't reach innerloop as well. Use an http proxy to solve that issue (http://www.go2s.info/ for example).

Hope it helps.

mrcalonso said...

@alkeno. Muchas gracias!! Ya era hora de que alguien contestara. Si, soy español y usando telefónica. Ya había perdido la esperanza de poder seguir los tutoriales. Gracias otra vez!!

Ubaldo said...

Thanks a lot!!

I'm working with Xcode 3.1.4 and the new template/ When I try to build a new project I get :
"MainWindow-iPad.xib" could not be handled because ibtool cannot open files of this type.

Help Please

h4ns said...

What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say. Im sure youll reach so many people with what youve got to say.

Arsenal vs Huddersfield Town live streaming
Arsenal vs Huddersfield Town live streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Notts County vs Manchester City Live Streaming
Notts County vs Manchester City Live Streaming
Bologna vs AS Roma Live Streaming
Bologna vs AS Roma Live Streaming
Juventus vs Udinese Live Streaming
Juventus vs Udinese Live Streaming
Napoli vs Sampdoria Live Streaming
Napoli vs Sampdoria Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
AS Monaco vs Marseille Live Streaming
AS Monaco vs Marseille Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Technology News | News Today | Live Streaming TV Channels

jmerk said...

Does this need to get updated again?

David said...

Where should i put this in Xcode 4.0. It doesnt work with the same folder.

reza.f said...

I have the same issue as David, I can not get it to work with xcode 4, and looking around it seems that the template setup for xcode 4 is quite a bit more complicated. Can anyone help here.
Thanks

manifest said...
This comment has been removed by the author.
manifest said...

@David, @reza.f, you can read "A minimal project template for Xcode 4" article to learn how to build custom template for iOS.

And you can use the SDL iOS template for Xcode 4, just remove SDL.framework reference from it.

max46145 said...

Hey everyone, I have copied the folder from Jeff's link (/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application/) to the directly he mentions in this post, but somehow it is still not showing up in my list of templates when I create a new project in xcode. I see that kimptoc recommends putting these files in another directory where they won't be overridden (~/Library/Application Support/Developer/Shared/Xcode/Project Templates/Application). That directory did not previously exist, so I created it and put the folder there as well, and still nothing. I am new to the iOS world (from .NET), so I might be missing something really obvious. Any help would be SUPER appreciated. I've spent a couple hours on this already and I can't wait to get to the meat of these blog posts. Thanks

max46145 said...

Turns out my problem was that I was using the old template, which will not work on XCode 4. If you are also stuck, the new template is at:

http://iphonedevelopment.blogspot.com/2011/05/empty-opengl-es-application-xcode-4.html

and I put that folder in the:
~/Library/Developer/XCode/Templates folder

Jimmy said...

Thank you so much for making these tutorials