iPhone Game Programming – Tutorial 1

OK, so I have finally managed to get my first video tutorial done for writing a game on the iPhone.

This Tutorial will cover the basics of taking an OpenGL ES Application template available in Xcode and making the changes necessary so that we can use it for writing out game. The game I am going to be creating is a 2D game to keep things simple as I’m still learning myself :o)

I have found some very using sites for learning OpenGL on the internet. Its important to remember that the iPhone use OpenGL ES which is different to normal OpenGL. For our needs it should not present a problem, but it something you need to be aware of. I’ll be mentioning in the Tutorials where I come across the differences.

A couple of sites I have found useful are:

NeHe Productions

OpenGL ES 1.1 Ref Page

I am sure there are many other sites out there that can help as well.

The basis for my learning to write a game on the iPhone so far is the CrashLanding exmples provided by Apple. This is something I refer to in the video and also something we will be taking some classes from so its worth having it to hand. It should have been included with the SDK or can be downloade from the iPhone portal.

I hope you enjoy this first Tutorial. It is my first so forgive any mistakes or poor style. I hope it will improve over time. Please post any questions or comments you may have.

Play Tutorial 1

Tutorial 1 Project

Mike

Discuss in our community forum.

Share:
  • Digg
  • del.icio.us
  • Facebook
  • MySpace
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis
  • Design Float
  • DZone
  • email
  • Google Bookmarks
  • LinkedIn
  • Scoopeo
  • Tumblr

130 Comments

dinesh  on March 4th, 2009

Mike excellent screencast.

Seems like Apple stopped giving the CrashLanding source code. If can please post it to some repo so that I can download and use it.

Thanks for the great tutorial have a great day

Dinesh

Joe  on March 4th, 2009

Hello Mike,

I really enjoyed following your tutorial. Keep up the great work.

Cheers,
Joe

mike  on March 4th, 2009

Hi guys

Thanks for your comments. It’s great to hear you found this useful :o) it encourages me to get the tutorial I’m working on now finished quickly and posted.

Dinesh, I have been looking around and Apple do seem to have taken CrashLanding from their site. It would seem it was not doing things in the most effecient way and rather than change it all have pulled it.

The items I am using for these tutorials still seem to be a good choice for people beginning game programming, such as myself so I’ll continue using them.

If you need to download the CrashLanding code it can be found at http://www.71squared.co.uk/iPhone/CrashLanding.zip

More soon

Mike

Dinesh  on March 5th, 2009

@Mike
Thanks a lot for the crashlanding source. I am a newbie learning opengles so will be hacking a lot in the coming days.

If you are struck in any of your work do post it here I will surely help If I know about your issue.

you have a great day

mike  on March 5th, 2009

Thanks Dinesh, I will certainly post any problems I have :o)

The next tutorial is going to cover getting the ship to move, so will be a short one and I’ll follow that up with a third tutorial which will cover creating an Image class which will wrap the Texture2D class and provide rotation, scaling and color filters. Its coming along ok at the moment, so stay tuned :o)

Mike

alvinlai  on March 8th, 2009

Good stuff!
I learnt lots from your tutorial, keep up the good work man! :)

Eskema  on March 8th, 2009

Excellent tutorial, i made some games in sdl, now im trying opengl, but im stuck with textures, is any way to clip the textures and draw only the clip you want?, all 2d games have their images in one tilesheet, im looking for a way to clip only a specific area, and not draw the entire tilesheet.
Is there any function in opengl to do that?

mike  on March 8th, 2009

Hi Eskema

Thanks for your comment on the tutorial.

SpriteSheets is a topic I’m going to be covering within the tutorials. I’m currently finishing off writing all the classes needed to be able to start the game and I’m then going to create a tutorial which goes through how I have created them and how they work.

The next Tutorial will be about adding an Image class. This will wrap around the Texture2D class and provide a method which will allow you to draw just a subSection of an image. It will also let you scale and rotate the image as well.

Once that is in place you can then wrap that class with a SpriteSheet class which will allow you to define a width and height for the tiles in your sprites heet and then draw the one you want just by passing in an X and Y tile coordinate.

There is no specific OpenGL commands for this, its just really providing texture coordinates from the texture and then when you draw a shape OpenGL maps the texture coordinates you provided to your shape, scaling up and down as necessary.

I hope that makes some sense and I should have the Image tutorial up soon.

Thanks

Mike

Eskema  on March 9th, 2009

Awesome!! Mike, i’ll be waiting for your next tutorial, its just what im looking for :)

John  on March 9th, 2009

Nice work mate! Keep the tutorials coming, can’t wait for the SpriteSheet one, especially after what you showed me today :p

Jeonghyun  on March 16th, 2009

Wow!
Excellent tutorial!
I’ve been looking for a tutorial like this but all I got were links to icodeblog which does everything the easy way and no OpenGL ES, something I would prefer to use.

I saw a video on youtube of a game in progress using the Crash Landing and heard there would be a tutorial on how he did what he did.
I FOUND IT!

Anyway, your tutorial is by far the best.

Can’t wait for the second tutorial!

Joe  on March 18th, 2009

Great presentation, however, a lot of your information was just plain wrong unfortunately. I was intending to help by setting a few things straight, but my list was getting a little long.

I will say a few things: Check out the OpenGL ES spec on framebuffers and renderbuffers. Your explanation isn’t correct.

It is typically considered bad practice to implement OpenGL ES commands in initWithCoder:. There are a variety of reasons and as you dive deeper in to OpenGL ES, you will start to see why (especially enabling client states).

When adding a framework, it is much simpler (and it will always link the proper version of the framework!) by selecting Get Info on your Target, going to the General Tab, and adding a Framework there.

“Video memory” doesn’t truly exist on the iPhone yet. Binding a texture does not “load it in the memory”, calling glTexImage2D does.

While deallocating your Texture2D, you correctly explained that it will never happen in this application, but it is good practice. However, you add that line after you set your current EAGLContext to nil. Because the EAGLContext is nil, the call to glDeleteTexture() within the dealloc method of Texture2D will be invalid.

Hopefully these can be corrected so that iPhone Developers don’t find themselves in a corner. Otherwise, great style and very helpful to those beginning OpenGL on the iPhone.

Dan  on March 19th, 2009

Mike I just had to tell you how great of a tutorial that was. I only wish I had come across this site earlier. I really look forward to seeing what is to come. Thans again for taking the time to put this together!

powpow  on March 19th, 2009

Great tutorial Mike, when do you think the second one will be ready? :D

Anonymous  on March 19th, 2009

Thanks guys, your comments are much appreciated.

@Joe, great feedback. I’m learning all the time with this stuff and the risk is that I will get some stuff wrong and it gets shared with others as I’m sharing as I learn. Having someone spot mistakes and provide feedback is great and will help both me and others.

