I am working on an iPhone game, which will have many types of creeps, and each type of creep may have different colors, so I'm looking for the best way to do it, which so far seems to be palette swaping.
Is GL_EXT_paletted_texture available in OpenGLES (it is deprecated in OpenGL)? Since my game must support older devices (iPhone 3G) I can't use shaders, so I'm stuck with fixed pipeline.
How should I do palette swapping with OpenGLES on an iPhone?
OpenGL Color Index for iPhone's OpenGL ES 1.1?
It sounds that you can use glCompressedTexImage2D with GL_PALETTE4_RGB8_OES or GL_PALETTE8_RGBA8_OES. It would be possible to load texel data with various palette data.
Or you can use OpenGL ES 1.1 Texture Environments. Combine texture or constant color with proper environment.
iPhone 3D Programming - Chapter 8. Advanced Lighting and Texturing
Related
In apple's docs:(http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/OpenGLESPlatforms/OpenGLESPlatforms.html)
it says that for "OpenGL ES 1.1 on the PowerVR SGX" "There are 8 texture units available."
it doesn't say how many units are available on OpenGL ES 2.0, does that mean there is no limit?
Rather than asking and getting an answer that may or may not be correct in the future, your app should be checking programmatically at runtime using something like this:
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &MaxTextureUnits);
Note that there are also separate numbers for the number of allowed texture units in a vertex shader and a fragment shader. They would use the constants GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS and GL_MAX_TEXTURE_IMAGE_UNITS. The COMBINED number is the number available to both at the same time.
There is a detailed listing of all the hardware across iPhones and iPads on Apple's iOS Device Compatibility Reference
Based on this, you are safe with using upto 8 Texture units on any iOS device.
Actually the answer is in same page you linked in question:
OpenGL ES 2.0 on the PowerVR SGX
Limits
...
You can use up to 8 textures in a fragment shader. You cannot use texture lookups in a vertex shader.
....
So, I've been trying to figure out why the square is moving up and down the iPhone simulator when I Build and Run the template that Apple provides for OpenGL ES. I don't understand why for example they have ES1Render.m, and ES2Render.m instead of just one ESRender.m. Also, where is the equivalent of the glutDisplayFunc, and glutTimerFunc? Thanks in advance.
They are trying to the show the two versions of OpenGL ES. One uses shaders (v2) and the other (v1) uses older OpenGL technology. In the ES2 renderer I believe they are doing all the movement in the shader code. If you want something that looks like older OpenGL code try setting it to use the version 1 renderer. Then you can use stuff like the older demos on http://nehe.gamedev.net/. You just need to fill in the "render" function with your drawing code.
EAGLView has a timer which sets the frame rate, but there is a method which allows you to set it to be whatever you like.
I want to develop this game for the iPhone. Which framework would be best to use (e.g., Cocoa, Cocoa2d, OPENGLES)?
I would look at
http://code.google.com/p/cocos2d-iphone/
You get a whole engine to help with your app and getting some pretty tricky stuff working.
Cocos2d does the following.
Scene management (workflow)
Transitions between scenes Sprites
and Sprite Sheets Effects: Lens,
Ripple, Waves, Liquid, Twirl, etc.
Actions (behaviors): Trasformation
Actions: Move, Rotate, Scale, Jump,
etc. Composable actions: Sequence,
Spawn, Repeat, Reverse Ease Actions:
Exp, Sin, Cubic, etc. Misc actions:
CallFunc, OrbitCamera Basic menus and
buttons Integrated Chipmunk 2d
physics engine Particle system Text
rendering support Texture Atlas
support Tile Map support Parallax
scrolling support High Score server
(Cocos Live) Touch/Accelerometer
support Portrait and Landscape mode
Integrated Pause/Resume Supports
PowerVR Texture Compression (PVRTC)
format Language: objective-c Open
Source: Compatible with open and
closed source projects OpenGL ES 1.1 based
Cocoa2D is using OpenGL ES, and given the game you are looking to do is a simple sprite based game, I think this would be a fine tool kit to use.
On the other hand, for performance you might find that Quartz 2D is significantly faster and provides you for free useful things such as key frame animation. The reason you'll find it's faster is that OpenGL needs to handle at all times the possibility of 3D rendering and all the various possible interactions your polygons could have with the image space: projections, zordering along vertices, etc. Quartz 2D however is fixed in 2D space so provides a good 2D space management tool kit. Additionally all the additional overhead OpenGL can encompass is stripped out.
I've done both, and I've found Quartz 2D to be a simple and fast toolkit to learn and definitely easy to program in. In the future when I do simple 2D sprite based apps I myself will be using Quartz 2D.
I would go with OpenGLEs. It would allow you to have 3d and do some cool stuff later on if you wanted.
I want to make metallic 3d object that appears to be reflective. I want to accomplish this using an environment shader that uses either a sphere or cube map that I can assign an image or texture as the "reflection" source.
Does OpenGL ES on the iPhone support this in any versions?
OpenGL ES 2.0 provides shader support. However, it isn't available in many mobile devices that are on the market today. It would be important for you to code both ES 1.1 and ES 2.0 versions of the graphics.
Apple Dev Center has tons of information on the transition:
The fixed-function pipeline of OpenGL
ES 1.1 provides good baseline behavior
for a 3D graphics pipeline, from
transforming and lighting vertices to
blending the final pixels with the
framebuffer. If you choose to
implement an OpenGL ES 2.0
application, you will need to
duplicate this functionality. On the
other hand, OpenGL ES 2.0 is more
flexible than OpenGL ES 1.1. Custom
vertex and fragment operations that
would be difficult or impossible to
implement using OpenGL ES 1.1 can be
trivially implemented with an OpenGL
ES 2.0 shader. Implementing a custom
operation in an OpenGL ES 1.1
application often requires multiple
rendering passes and complex changes
to OpenGL ES state that obscure the
intent of the code. As your algorithms
grow in complexity, shaders convey
those operations more clearly and
concisely and with better performance.
http://developer.apple.com/iphone/library/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/DeterminingOpenGLESCapabilities/DeterminingOpenGLESCapabilities.html#//apple_ref/doc/uid/TP40008793-CH102-SW1
In the old days "metallic" look was achieved using technique called "environment mapping" or "reflection mapping".
Since no programmable shaders are available for OpenGL ES 1.1, simple reflection mapping can be done with software. Just transform vertex normals according to reflection source/camera and get texture UV-coordinates from transformed normal vector. iPhone has horsepower to do this easily, at least with decent vertex counts.
OpenGL ES Supports most of the features of OpenGL (and some extra features for mobile devices). If I recall correctly the iPhone 3Gs supports fragment shaders, while the older iPhone 3G just supports a fixed pipeline.
On an iPhone:
If I am writing a game that has multiple levels, with multiple animations (image sequences), jpg and png (transparent), some full screen and some not, some looped and some played once only. What is the best way of doing it? Each level might have up to 10MB of images. Add on to this music, and video (cut scenes). All 2D graphics, no 3D models.
Is OpenGL required? Or can this be achieved with Quartz or Core Animation?
I do similar using UIViews and a bit of Core Graphics (Quartz 2D) and it works fine. I've found the custom drawing in Core Graphics pushes it a bit further, tho - UIViews work best when given images rather than having to draw themselves. Also watch out for lots of transparencies. You'll probably find that large or long (many frame) animations will be the killer, though. There are some techniques for minimising the impact of the animations which involves allowing it to purge images from memory if not being immediately displayed (I forget the setting). This may result in your animations not being as smooth as you they would otherwise be (not sure if Open GL ES would help here, though).
You should probably prototype using UIViews, and decide then if it's worth doing the extra work for OpenGL ES. Also, if you're not already familiar with OpenGL/ Open GL ES it's a steep learning curve.
I've used both Quartz and OpenGL to do graphics on the iPhone, and while OpenGL has a much higher learning curve, it gives much better performance than Quartz. Let's say you have a scene that involves drawing 6 large, semi-transparent images on top of each other. Quartz will do it, but you'll probably get 15fps at best. OpenGL takes advantage of the iPhone's PowerVR chip and the drawing is hardware accelerated - so you can load those images into OpenGL textures and render at 25-30fps no problem.
I would agree with Phil though - try doing it using Quartz and see if it meets your needs. OpenGL is extremely powerful but it's API lacks some of the convenience features of Quartz (such as saving/restoring graphics state).
One another note entirely, you might want to take a look at Unity's iPhone development tools (http://unity3d.com/#iphone). They leverage OpenGL but provide you with an IDE to create your game. It abstracts away all of the graphics-level code, so you can focus on the high-level gameplay. My brother uses it to write iPhone games, and it's extremely cool.
I recommend having a look at Cocos2D iPhone.
cocos2d for iPhone is a framework for building 2D games, demos, and other graphical/interactive applications. It is based on the cocos2d design: it uses the same API, but instead of using python it uses objective-c.
Most likely OpenGl.
One advantage of using OpenGL ES would be that the investment of time for learning the technology could be applied to other platforms/contexts and your game is potentially more port-friendly. These may not be important to you.
I would suggest using Quartz. OpenGL ES is really best for 3d stuff. However both work fairly well, so if you already know OpenGL ES, it's fine to use that.
You should consider using a lot of less resources in your game, Apple recommends not to use more than 10 mb in texture for openGL apps.
Try texture atlas, reuse graphics, tile based graphics...but avoid to use to much graphic assets.