0
votes

I'm trying to insert an OpenGL ES 3D view in a Cocos2D app on the IPad. I'm relatively new to these frameworks, so I basically added those lines in my CCLayer:

CGRect rScreen;
// some code to define the bounds and origin of my frame
EAGL3DView * view3d = [[EAGL3DView alloc] initWithFrame:rScreen] ;

[[[CCDirector sharedDirector] openGLView] addSubview: view3d];

[view3d startAnimation]

The code I'm using for the 3D part is based on a sample code from Apple Developer : http://developer.apple.com/library/mac/#samplecode/GLEssentials/Introduction/Intro.html The only changes I made were to create my view programmatically (no xib file, initWithCoder -> initWithFrame...), and I also renamed the EAGLView class & files to EAGL3DView so as not to interfere with the EAGLView that comes along with Cocos2D.

Now onto my problem: when I run these, I get an "OpenGL error 0x0502 in -[EAGLView swapBuffers]", the 3D view being properly displayed but with a completely pink screen otherwise.

I went into the swapBuffers function in Cocos2d EAGLView, and it turns out the only block of code that is important is this one:

if(![context_ presentRenderbuffer:GL_RENDERBUFFER_OES])
    CCLOG(@"cocos2d: Failed to swap renderbuffer in %s\n", __FUNCTION__);

which btw does not enter the "if" condition (presentRenderbuffer does not return a null value, but is not correct though since the CHECK_GL_ERROR() afterwards gives an 0x0502 error).

So I understand that there is some kind of incorrect overriding of the OpenGL ES renderbuffer by my 3D view (since Cocos2d also uses OpenGL ES) causing the Cocos2D view not to work properly. This is what I got so far, and I can't figure out precisely what needs to be done in order to fix it. So what do you think?

Hoping this is only a newbie problem…

Pixelvore

1
Sounds like you're trying to setup two separate OpenGL views. I wouldn't recommend it, if it is at all possible on iOS. - LearnCocos2D

1 Answers

0
votes

I think the correct approach for what you are trying to do is:

  1. create your own custom CCSprite/CCNode class;

  2. put all the GL code that you are using from the Apple sample into that class (i.e., overriding the draw or visit method of the class).

If you want to try and make the two GL views work nicely together, you could try reading this post, which will explain how you associate different buffers to your views.

As to the first approach, have a look at this post and this one.

To be true, the first approach might be more complex (depending on how the Apple sample is doing open gl), but will use less memory and will be more optimized that the second.