I’m going to work through your comments and make sure that corrections are made to my code and I’ll cover the changes in future tutorials so that I can make sure the record is set correctly on those items :)

If you have any information or somewhere you can point me in terms of setting client states in initWithCoder and why that is a problem I’d be interested to check it out and make the necessary corrections. I have already made some changes in this area I cover in my second tutorial, but I do have a state enabled in the initWithCoder still so I’d like to fix that if necessary.

For those who are awaiting the second tutorial its currently uploading to the website as I type and should be available in the next couple of hours. Its a long one coming in at around 1.5 hours so I hope its not too long and you find it useful.

As always, if anyone spots any errors, mistakes or has comments please let us know.

Thanks

Mike

Joe  on March 19th, 2009

Mike,

You have four client states – vertex, color, texture coord and normal coord. In a game, you will be drawing lots of objects. Not all of these objects will use all of these client states. For example, you might have an object that is using per-vertex coloring to modulate its texture. You would then enable color arrays… but later on, when you draw another object, color arrays would be on and the buffer sizes would not match. This would immediately crash and give you very little information as to why. You should always keep vertex arrays on (how else are you going to draw? :), but turn texture, color and normal arrays on and off as necessary to prevent that.

As far as setting the projection matrix in initWithCoder:, sometimes that projection matrix needs to change. You can implement zooming by using the projection matrix, you can overlay a 2D interface on top of a 3D world by using the projection matrix and I’m sure there are a few other things out there. It’s a lightweight call, you can certainly do it every frame and be okay.

And finally, it is more of a “style” thing. Experienced OpenGL/Cocoa developers aren’t going to look inside an init method for OpenGL calls. They are going to have all of their OpenGL calls in another object’s method or perhaps in a C function that only makes OpenGL calls and is portable to other platforms.

Hope this helps.

mike  on March 19th, 2009

@Joe, that does help a lot.

I have made some of those changes already based on stuff I’ve been reading and these changes are in the second Tutorial which will be available in a few minutes. The only state still enabled in initWithCoder is the Vertex Array and then also the projection matrix stuff.

Based on what you have said, where would you normally see the Vertex Array getting set if its going to be left on?

Also, with setting the Projection Matrix, what would you include in that i.e. would you also have the glOrthof and glViewPort set for every frame?

I’ve also started to enable and disable blending for each object drawn as I’ve read leaving blending on can reduce performance but I only set the glBlenFunc once at the moment in initWithCoder. Is this something else which should be set for each object being drawn?

Your input is really useful and I want to make sure I’m doing stuff as well as I can given when I’m learning :)

Thanks again for the feedback

Mike

Joe  on March 19th, 2009

Glad to help.

Typically, you set up the projection matrix and turn on vertex arrays every frame. Now, if you know those are never going to change, you can wrap those in an if statement at the top of your rendering method: if(!glInitialized) {do things once; glInitialized = YES; }

My usual approach is having a UIView subclass with a backing CAEAGLLayer (that is, a OpenGL view like EAGLView in Apple’s sample code). That subclass has a delegate, whose only method is – (void)renderContent:(EAGLView *)renderingView;

Inside the drawView method, or whatever you choose to name it, you set your context to current, bind the frame buffer, set the viewport, then hand off your drawing to the delegate object via renderContent:. At the end of your drawView method, you can then bind the renderbuffer and present it.

This is a clean and reusable way of having a OpenGL View. You write it once, and then you never have to worry about it again. You simply give it a delegate object that is responsible for setting up the projection and drawing. You can use the same EAGLView object to do multiple rendering tasks for one application, and you can reuse that subclass in any other application.

A note on the frame and render buffers: the currently bound frame buffer receives drawing commands. It uses those drawing commands to produce an image, that image is written to it’s color attachments: your renderbuffer. So the framebuffer is really just a processing plant, and its products are renderbuffers (which are really just images), and those renderbuffers share their data store with your CAEAGLLayer. When your context is presented a renderbuffer, the currently bound renderbuffer is than presented to the screen through that CAEAGLLayer.

mike  on March 20th, 2009

Thanks @Joe, that is really helpful and certainly clears a lot up for me from what I’d been reading on the internet. I’ve made changes to my code which I’ll go over in the next tutorial which will hopefully remove the issues you have raised. It would actually be cool if you could have a look at the code before I post the code changes on the blog. If your happy to send me an email I could send the project over to you and get your comments.

Your comments on the frame and render buffers plus some more reading I’ve done since your post makes it clear where I was going wrong :) and what I had not picked up from other sources I’ve been reading so thanks for that and its something I’ll go over again in a tutorial.

The feedback has been great and I know I’ve learnt from it and I’m sure the others reading this blog will have done also.

Cheers

Mike

Joe  on March 20th, 2009

Sure, although can’t seem to find your e-mail address on the page. You can construct mine by using joe@name_of_the_company_I_work_for.com

That company name is in the link I pasted to the discussion on UITableViewCells… minus the “weblog” part, of course :)

Mitur Binesderti  on March 31st, 2009

Hey thanks for the tutorials!

Strangely enough I’m trying to watch this ON my iPhone but iTunes says the iPhone can’t play that type of file. Am I just really, really dumb, as is often the case, or is it really true that a ScreenCast recorded on a Mac about programming the iPhone won’t actually play on an iPhone?

I know I can just convert it but it seems more likely I’m just doing something wrong.

mike  on April 1st, 2009

Hi Mitur

You are not being dumb at all. The screen casts are MOV files and have been recorded at a high resolution. For this reason they will not play on the iPhone without being converted. The problem you may find is reducing something which is around 800×500 down to smaller in that you wont be able to see the code :o)

Mike

Mitur Binesderti  on April 1st, 2009

Ahhhh, thanks. That makes total sense. I often just listen to the videos when I’m doing some boring thing like riding the bus or sitting in a company-wide meeting.

It wouldn’t make sense, like you said, to make them so small you can’t even see what’s going on. I’ll still make little videos though ’cause I do like ‘em.

Thanks again for the great videos. I’m learning a great deal!

Sion  on April 14th, 2009

Thank you very much, please keep releasing these tutorials. You run them at just the right pace.

Thanks again.

permadi.com - Blog » iPhone Game Programming  on April 25th, 2009

[...] Mike at 712 has a video tutorial on creating games using OpenGL ES.  http://www.71squared.co.uk/200.....utorial-1/ [...]

handsome  on April 26th, 2009

this is great thank you so much!

Greg  on May 2nd, 2009

This is brilliant!! I’ve just started Mac/Cocoa programming – just finished a couple books on Objective-C and XCode and I was looking for exactly this – info on programming games! I going to go watch the next tutorial right now!

