OpenGL ES iPhone Textures - iphone

For one of my new games I'm using OpenGL ES since it has multiple enemies and bullets, etc. How do you draw images on the screen with Opengl ES? I have a player.png image that is a 48x48 pixel image; how would I draw that on the screen?

The basic answer is that you create a quad out of two triangles and draw that "camera facing" or in 2D mode on the screen.
In the iPhone example of OpenGL ES (the rocket ship one) you can see the Texture2D class which handles loading png's and displaying them. It's simple, but works.
But I would suggest you take a look at cocos2d iPhone. This framework handles a lot of this stuff for you and lets you focus a lot more on your game: http://code.google.com/p/cocos2d-iphone/
You might also look at GameSalad for a non-programmery way of making simple iPhone games: http://gamesalad.com/

Related

ES 2.0 Multi-Pass & Render to Texture Implementation

I need help setting up multi-pass rendering with OpenGL ES 2.0 on the iPhone. I haven't been able to find an example which implements both rendering to a texture and multi-pass shading.
I'm looking for some instructions and sample code which implement:
First stage: Render to a texture
Second stage: Input that texture and render to screen
I have referenced Apple's OpenGL ES Programming Guide, OpenGL Shading Language (Orange Book), and O'Reilly's iPhone 3D Programming Book.
The Orange Book discusses deferred shading and provides two shader programs for first-pass and second-pass rendering, but doesn't provide example code to setup that application or show how to communicate data between both shaders.
Questions:
How to render to texture?
Using glDrawElements
How to input that texture to the next pass?
How to implement two shading programs?
How to alternate first- and second-pass shading programs?
Need to attach, detach, and call 'use' for each pass?
How to implement multi-pass shading?
I wrote a short example of doing just this (multiple render-to-texture passes on the iPhone using OpenGL ES 2.0) a few weeks ago: http://www.mat.ucsb.edu/a.forbes/blog/?p=245
**
Edit, this post is a bit old, and it has moved here:
http://blog.angusforbes.com/openglglsl-render-to-texture/
**
Ok, first of all: I'm no expert on OpenGL ES 2.0. I was kind of in the same situation where I wanted to do a multipass render setup, in one of my first OpenGL ES applications.
I also used the Orange Book. Check chapter 12. Framebuffer Objects > Examples. The first example demonstrates how to use a framebuffer to render to a texture, and then draws that texture to screen.
Basically using that example I created an application that renders some geometry to a texture using an effect shader, then renders that texture to screen, layered with some other content all using a different shader.
I'm not sure if this is the best approach, but it works for my purposes. My setup:
I create two framebuffers, the default and an offscreen one. Same for the renderbuffers
I create a texture which the app will render to
I bind the offscreen framebuffer, and attach the texture to it using glFramebufferTexture2D
My rendering:
bind the offscreen framebuffer.
use my first shader program
draw my geometry
bind the default framebuffer
use my second shader program
draw a fullscreen quad with the texture attached to it.

Playing 3D Animation in iPhone App (Possibly using a looping video)

Is there a relatively easy was to include a 3D animation into an iPhone app? We have the animations already made up for another project and our client has asked if they can be placed inside an iPhone app. We could perhaps include a low-res looping video of the animation (it's just a 3D component rotating on a single axis), or would it be better to look into getting the 3D animation directly onto a view?
Cheers,
Dan
You could either split it up into a set of frames and use the UIView animationImages property like so:
http://appsamuck.com/day2.html
Or assuming its already an OpenGL animation you could port the code to openGLES.
Here are good tutorials for openGL ES:
http://iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-table-of.html

2d openGl game in iphone?

I want to develop simple 2d opengl game with animation.in that animation I have to clip the image frame and draw it.
Any single tutorial link or book which gives step by step Teachings to animate the image frame(sprite) and to do calculation.
http://apress.com/book/view/9781430225997
A free tutorial on OpenGL ES for the iPhone:
http://iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-part-6_25.html

iPhone - Drawing 2D with OpenGL ES, fast and simple

I'm going to make a game for the iPhone, and I'm mostly going to be using images. I've read that using Quartz only is slow for actual games with high frame rates, so I was wondering if you guys had any good ideas for using OpenGL for rendering a game scene?
I'm going to be using a lot of images, and I want to be able to freely rotate them.
I've looked at Apple's examples GLSprite and GLPaint, but I don't really see anything I could use.
All I want to do is be able to render images at specific positions, and want to be able to rotate them.
I'm a noob at OpenGL, but I know Quartz.
Take a look at cocos-2d. It uses OpenGL instead of Quartz and supports making the kind of game you seem to want to make:
http://code.google.com/p/cocos2d-iphone/

2D Game Character Animation in iPhone - How is it done?

What I mean is, do animators work on an animation in say Flash (or some other kind
of key frame animation program) and then export it to the iphone somehow?
For example, say I am an animator and I want to create a person waving for an iphone
game. What type of external program would I use and then what libraries on the iphone
sdk would I use to load them in?
I think it all depends on how in depth you want to get. Making a 2D game is a broad statement. For example, to make what you ask. You would just make a series of PNG images for a cell based animation of the wave. wave1.png, wave2.png, waveN.png...
Then load the PNG images in and then play them in sequence. You can do this with UIImageView, Core Animations classes, or manually your self with UIImages and UIViews.
There a lot of great game engines you can check out too. Here is a link for an example of what is available. Game Engines
For the best performance, most companies/developers use OpenGL to do both 2D and 3D style games. You can utilize a lot of tricks for the textures used in your games.
The iPhone natively supports key frame animation with the CAKeyframeAnimation class.
I think the most popular framework for 2D games is Cocos2D: http://cocos2d.org/