开发者

Advantages of using Core Graphics

开发者 https://www.devze.com 2023-04-10 19:34 出处:网络
I would like to know what kind of advantages I get from using Core Graphics instead of Open GL ES. My main question is based on this:

I would like to know what kind of advantages I get from using Core Graphics instead of Open GL ES. My main question is based on this:

  • Creating simple View animations.
  • Creating some visual appealing objects (Graphics like Core Plot for instance, Animated Objects, etc).
  • Time consuming (both learning and implementing)
  • Simple 2D Games
  • Complex 2D Games
  • 3D Games
  • Code maintenance ad also cleaner cod开发者_Go百科e.
  • Easier integration with other UI elements.

Thanks.


First, I want to clear up a little terminology here. When people talk about Core Graphics, they generally are referring to Quartz 2D drawing, which is a 2-D vector-based drawing API. It is used to draw out vector elements either to the screen or to offscreen contexts like PDFs. Core Animation is responsible for animation, layout, and some limited 3-D effects involving rectangular layers and UI elements. OpenGL ES is a lower-level API for talking with the graphics hardware on iOS devices for both 2-D and 3-D drawing.

You're asking a lot in your question, and the judgment on what's best in each scenario is subjective and completely up to the developer and their particular needs. I can, however, provide a few general tips.

In general, a recommendation you'll see in Apple's documentation and in presentations by engineers is that you're best off using the highest level of abstraction that solves your particular problem.

If you need to just draw a 2-D user interface, the first thing you should try is to implement this using Apple's provided UIKit elements. If they don't have the capability you need, make custom UIViews. If you are designing Mac-iOS cross-platform code (like in the Core Plot framework), you might drop down to using custom Core Animation CALayers. Each step down in this process requires you to write more code to handle things that the level above did for you.

You can do a surprising amount of stuff with Core Animation, with pretty good performance. This isn't just limited to 2-D animations, but can extend into some simple 3-D work as well.

OpenGL ES is underneath the drawing of everything you see on the screen for an iOS device, although this is not exposed to you. As such, it provides the least abstraction for onscreen rendering, and requires you to write the most code to get something done. However, it can be necessary in situations where you want to extract the most performance from 2-D display (say, in an action game) or to render true 3-D objects and environments.

Again, I tend to recommend that people start at the highest level of abstraction when writing an application, and only drop down when they find that they cannot do something or the performance is not within the specification they are trying to hit. Fewer lines of code makes applications easier to write, debug, and maintain.

That said, there are some nice frameworks that have developed around abstracting away OpenGL ES, such as cocos2D and Unity 3D, which might make working with OpenGL ES easier in many situations. For each case, you'll need to evaluate what makes sense for the particular needs of your application.


Basically, use OpenGL if you are making a game. Otherwise, use CoreGraphics. CoreGraphics lets you do simple things embedded in your normal UI code.

Creating simple View animations. -> CG

Creating some visual appealing objects (Graphics like Core Plot for instance, Animated Objects, etc). -> CG

Time consuming (both learning and implementing) -> OpenGL and CG are both kind of tough at first.

Simple 2D Games -> OpenGL

Complex 2D Games -> OpenGL

3D Games -> OpenGL

Code maintenance ad also cleaner code. -> Irrelevant

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号