Anonymous  on May 6th, 2009

No souce code to download?

mike  on May 6th, 2009

Not sure what happened there, anyway, I’ve added a link to the source code for Tutorial 1 which you will find just below the Tutorial link.

Mike

Anonymous  on May 6th, 2009

Thank you!

RoberRM  on May 9th, 2009

Thank you very much, Mike!
You are the first one I’ve seen that not only makes freely available such great tutorials, teaching us how to code games, but also takes time to EXPLAIN why you do the things you do and why you didn’t chose other possibilities. THANK YOU very much! :D
Please, continue creating this great tutorials, because I’m learning too and you are my main source of knowledge right now (even Apple’s examples are too obscure for me on this matters).
I started your “course” on Wednesday. I’m creating my own game using your tutorials as templates and changing what I need. (I hope you don’t mind, do you?)
As I said above, thanks to you I finally am able to understand OpenGL and how to use it on Xcode. So I can’t help to be very, very grateful to you. :D
As soon as I finish each of the tutorials I’ll be sure to praise your work on the corresponding post, because I’m sure you’ll deserve it as much as you do in this first tutorial. ;)
Keep up such excellent work!
RoberRM

Becjr  on May 15th, 2009

Hey Mike,

I discovered your site & tutorials several weeks ago and have found them to be the most approachable that I’ve seen, I’m hoping you can provide some rudimentary guidance…
I’m as new to programming as one can be. Having said that, have been trudging my way through many of the numerous .pdf files available from Apple’s Dev and as a result I currently can’t tell if I’m making any forward progress or just spinning my wheels. Not even the hour-long class videos from Stanford University are helping.
The problem I’m having is that when I reference projects already completed the coding seems to make sense, yet when I sit down in front of Xcode to perform some coding for my own app ideas… I just don’t know how to proceed. The graphics side of things I have a fair handle on [that's more my background]. I just can’t wrap my head around when I’m trying to code is what to put and where – such as which class should I use for a particular function and does that code go in the header file or the implementation file? I’ve been rewatching your earlier tutorials to try and piece things together but since I’m following your lead I am still uncertain about how to code for my own projects.
Based on the 6 tutorials I’ve seen so far, I feel that your tutorial style is thoughtful enough to explain this confusing (for me) matter better than anyone else. I know the tutorial process is time consuming and it’d be like asking you to backtrack now that you’re so far along into your OpenGL game, but I would like to humbly request a “beginners guide” to programming tutorial.
I will continue to view your site with much anticipation, regardless. Your tutorials are “hands-down” the best.

Thank You very much!
Bobby

mike  on May 15th, 2009

Hi Bobby and thanks for your comments. I’m really pleased the tutorials are helping in some way and welcome to the world of development.

Starting out can be a real drag in trying to get the language syntax correct as well as understanding the common design patterns to use etc. It sounds like you are doing the right thing in checking out all that is available on the Apple website and other resources. I can highly recommend the book “Cocoa Programming for Mac OS X”. When I started out with Objective-C I got this book and it was a great lead into the language.

It doesn’t take you from the very beginning if you are very new to development, but it does give you a good grounding in Objective-C.

I like the idea of a very simple Tutorial on how to structure a simple application describing what goes into the .h file and what in the .m etc. They do take some time to put together, but I’ll add it to the list and see how quickly I can get to it.

Thanks again for following the blog and taking the time to comment. If you have any questions you would like to shoot over then please do and both myself and I’m sure other blog readers would be happy to help you out.

Good luck.

Mike

HarryiPhony  on May 18th, 2009

Hi Mike,

Thanks for helping to us through great tutorial. I downloaded this tutorial but its show only one small image at center and then there is no action, no moving like that.

Actually i am using OS 2.2.1(Applied for Developer certificate), do u know what is the problem.

Thanks.

Anonymous  on May 18th, 2009

Really good job,

i’mnoob ine programmation, non native english speacker and even i find your tuto straight.

Favorite and waiting for others ^^

mike  on May 18th, 2009

@HarryiPhony thanks for checking out my Tutorial and I’m glad it has been useful. Tutorial 1 is a basic one and it only covers getting a project set up and drawing a single image on the screen. This tutorial does not make anything move or react to the user moving the phone etc, so it sounds like for Tutorial 1 its doing exactly what it should be.

@Anonymous, glad you liked the tutorial and I hope you both enjoy the other tutorials on our site.

Mike

How To Make an iPhone Game: Day 2 | Phoxware  on May 20th, 2009

[...] to kick the day off I went over to 71Squared to get started watching an excellent series of iPhone game programming tutorials. In a way they’ve done something like what I’m doing here in this chronicle, except the [...]

magiconair  on May 20th, 2009

Very nice tutorial. I’m almost done finishing a simple Pong game using UIImageViews and after watching your tutorial I’m getting interested in porting it to OpenGL just for the fun of it :)

Thanks
Frank

mike  on May 20th, 2009

Thanks magiconair. If you have any screenshots or videos to share that would be cool. I love seeing others peoples work :o)

Mike

Anonymous  on May 21st, 2009

Nice tutorial. where is the next part cant wait to get my ship moving ;)

mike  on May 21st, 2009

@Anonymous, I’m getting close in my tutorials to actually moving stuff :O) just been getting the core stuff done first.

If you want to have a go at move the image, create a couple of variables called imageX and imageY and within the update method change their value, which could be as simple as:


imageX += 0.2f * delta;
if(imageX > 320)
    imageX = 0;

Then in the render code make sure that you are using the imageX variable within the renderAtPoint. This should make your image move from the left to the right of the screen and then back to the left once it falls off the right.

That is just a simple example of how you can change the location of an image to make it move. I’ve be covering more on this in future tutorials.

Hope it helps for the moment.

Mike

Boxer Bob  on May 22nd, 2009

Every time I go to Build and Go it gives me an Error: syntax error before ‘glMatrixMode’ ?? It’s the line right after //Set up OpenGL projection matrix. I’ve triple checked it with your tutorial and I copied it directly from the OGLGame download. What am I doing wrong??

mike  on May 22nd, 2009

Hi Boxer Bob, can you post the code above and below the line which is giving you the error and I’ll take a look, or you can send over your project to mike@blog_domain_name.co.uk and I’ll check it out for you.

Mike

Boxer Bob  on May 22nd, 2009

Within my EAGLView.m –

//Set up OpenGL projection matrix
glMatrixMode(GL_PROJECTION);
*Error: syntax error before ‘glMatrixMode’
glLoadIdentity();
glOrthof(0, rect.size.width, 0, rect.size.height, -1, 1);

and so on

mike  on May 24th, 2009

