1

I am making a 2D game for iOS using Kobold2D/cocos2D. Now i've decided to try and add some 3d buildings as well (think GTA1/2 everything is 2D except the buildings).

I know how OpenGL works but im getting all sorts of errors when try to implement this.

My questions is: Does cocos2d prevent me from using normal OpenGL calls ?,or should this work fine if its done correctly? Every tutorial/example i've found uses some cocos2d wrapper for mixing opengl and cocos..

If you have done this before (mix your own OpenGL ES 2.0 code with cocos2d) could you point me in the right direction?

user1033619
  • 1,757
  • 2
  • 11
  • 11

2 Answers2

1

As long as you're using cocos2d/Kobold2D v2.x you can use OpenGL ES 2.0. You can override/implement any CCNode class' -(void) draw method and hack away.

There's only one caveat: you should prefer to use the cocos2d provided "ccStuffStuff" methods (for example ccDrawColor) instead of the OpenGL ES methods because they wrap some behind the scenes stuff for performance reasons and compatibility. Check any existing cocos2d drawing code for examples. One such example would be the GLES-Render.cpp from cocos2d+Box2D projects, or the ccDrawingPrimitives.m file.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • Bah, what does this guy know about Cocos2D... TOTALLY JOKING, haha. Check out his book, it has some great info on the subject and between him, Riq and Ray they are the ones to ask or reference. ;-) – Mark McCorkle May 09 '13 at 19:08
0

You can simply simply display another oOenGL view over top of your previous one although if you are wanting to layer objects inside another engine (cocos2d) you are talking about adding to an existing CCLayer which is in itself another OpenGL layer. That's where you will have problems. What you may be able to do is sandwich 3 views together to get the effect. (1 CCLayer below your OpenGL view and one CCLayer above that). Then you can just leave the background color transparent on your 2 top views and it will appear as if they are all in one view.

UIColor *color = [UIColor clearColor];
CGColorRef layerBackgroundColor = [color CGColor];
[subLayer setBackgroundColor:layerBackgroundColor];
Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42