I am developing iphone game using coregraphics. but the speed is very slow. I could not play my game.. So, I googled a lot.. During the googling, I found the belows.
CoreGraphics, CoreAnimation, OpenGL ES, CALayer, Quartz 2D
I am so confused between them. Someone told me coregraphics is not using GPU. Some told me it is using GPU. coregraphics is best or openGL is best, calayer is better. ^^;;;; What is different between them and which one is using GPU?? Which one is the best to make a game. I have many image to draw.
Please let me know..... Thanks in advance.
The iOS graphics APIs are layered. Even though some portion of the final render might go thru the GPU, most of the CoreGraphics drawing functions do not.
CoreAnimation does use the GPU, but the types of graphics operations within its API (transforms of existing image data mostly) is limited.
OpenGL ES uses the GPU, but (re)compiling any changes to the rendering pipeline is reported to be quite CPU intensive.
And anything that uploads new bitmaps, images or textures to the display pipeline appears to be both CPU and GPU intensive.
If you are writing a game, you may wish to look at SpriteKit if 2D and metal if 3D. Core graphics is for rendering high quality still content, but wasn’t intended as a game interface with massive FPS, unless your game resembles common app UI more than the typical game.
Related
I am working on a live multiplayer version of a pictionary like game. It will be like draw something except live with 4 players and not turn based.
is there a benefit to writing my drawing algorythm in OpenGL ES vs CoreGraphics (Quatz 2D) in this situation since i have to be sharing it among 4 players over a network? Or as far as performance goes?
From my own experience in game development... the main reason is performance. Simple 2D game was VERY slow with core graphics and VERY fast with OpenGL ES (1.1).
There was a lot of issues with the positioning of images, strange lines between tiles but at the end we managed to fix it all. In reality, we built a small library of functions very similar to core graphics, only simpler and faster.
Also, portability with OpenGL is simple, with Core Graphics impossible.
CoreGraphics only works on apple products. OpenGL could maybe be adapted to different platforms. I would say that also performances should be better.
Core graphics is not designed for fast, real time drawing or updates to screen. It is designed for high quality artwork, while OpenGL is designed for fast performance, though getting high-quality visuals can be a bit more challenging with OpenGL. It's a trade-off between these of performance and quality of rendered visuals.
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/
I want to create an iPhone/iPod game. I want it to be 3d, but I want to use sprites instead of OpenGL to do this (I assume this would be easier since I don't know OpenGL).
I was thinking of simply layering sprites over top of each other and changing their size to give an illusion of 3d. It doesn't need to be too convincing since the game will be somewhat cartoony.
How can I use sprites as an alternative to OpenGL on the iPhone platform?
You can use CoreAnimation for this. Either using UIImageViews (or plain UIViews) or CALayers.
It's usually the best choice for some types of 2d games (board games, for example), since animation, rotation and scaling are really easy. Just keep in mind that if performance is your concern, OpenGL will always be better.
Depending on how much 3d, I'd recommend taking a look at cocos2d. It supports multiple layers, sprites, animations, etc, but is pretty straightforward to pick up & learn. (Much easier than OpenGL to me) The example code is very comprehensive.
http://code.google.com/p/cocos2d-iphone/
I have built a game using core animation with upto about 17 - 20 objects floating about the screen scaling and rotating and performance was fine on the iPhone (make sure you check regularly on the iPhone as the simulator doesnt simulate iPhone memory or CPU speed).
CoreAnimation is pretty simple and really powerful. Use PNG's for images and I don't think you will have to many issues. The real killer of this will be alpha's in your images, this is hard work for the iPhone. So the less transparency you have the better you app will go.
In addition to Marco's answer I want to add: Not using OpenGL may also tax the device battery a little more. As I understand it, OpenGL ES can be more efficient on a device power supply (if implemented properly). Of course, this depends on how much animation is going to be used with UIImageView, UIView or CALayers, etc.
I'm sure there is a tipping point.
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.
I've seen a lot of bandying about what's better, Quartz or OpenGL ES for 2D gaming. Neverminding libraries like Cocos2D, I'm curious if anyone can point to resources that teach using OpenGL ES as a 2D platform. I mean, are we really stating that learning 3D programming is worth a slight speed increase...or can it be learned from a 2D perspective?
GL is likely to give you better performance, with less CPU usage, battery drain, and so on. 2D drawing with GL is just like 3D drawing with GL, you just don't change the Z coordinate.
That being said, it's easier to write 2D drawing code with Quartz, so you have to decide the trade-off.
Cribbed from a similar answer I provided here:
You probably mean Core Animation when you say Quartz. Quartz handles static 2-D drawing within views or layers. On the iPhone, all Quartz drawing for display is done to a Core Animation layer, either directly or through a layer-backed view. Each time this drawing is performed, the layer is sent to the GPU to be cached. This re-caching is an expensive operation, so attempting to animate something by redrawing it each frame using Quartz results in terrible performance.
However, if you can split your graphics into sprites whose content doesn't change frequently, you can achieve very good performance using Core Animation. Each one of those sprites would be hosted in a Core Animation CALayer or UIKit UIView, and then animated about the screen. Because the layers are cached on the GPU, basically as textures, they can be moved around very smoothly. I've been able to move 50 translucent layers simultaneously at 60 FPS (100 at 30 FPS) on the original iPhone (not 3G S).
You can even do some rudimentary 3-D layout and animation using Core Animation, as I show in this sample application. However, you are limited to working with flat, rectangular structures (the layers).
If you need to do true 3-D work, or want to squeeze the last bit of performance out of the device, you'll want to look at OpenGL ES. However, OpenGL ES is nowhere near as easy to work with as Core Animation, so my recommendation has been to try Core Animation first and switch to OpenGL ES only if you can't do what you want. I've used both in my applications, and I greatly prefer working with Core Animation.