Hi Boxer, I cannot see anything wrong with what you have posted above. Syntex errors like this can be reported quite some distance from where the problem actually is, so I’d need more of the code to help spot where the problem is coming from.

Mike

Hanol  on May 26th, 2009

Thanks for the good tutorial.
I am still a beginner and have a little question.

Shouldn’t we set an autorelease pool before calling
the CGMakePoint (160.0f,240,0f) and releasing the pool after that?

It seems that the CGMakePoint is creatin a Point Object and passing it to the 2D texture draw methode which is not releasing it. and seeing how many times/seconds this function is called, I think it can create a major memory leak.

Please tell me if that could be correct.
Thank you.

magiconair  on May 26th, 2009

CGPoint is not an object but a struct. Therefore no memory has to be released as none was allocated.

The autorelease pool is usually created by Xcode in the template in the main() method. You don’t have to release the autorelease pool or objects therein as it exists during the entire lifetime of the app and holds on to objects which are usually only shortlived and are freed automatically. (Think [NSString stringWithFormat:...] you don’t have to release the string generated by this method because its in the autorelease pool)

Frank

mplaczek  on May 31st, 2009

Thanks for the great tutorials! Looks like there is going to be some fantastic information contained in these videos… Having just finished my first app… I have started working my way through your videos (using the 3.0SDK)… having imported the Texture2D.h and .m I have 123 errors! as opposed to your 18. And they are not remedied with the addition of the framework… is this related to changes in 3.0? Any thoughts would be appreciated! Thanks!

mike  on May 31st, 2009

Hi mplaczek, thanks for the comments.

I have not had a chance to run through all of the tutorials using OS 3.0 but I have just tried tutorial 1 again with OS 3.0 b5. It actually worked fine without any errors so it could be something which has been missed from your project.

Can you post some of the errors which you are seeing as that would help to figure out what is going on, or you can send me your project (mike@71squared.co.uk) and I’ll take a look at it for you.

Mike

mplaczek  on May 31st, 2009

Ooo, ok… half the fun (and best way to learn) is through troubleshooting… I’ll go through my code and try to figure it out… if I hit a brick wall, I’ll let you know!

Thanks!!

mplaczek  on June 1st, 2009

Started fresh from the start and it worked perfectly… I think it had something to do with the coregraphics framework I had selected first time around… that is the only thing I did differently. Thanks :)

mike  on June 1st, 2009

@mplaczek, great, I’m glad you got it sorted. Let me know if you have any others questions.

Mike

jhorn929  on June 11th, 2009

Mike, Thanks for the great tutorials so far. They have all been super helpful. Have you thought about doing a tutorial for the title screens or the menu system for a game? Maybe when you click on the icon for the game a title screen pops up, then you can press something to play game or view controls, etc.

If you have done something like this I must have missed it and sorry for the spam.

Thanks,

John

Anonymous  on July 2nd, 2009

THANK YOU

Anonymous  on July 13th, 2009

Wow, this is a great tutorial. If this is you with mistakes and “poor style” then I can’t wait to see what the other tutorials offer, because this was really helpful! I was in a rut and this stuff really showed me the light. Keep up the good work. Thanks!

johngood  on July 18th, 2009

Hi Mike,

Just bought an iPod and I have installed the iPhone SDK
and would like to write some applications for it.

Found you Web Site and the tutorials just what I need
the only problem is when I open XCode and select a new
project the option for ‘OpenGL ES’ is not there?

I have searched Apple.Development with no luck and not
sure what I need at http://nehe.gamedev.net/

Can you help?

Thanks.
johngood.

John  on July 19th, 2009

Hi John,

Mike is on holiday for a couple of weeks but hopefully I can help you out. When you open XCode and go to create a new project, make sure on the left of the dialog box you have the “Application” link selected under the iPhone section at the top, otherwise you will be creating a Mac OS X project.

Let me know how you get on.

johngood  on July 19th, 2009

Hi,
I have not used a Mac for some 12 years now so
bear with me.

When I Open Xcode and select Application all I get
is the following:

Cocoa Touch Application
Cocoa Touch List
Cocoa Touch Toolbar

Where do I go from here?

Regards,
John.

John  on July 19th, 2009

Hi,

What version of XCode are you using?

Thanks
John

johngood  on July 19th, 2009

Hi John,

Xcode 3.1 from iPhone SDK Developers Tools for Mac
10.5.5.

It would seem to me that I need OpenGL ES Software
installed on my Mac but searching the net is very
confusing because there are many types and
versions ranging from 1.0 to 2.1.

I also need to create a Template for Xcode to use
OpenGL ES I think but I dont know how to do this
either.

Thanks for your help so far.

Regards,
John.

I am running Intel OSx86 10.5.7

Jamie Chapman  on July 23rd, 2009

Excellent tutorial, OpenGL scares me a bit in comparison to regular Cocoa touch but this has definitely put me at ease.

Thanks very much, Mike.

John  on July 24th, 2009

@johngood I haven’t installed anything other than the latest SDK (3.1 beta 2) and the Open GL ES application shows up in the available projects when creating a new one. I am a little confused as to why you are not seeing it.

This may be a question for Mike when he comes back ;)

I am more of a webdev guy and only dabble in iPhone dev.

mike  on July 28th, 2009

@Jamie Chapman, thanks for the comment and I’m glad your finding the tutorials useful. OpenGL certainly looked worrying to me when I started this and although I’m far from an expert, you do get used to it after a while :o)

@johngood, are you still having problems with finding the OpenGL ES XCode template?

Mike

Sandbird  on July 30th, 2009

Mike if you were a girl i’d be in love with you. lol.
Thanks for the awesome tutorial. Cant wait to see the others.

I have studied VC++ back in the day and i have to say this Objective-C is really bugging me. I dont understand how to “struct” my thoughts in this… (probalbly cause i’ve been using PHP instead since my university years.hehe)

Nonetheless starting from scratch and watching your tutorial put me back on track.
Thanks !

mike  on July 30th, 2009

@Sandbird, lol, thanks :o)

I’m glad its helping you out and once you get your head around Objective-C its not hard to work with at all :o)

Good luck

Mike

Incredible iPhone Game Programming Tutorials With Video | iPhone Development Tutorials and Tips  on July 31st, 2009

[...] iPhone Game Programming – Tutorial 1 iPhone Game Programming – Tutorial 2 – Image Class iPhone Game Programming – Tutorial 3 – SpriteSheet Class iPhone Game Programming – Tutorial 4 – Bitmap Font Class iPhone Game Programming – Tutorial 5 – Animation Class iPhone Game Programming – Tutorial 6 – Tiled Map Class iPhone Game Programming – Tutorial 7 – Singleton Class iPhone Game Programming – Tutorial 8 – Particle Emitter iPhone Game Programming – Tutorial 9 – Sound Manager iPhone Game Programming – Tutorial 10 – Game Structure [...]

skube  on August 8th, 2009

I’m completely new to (real) programming so I don’t have a clue what I’m doing. All the same, I enjoy following your tutorials hoping something will rub off ;)

If I make it through all of your tutorials and retain anything I’ll definitely buy you a coffee!

mike  on August 8th, 2009

Hi skube. No problem if your new. Hopefully the tutorials will help you get some ideas on how to get started. They don’t cover the basics of programming but there some other great sites for that, but as far as how to use code to create games hopefully these tutorials will help.

Good luck with your journey and I hope to see a blockbuster app on the app store soon ;o)

Mike

Madcow  on August 10th, 2009

I watched through the first three tutorial and Mike, i gotta admit it was very awesome. However as i have zero understand on OpenGL, i find it hard to follow some of the code that belong to setting up the projection matrix, declaration and setting up properties for the view and since i eager to know what those code does.

So i still waiting for some of the basic that u mentioned within the next video. And i will definitely throw in extra sugar for your cup of coffee. ;)

archer  on August 13th, 2009

Hi Mike

I’m getting this error when I’m compiling this code on my machine.

/OGLGame Tutorial 2/OGLGame_Prefix.pch:7:24: error: UIKit/UIKit.h: No such file or directory

Please help me with this.
I’m new to iphone Programming but I’m quite familiar with OpenGL.
I’m using your tuts for learning iphone programming

Madcow  on August 13th, 2009

@archer: Something tell me that u need to reinstall SDK ..

madhuk  on August 28th, 2009

Hi mike,

First of all thanks for the nice tutorials.

I saw first two tutorials they are really good..
And planning to watch the rest..

I need a suggestions.

I am planning to develop a iPhone 2D game,and I am confused which one to choose between Quartz2D or OpenGL ES.

And one more doubt is can I use Interface builder along with OpenGL ES for creating my menus,sub menus,settings(sliders) etc.,.because I will
get so many thing for free with less coding.And even nice text view scrolling which is difficult to manage that through code.

mike  on August 28th, 2009

Hi Madhuk and welcome to the blog.

I would suggest you use OpenGL ES for the game. Quartz and Core Animation are great for very simple games, but as soon as it starts to get a little complex things will get slow.

OpenGL ES basically uses a UIView which has a CAEAGLLayer attached to it so that OpenGL ES can be rendered to the screen. This means that if you wanted to create other screens such as menu and settings etc then you could use IB and just switch between the views.

Having the OpenGL ES view visible as well as another view during game play is possible but not advisable due to the performance hit, but switching between them should be fine.

If you look at the Touch Fighter example project from Apple, they mix OpenGL ES with UIKit controls for settings etc as you are suggesting.

Good luck and let us know how you get on.

Mike

Anonymous  on August 29th, 2009

Hi mike,

Thanks for the quick replay…

I have one more thing to ask.

I doing same thing what you have done in tutorial-1 to get some experience,but in my Xcode I dont see any reactor button before build and go button.

Can you please tell me how can I do that because refactoring is the most common thing that we most of the time have to do.

-Madhu

mike  on August 29th, 2009

Hi Madhu

If you right click in the toolbar near the build & go button you will get the option to customise. If you select this you will see a number of buttons that can be added to the toolbar. Re-factor is one of them. Just drag it onto the toolbar where you would like it to be and your done :o)

Mike

gnetro  on September 17th, 2009

Cannot download the video :(

youke  on September 17th, 2009

I am from china
thank you
this turorials are very good
thanks

exerion  on September 25th, 2009

Hi Mike

I’m starting with XCode and iPhone SDK. I’m using the latest version of xcode (3.2) and I’m a little confused because when i create a new project with OpenGL ES i’ve got more files then it’s in your tutorial like ES1Renderer and ES2Renderer and I cannot find the CoreGraphics.framework. What i should do with the esXRenderer files and where I can find the CoreGraphics.framework ?

I’ve also wanted to ask you what I have to do to use the accelerometer on iPhone Simulator 3.1?

By the way – great tutorials.

Exerion

mike  on September 25th, 2009

Hi exerion

What you are seeing is a result of changes that were made to the OpenGL ES template in 3.1. Because the iPhone 3Gs supports OpenGL ES 2.0 the template basically shows you how to set up an OpenGL ES Context for either 1.1 or 2.0. Unless you are working on a 3Gs it will always create an OpenGL ES 1.1 context which is what my tutorials are based upon.

I’ve not had a chance to change the first tutorial based on the new template yet. The new template also delegates the rendering to the ES1Renderer or ES2Renderer classes which is different from the tutorial. If you just download the project for Tutorial 1 and build from that then it will be fine.

Let me know if you have any other questions.

Cheers

Mike

exerion  on September 25th, 2009

Thanks Mike,

I have another question, I’ve downloaded the Tutorial1 project but I would like to change the whole project name from OGLGame to something else like f.e.: iPhoneGame. Is there a fast and a safe way to do this? I know that inside the project there are many references to files with “OGLGame” phrase in their names. How I can change it?

And the second question. Will you create a new tutorial based on the latest version of xcode?

Thanks for your help.

Exerion

mike  on September 25th, 2009

You can rename a project in 3.2 by using the rename option in the Project menu. To rename a file and have it ripple throughout the project you need to select the name of the file in the .h or .m file and use refactor. That will change the name throughout the project and the filename as well.

I’ve not got any tutorials planned for Xcode 3.2 until after the book is done. The book is based on SDK 3.1 and XCode 3.2 so that will be up to date, as long as there are no more release ;o)

Once the book is out I’ll then be looking to update some tutorials and also create some new ones.

Hope that helps.

Mike

Aeldron  on September 27th, 2009

Great tutorials, I’m looking forward to reading the book too.

Is there any chance we could get the videos available for download as well? I’d like to watch them offline on the train…

John  on September 27th, 2009

Sorry, I am in the process of uploading them to Amazon S3, should be done this weekend and the downloads will be back.

Aeldron  on October 2nd, 2009

Thanks John and congratulations for the wedding!

I’ve upgraded to Snow Leopard and Xcode 3.2, and now the tutorial project doesn’t work anymore…
:’(

I’ve created a new OpenGL ES project and I’m migrating the code there.

They’ve added a couple of new renderer classes (ES1Renderer and ES2Renderer), so I moved the renderScene code there. That all works fine until I enter the playerShip code. The iphone simulator will try to open the app and simply close it, without giving me any error messages to work with.

I figured it has something to do with the Texture2D class. When I set a breakpoint and trace it to the point it crashes, it breaks at the drawAtPoint method with an “EXC_BAD_ACCESS” error when it tries to create a glVertextPointer.

Is there a version of the Texture2D class which is compatible with the latest SDK?

Now, I’m not sure if I should downgrade my Xcode to be able to follow your tuts or if I should just keep on trying to do the same you are doing but using the latest version.

Any ideas?

exerion  on October 8th, 2009

Hi Aeldron,

Maybe it’s because in the latest SDK there is no CoreGraphics framework (at least I couldn’t find it). Propably when you’ve upgraded your SDK old frameworks was deleted or replaced with the new ones.

But if you download the tutorial 1 and build it, it will work because it contains all necessary frameworks.

Hope I’ve helped, Exerion

Robin  on October 13th, 2009

This may very well be the best iPhone-dev-screencast I have ever watched. Nice work, Mike!

mjsdabeast  on October 14th, 2009

Hi, i really like your tutorials a lot, but i’ve been wondering where you started learning open GL and how you learned so much of it. Also, when is the haunted house game you mentioned going to be done? Great job on the tutorials!

mike  on October 14th, 2009

@Robin, thanks for the kind feedback.

@mjsdabeast, Glad you like the tutorials. All the knowledge has come from reading the Apple iPhone documents on OpenGL ES and reading through/playing with the example code that Apple provides.

I’ve also made use of excellent web resources such as the iDevGames forum and iPhoneDevelopment blog http://iphonedevelopment.blogspot.com/

These are great resources to search when your trying to work stuff out and also if you need to ask questions if you really are stuck. I’ve found them fantastic resources.

The rest is trial and error. I could have just gone with using something like Cocos2D and not worries about how you used OpenGL ES, but I’m the kind of person who likes to know how this stuff works, so trial and error and actually making the tutorials has got me to where I am now.

I will be putting up a video of Sir Lamorak’s Quest this week to show people where it stands. Got some great graphics in there now from Ryan Sumo who is the artist I am using, so watch this space.

Mike

Adam  on October 14th, 2009

Mike,

(Please respond to my email provided as i will not be able to find your response thanks so much)

I have a simple question for you, I really am a beginner when it comes to making games for any platform not iPhone specific. But i took a look at your great tutorials but my question to you is simply this…

Is each tutorial meant for developers to watch and then implement separately in there own games or is this a set of tutorials that will take you from start to finish of the needs and what to knows about making a complete game. From menu’s to level.

Thanks and if you could point me toward a super beginner resource for making games for the iPhone maybe?

Other than that everyone seems to be quite pleased with your work so good job man!

Jan  on November 4th, 2009

Hi! Just wanted to let you know that I’m just getting started with iPhone programming and your tutorials make this really easy (and fun). Thanks!

mike  on November 7th, 2009

Hi Jan

Thanks for the comments. You are starting on a really fun journey. It will be frustrating at times, but when you see you creations come to life it will all be worth it.

Good luck and feel free to post questions in the blogs or forums if needed.

Mike

Ken  on November 14th, 2009

Hi Mike, I just start working on the tutorial 1 using iphone OS 3.1.
It seems that quite a big different of the template from your example such as the render OS 3.1 includes ES1 renderer and ES2 renderer, can you explain a bit such that it is easier to do tutorial for OS3.2
Thanks
Ken

mike  on November 14th, 2009

Hi Ken

Your right in that the new template is very different to the old one used in the tutorial. I’ve not had a chance to go back over the old tutorials. I’m not going to get a chance to do that until the book I’m working on is finished.

Whilst the template is different to the new one, you can just use the code in the tutorial and it will work fine. ES1Renderer is basically setting up an OpenGL ES context for OpenGL ES 1.1 and ES2Renderer is going the same for OpenGL ES 2.0.

I’m not using 2.0 is any of the tutorials, so they are basically already doing what ES1Renderer is doing just not using the same structure.

Another thing to watch out for the screen being blank when you run the tutorial. If you search for Black Screen in this blog you will find a post on how to correct this problem.

Sorry I’ve not been able to go back and change the tutorials, but the code is still valid if you use the projects that come with the videos :o)

Mike

MrZero  on November 28th, 2009

I please you to update your tutorial video to Xcode Version 3.2.1. – you are right ppl can use the orgiginal code from you and it will work … but the think is that the new example from apple include a version check – so that it will automaticly use the right GL ES Version for 3g or 3gS phone .
the ES2.0 is much faster – but opengl beginner with a 3gS can not use it with this tutorial.
Its to heavy for opengl beginners to bring this version to run with the old video turorial and the new example from apple.
It will makes sence for all who like your stuff.

mike  on November 28th, 2009

Hi MrZero

The tutorial does need to be updated. I’ve just not had the time to do it recently. Also, OpenGL ES 2.0 is a very steep learning curve as you need to learn Shader Language to do anything. There are plenty of examples on the net, but it is still a large learning curve.

To reduce the amount you need to learn as much as possible and to allow the software to run on the maximum number of devices at the moment I’ve stuck with OpenGL ES 1.1. The 3Gs is generally faster than a 3G device anyway. As OpenGL ES will not run on anything other than a 3Gs then you would not get the benefit of the speed on the older devices.

As soon as I finish the book I will be reviewing the tutorials again and updating them. The code in the book does use the new template but also stick to just OpenGL ES 1.1.

Thanks for your feedback though, its what keeps this blog alive :o)

Mike

Scott  on November 30th, 2009

Mike,

I just wanted to say thanks for putting this together. I just found your site a few days ago and have only had a chance to run through the first two tutorials. Very nice work.

I, like you, need to understand why things work the way they do. Your tutorial allows me to do exactly that. I agree that it would really help if the tutorial were using the latest version of the OpenGL template, but I was able to port it over without much of a problem.

I would be happy to post my changes here if it would help others. However, I’ve only made it through the first couple of tutorials and it sounds like there are more changes coming. In a nutshell, the rendering just needs to be implemented in the ES1Renderer.render method.

Anyway, keep up the great work. I will be spending a lot of time on this site over the next few weeks.

Thanks,

-Scott

Martin  on December 29th, 2009

Hi Mike,

This is simply superb. Very useful for beginners like me. I have a question, i want to keep the home view background image as under the sea(i.e. live water image as background image), how can i do that? Do i need to have a sea water image in .gif format and add it as background because it should be live water flowing here and there, same like under sea?

Scoobie  on December 30th, 2009

Hi Mike,

Awesome work on sharing the knowledge and willing to put forth your own time to help people like me who are entirely new to this kind of programming and doesn’t understand it to easily. It’s obvious that others have caught on to the new examples given out with the SDK and I see that you stated it’s still valid to use this tutorial and its code.

I went ahead and followed several of your instructions and not sure if I hit a road block here, but even after deleting the code provided in the original example and adding in the code given in your tutorial here, I don’t see a blank screen, I still see the ‘box’ provided by Apple, jumping up and down now, no longer spinning. Have I done something wrong? I also went on to try the glClear and gave the green a value of 1 like you gave in the example and still no green screen for refreshes.

Just want to say, thanks again for all your hard work and spreading your knowledge to us…

Isaac  on December 30th, 2009

I really enjoyed the two December tutorials. Your explanations are awesome. I had a couple of quick thoughts about tutorial 1.

You indicate that the call to sqrtf() in updateWithTouchLocationMoved to compute distance is expensive. I noticed that you call atan2() to compute the joystick angle only to call cosf and sinf later on the angle later. It would seem more efficient to avoid the atan2() call and to compute cosf and sinf as dx/distance and dy/distance. You could store the sinf and cosf values rather than computing them from the angle in updateWithDelta.

Also, inside updateWithTouchLocationBegan, why not end the for loop after joyPadTouchHash = [touch hash]?

Scoobie  on December 31st, 2009

Hi Mike,

Please disregard my last question. I finally found out my mistake in that I left #import ES2Renderer, so it was still calling that and overriding ES1Renderer? This is where I’m a little confused as I’m guessing the ES2 import is overriding the ES1 import. Nonetheless, I deleted the ES2 header and method and also any where else ES2Renderer would be called or checked and found that the your Tutorial 1 instructions work perfectly. It just took some time where to put some other code and what not.

I’m really enjoying it all though and look forward to spending more time catching up with your other tutorials.

mike  on December 31st, 2009

Hi Isaac, you make a couple of excellent points. I had not thought about using the distance and dx/dy to compute the angle. I’m going to give that a try. Your also right on about exciting the loop after finding the hash. Both of those are really great points. I’m glad your enjoying the tutorials and the feedback is really appreciated.

Scoobie, I’m glad you sorted out your problem. The way the default template works is that it will try to create an OpenGL ES 2.0 context first and if this works then it will use that. If that fails it will try to create an ES 1.1 context. This is how you can build in support to your app for the different ES versions. On the Simulator it will allow you to create an ES 2.0 context and not drop into the 1.1 version. It will also do the same if you were running the code on an iPhone 3Gs or 4G iPod touch :o)

I hope you enjoy the rest of the tutorials.

Mike

Isaac  on December 31st, 2009

Mike,

Just to be clear, I’m recommending that you skip computing the angle and just store sinStickAngle and cosStickAngle which can be computed using dy/distance and dx/distance. This would eliminate *all* calls to atan2, cosf, and sinf, for the joystick. Then in your game logic just use the stored sinStickAngle and cosStickAngle. The joystick code does not need to call any trig functions.

But if you want to use trig, using atan2() as you do now is probably far less messy than computing the angle from distance and dy/dx because atan2 sorts out the correct angle quadrant for you.

Isaac

rgauss  on January 3rd, 2010

Hi mike,
Thank you for your excellent tutorial. I am trying to follow your tutorial using the new SDK and I had a question. The code exits unexpectedly to render the ship whenever I use the line:

[playerShip drawAtPoint:CGPointMake(160, 240)];

Trying to debug I went to the Texture 2d file provided and I saw that the code exits at this line:

glVertexPointer(3, GL_FLOAT, 0, vertices);

Could you provide any insight as to what I might be doing wrong?

Thank you
rgauss

rgauss  on January 3rd, 2010

I think the problem might be in the renderScene function. The tutorial renders the playerShip in the EAGLView.m but the new SDK has the ES2renderer that is supposed to render it. I am declaring the playerShip in the ES2renderer but I am not sure if it will get created in the current context.
Should I post my code?

rgauss  on January 4th, 2010

Hi mike,
Never mind. I played with the renderer classes more and finally am displaying the player.png. I look forward to the other tutorials.
One question is, I modified the ES2 renderer class to initialize with context: kEAGLRenderingAPIOpenGLES1 rather than kEAGLRenderingAPIOpenGLES2. is that ok? or should i just modify the EAGLview to use ES1renderer instead of ES2renderer always? Sorry, my question might be trivial since my understanding of the rendering classes is limited at this point.

WonwooLee  on January 4th, 2010

Nice tutorial !!

Hey, could you share the video in mp4 format, something like pod casts ?

I really want to watch tutorial videos on my iPhone, while I’m outside.

mike  on January 4th, 2010

Hi rgauss, I’m glad you got your issue sorted out. I would stick with the ES1Renderer class. This is already set up to work with OGLES 1.1 and so should not need any change. Just change the EAGLView class to use this class rather than ES2.

The new template is set up to try and create an ES2 context that will only work on the SImulator of an iPhone 3Gs.  If that does not work then it will create an ES1.1 context using the ES1Renderer.

For my game I have simply removed the ES2Renderer all together and just use the ES1.1.

The code I have in EAGLView is below:

- (id) initWithCoder:(NSCoder*)coder
{
    if ((self = [super initWithCoder:coder]))
	{
        // Get the layer
        CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;

        eaglLayer.opaque = TRUE;
        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                        [NSNumber numberWithBool:FALSE],
					kEAGLDrawablePropertyRetainedBacking,
                                        kEAGLColorFormatRGB565,
					kEAGLDrawablePropertyColorFormat,
                                        nil];

		// Set up an OpenGL ES 1.1 renderer
		renderer = [[ES1Renderer alloc] init];

		// If the renderer is empty then something wen wrong so release this instance
		// and return nothing
        if (!renderer)
        {
            [self release];
            return nil;
        }
    }
    return self;
}

Hope it helps.

Mike

mike  on January 4th, 2010

Hi WonwooLee

We used to host the videos for download but there are so many downloads now it was costing us a fortune in bandwidth charges, this is why we moved to Vimeo.

When new videos are added to Vimeo there is a download link available for a short while that can be used, apart from that we don’t have a download link available.

If we find a hosting solution that allows us to download the movies we will start that again. We were using over 40Gb per month on movies alone which can get expensive :o)

A link to the latest video for download is http://www.vimeo.com/8355746

Mike

CasdraBlog » Blog Archive » links for 2010-01-29  on January 29th, 2010

[...] iPhone Game Programming – Tutorial 1 | 71² – The ramblings of two 30-something developers (tags: iphone programming) [...]

Joseph  on April 7th, 2010

This is real real great tutorial. Thx a lot.

ipad user  on April 12th, 2010

lol can’t view this video on my ipad

Mike  on April 12th, 2010

Thanks ipad user. Ive just got my iPad and seen the same problem. Well look into getting this fixed. If you go directly to vimeo, where the videos are hosted they work fine on the iPad.

Mike

pearson  on April 19th, 2010

Hi,

I have just come across your tutorials and i think they are great. I am a new to this and i seem to be using a newer version of the SDK as i have a esr1 and 2 render files. i tried to follow the first tutorial but it will not build. what do i need to that is differnt from yours?

Thanks

stephen  on April 21st, 2010

HI mike,

Do you anyone have an updated version that uses the 3.1 template as I have been trying but I am unable to make your tutorial work.

Thanks

71-Squared: iPhone Game Programming – Tutorial 1 « Animated Coding  on April 30th, 2010

[...] came across a wonderful series of iPhone Game Programming by 71² and it is outstanding. Source code is also available at the official post. For beginners, this is [...]

keith  on May 23rd, 2010

I am a super beginner, if my question is too stupid, please forgive me.
your class is really useful, thanks
but the only problem is the SDK version.
I am using the 3.1.2 one
at the 1st time:
I got the “EXC_BAD_ACCESS” error .
after change the EAGLView class to use this class rather than ES2.
I got no error message when build, but it cannot show the player.png. I place the first code inside ES1renderer.m > init

playerShip= [[Texture2D alloc] initWithImage:[UIImage imageNamed:@"Player.png"]];

I place 2nd code inside ES1renderer.m>render
[playerShip drawAtPoint:CGPointMake(160.0f, 240.0f)];

Can you give me some advice? thanks much.

earlystar  on July 15th, 2010

Hi.

Can you convert your code for (XCode 3.2.3 OpenGL ES) template.
XCode 3.2.3 OpenGL ES template different template from OpenGL ES 1.1

keith  on July 15th, 2010

thanks thanks
finally i fixed the problem.

thank you

dowsky  on July 27th, 2010

Hey mike,

I really love your tutorial. It’s very easy to follow along.

The only problem is that when I try to run CrashLanding or OGLGame Tutorial 1, I get an error saying “There is no SDK with the name or path ‘iphoneos2.2′”
I am currently running snow leopard and have iphoneos 4.0. Do you know what I should do?

Harold  on August 4th, 2010

Hi Mike,

I’ve been following your tutorials and have to say: Well done! You’re really helping me out.

I also have a question. In this second tutorial the same methods with different parameters were programmed like this:

- (id) initWithTexture:(Texture2D *)tex {
self = [super init];
if(self != nil) {
texture = tex;
scale = 1.0f;
[self initImpl];
}
return self;
}

- (id) initWithTexture:(Texture2D *)tex scale:(float)imageScale {
self = [super init];
if(self != nil) {
texture = tex;
scale = imageScale;
[self initImpl];
}
return self;
}

Are there any disadvantages or some other reason you didn’t do it like this (and the other methods as well):

- (id) initWithTexture:(Texture2D *)tex {
[self initWithTexture:tex scale:1.0f];
}

- (id) initWithTexture:(Texture2D *)tex scale:(float)imageScale {
self = [super init];
if(self != nil) {
texture = tex;
scale = imageScale;
[self initImpl];
}
return self;
}

Because I’ve been wondering why you didn’t use it like that and couldn’t really find anything on this subject. Hope you get back to me about this.

Harold

mike  on August 4th, 2010

Hi Harold

There’s no reason the methods can’t be defined like that, in fact that is a much nicer way of doing it. When I created these methods and tutorials they were a little organic, and I never went back to tidy things up, hence things being implemented in two different methods.

Your approach is perfectly valid and is how things are done in the new code I’ve done for the book :o)

Hope that helps

Mike

Harold  on August 4th, 2010

Hi Mike,

Ok, thanks for the quick reply!

Alex  on August 5th, 2010

When I try to use OS3.0, it doesn’t work, what should I do.

Thanks

Regard,
Alex

mike  on August 5th, 2010

Hi Alex

When you say it doesn’t work, what is it doing?

Mike

Alex  on August 5th, 2010

Dear Mike,

WOW…It really amaze me for your quick reply.
Basically what have I done is follow your tutorial 1 and try to get it run on the simulator.

But I found in the first thing, when I simply create new openGL application, the drawView function is like taking object and calling rountine and it looks like the following:

- (void) drawView:(id)sender
{
[renderer render];
}

and it is a bit different from the tutorial.

Then when I try to run, the square is more like bouncing up and down on the screen rather then rotating.

Afterward, I download Tutorial 1 project from your link, I try to build and run again, and the complier said

error: There is no SDK with the name or path ‘iphoneos2.2′

I’m pretty sure that only a version problem, but I cannot move on to other tutorial…. Thats really frustrating….

Would you mind to tell me what to do, or what other reference I should look for??

If you want I can pack and send you the whole project that create by my SDK.

Many Thanks for your help.

Alex

mike  on August 5th, 2010

Hi Alex

With the project from Tutorial 1, make sure you have set the base SDK for both the project and the target to be the SDK version you are using, this should remove the problem you are seeing.

If you get to a point where you are getting a blank screen in any of the tutorials, search for a blog post called “The black screen of nothingness” which describes what needs to be changed in the project to make it work with SDK version 3.0+

I will be updating these in the near future, but that should get you moving to start off with.

Let me know how it goes.

Mike

Alex  on August 6th, 2010

Dear Miike,

Would you mind to tell me a bit more about where I can find information for “setting the base SDK for both the project and the target to be the SDK version you are using” ?

Thanks

Alex

jasonvan  on August 7th, 2010

Hey Mike,

Thanks for these great tutorials. I’ve just started Objective C not too long ago, so not really familiar with some stuff. So was hoping you could help me out here with the tutorial.

I am using the Open Gl ES template from the 4.0 SDK. I’ve been reading the comments and changing this suggested here. Everything works fine until I tried to add the playerShip into the ES1Renderer.h. It gives me an error and says playerShip undeclared. I know because I declared it in the EAGLView, but I don’t know how to make playerShip get “noticed” there (ES1Renderer), or am I even approaching it in the right way. Any suggestion would be nice.

Thanks in advance,

Jason

Dione  on August 24th, 2010

Have a question if i were to have all the graphics and textures and animation created in a program like lightwave or maya how do i just pull all the information into the game? Do i just make a folder (group for each and just invoke them?)

Thanks!

mrspeaker  on August 30th, 2010

I just started re-visiting these tutorials and came up against the same problem as others have said above: the rendering has been moved to ES1Renderer (or ES2Renderer, if you leave that in) – so playerShip does not exist in that class’s context.

My short-term solution is to pass the playerShip texture into the render method! So EAGLView has:
- (void)renderScene{
[renderer render:playerShip];
}

And ES1Renderer render method gets changed to:
- (void)render:(Texture2D *)playerShip

Then you can draw the ship. But obviously this is no good for the next lot of tutorials – we can’t pass every resource to the render method!

Leave a Comment