Log in or register to post comments

Cocos2d and QCAR project integration

October 5, 2011 - 11:38am #1

Hello,

We have a cocos2d game. We want to add QCAR. Can we do it? We tried integrating both but faced issue as both uses OpenGL View (EaglView). Is there any solution to it?

Your prompt response will be appreciated.

-Bhabani
:cool:

Cocos2d and QCAR project integration

March 26, 2015 - 6:56am #20

One key thing to note per the documentation for UIGLViewProtocol.h for vuforia 4 (& presumably for versions before that); QCAR traverses the view hierarchy looking for a UIView that responds to selector renderFrameQCAR; if none is found then its up to you to render your QCAR frames.  I was getting OpenGL errors when trying to run cocos3d and QCAR simultaneously (cocos3d with transparent background on top of qcar), and by simply commenting out the renderFrameQCAR method; I now get my Cocos3d scene showing, while at the same time receiving notifications in the console for events like "Completed CloudReco transaction with ID ...".

As is discussed earlier in the thread, I believe you can take the camera pixels from QCAR and render them as a background cocos3d scene or something like that.

Re: Cocos2d and QCAR project integration

May 25, 2012 - 12:58pm #19
imanust wrote:

I am facing same problem with integrating QCAR and cocos2d, anyone else successfully with that? can share some advise how to manage EAGLView class of cocos2d and QCAR library?

I managed to connect it somehow (I didn't subclass the EAGLView or anything like that), this is tutorial how I did it for cocos3d, but in my case it didn't perform very well, framerate was only ~24 FPS and the tracking alignment hasn't been tweaked yet:
http://www.cocos2d-iphone.org/forum/topic/31918

There is also a sample project that James_bur made and uploaded following the instructions.

If you have suggestions for improvements it would be nice to post them here or on cocos forums.

Re: Cocos2d and QCAR project integration

May 11, 2012 - 12:53am #18

I am facing same problem with integrating QCAR and cocos2d, anyone else successfully with that? can share some advise how to manage EAGLView class of cocos2d and QCAR library?

Re: Cocos3d and QCAR project integration

April 22, 2012 - 5:36am #17

I see that some of you managed to combine cocos with qcar SDK, I need to do the same thing (combining cocos3d and Vuforia for iOS) and I'm starting from scratch.

So can you give me some tips and pointers what is the best way to start.
Should I first start with the cocos3d template and then add the qcar framework or the other way around.
And it seems that it is better to rename the cocos EAGLView class (less problems later) but where do I connect them (or should I do it some other way?). In the AppDelegate class maybe?

Thank you in advance for the help.

Re: Cocos2d and QCAR project integration

November 16, 2011 - 5:47am #16

@soldmedow : I had done things what you had suggested but now I am getting this error "Failed to make complete framebuffer object 8cd6".
And application is hanging in the CCDirector Class.

Re: Cocos2d and QCAR project integration

November 15, 2011 - 5:59am #15

@soldmeadow : I am working on same thing. i.e integrating cocos3d with Qualcomm SDK in ImageTarget Demo. But, I am facing error as the two EAGLViews conflicts with each other. I have errors in CCDirector as cocos3d's EAGLView is set by the [director setOpenGLView:eaglview]; I have done all things to set up the EAGLView problem. but still the problem remains the same. Help me with this.

Re: Cocos2d and QCAR project integration

November 8, 2011 - 9:42pm #14

@ksiva - thanks for the info, I didn't know about turning off the video background using configureVideoBackground. At present I'm using QCAR::Renderer::getInstance().begin().

@zakharm - I started using pure cocos2d and then moved to cocos3d as I wanted to display 3d models loaded from a pod file.

Re: Cocos2d and QCAR project integration

November 4, 2011 - 6:54am #13

@soldmeadow

http://ar.qualcomm.at/node/2000847

Here's one example of use (from Kim as well).

Re: Cocos2d and QCAR project integration

November 4, 2011 - 6:31am #12
soldmeadow wrote:

I've integrated cocos2d and Qcar. Unfortunately the code was written for a client so I can't release it.

@soldmeadow, is your implementation straight 2D or are you running cocos3D?

Re: Cocos2d and QCAR project integration

November 2, 2011 - 8:43pm #11
Quote:

It would be nice if Qcar had a pull type API where you could just request the pixels of the camera and the matrices (and make it thread safe so developers don't have to worry about that) when you want them rather than having them pushed to you in the EAGLView.

You can get the camera pixels for each frame from the State object. See the following methods:

State::getFrame()
Frame::getNumImages()
Frame::getImage(int idx)
Image::getFormat()
Image::getPixels()
QCAR::setFrameFormat(PIXEL_FORMAT format, bool enabled)

You can get the State object in one of two ways:

1) Returned by QCAR::Renderer::getInstance().begin(). Typically this call also draws the video background, but you can turn that off in the configureVideoBackground method by setting config.mEnabled to false.

2) Provided by the QCAR::UpdateCallback, each time the tracking cycle has finished. See the VirtualButtons sample for usage.

- Kim

Re: Cocos2d and QCAR project integration

November 1, 2011 - 9:14pm #10

I've integrated cocos2d and Qcar. Unfortunately the code was written for a client so I can't release it.

My basic approach was to create a subclass of cocos2d's EAGLView that adds the renderFrameQCAR method and then modify the cocos2d start up code to use my subclass rather than its standard EAGLView.

Then in my renderFramQCAR method I update an OpenGL texture with the pixels from the camera feed. You have to be very careful here because Qcar is running on another thread. Look at cocos2d's asynchronous texture loading methods to get an idea of what you need to do with autorelease pools and shared contexts. NB: this is really important ;) it can screw you up in the most unpleasant way, you need to be au fait with multithreading issues on iOS and OpenGL.

Finally I have a CCSprite based on the camera feed texture and just use that like any other sprite.

The advantage of this approach is that you can manipulate the camera feed sprite like any other cocos2d CCNode so it can take part in scene transitions.

At first I wasn't sure whether the performance would be adequate but it is, particularly on iPhone 4 and 4S.

You can create a custom draw method in a CCLayer that applies the projection and model view matrices prior to rendering your CCNodes.

I think you are in for a world of pain if you try the two EAGLView approach. It is proving hard to get cocos2d to work with two EAGLViews that it owns (for example to support an external display) let alone integrating an EAGLView controlled by another API. Even if you do get it to work you still have the issue of not being able to apply cocos2d scene transitions to the camera feed.

It would be nice if Qcar had a pull type API where you could just request the pixels of the camera and the matrices (and make it thread safe so developers don't have to worry about that) when you want them rather than having them pushed to you in the EAGLView. This would make it much easier to integrate with cocos2d.

Re: Cocos2d and QCAR project integration

October 27, 2011 - 8:16am #9

Hello All,

Due to the time factor, we released the game without QCAR AR. Now, we would like to integrate it. MoSR, We had tried your suggestion of rendering QCAR and cocos2D on two different views, passing the pose data from QCAR to the cocos2D view earlier, but we faced the same error "BAD_ACCESS".

During these period, did anyone try to integrate Cocos2d and Qcar?

Looking forward to get some solution this time..

-Bhabani

Re: Cocos2d and QCAR project integration

October 12, 2011 - 12:40am #8

Too avoid a massive integration effort it may well be more productive (if it's actually possible) to render QCAR and cocos2D on two different views, passing the pose data from QCAR to the cocos2D view. The cocos2D view would need to have a translucent background to see through to the QCAR view. The views should be siblings in a parent view. This was one of the ideas I suggested to Bhabanee earlier.

Re: Cocos2d and QCAR project integration

October 11, 2011 - 8:54pm #7

hi,bhabanee
thanks for ur information.
since the issue is not about OPENGLES version,maybe conflict happend on realtime rendering.
it seems that QCAR and COCOS2D implement OPENGLES drawing in their own thread.perhapse multithread concurrent call OPENGLES drawing method trigger some strange conflict.
to get more ideas ,i hv to go deeper in COCOS2D source code.it may take a long time.hope we are all lucky.
thanks again.

Re: Cocos2d and QCAR project integration

October 11, 2011 - 8:25am #6

Hello Holyspot,

We had earlier tried following things.

1. Use OPENGLES V1 in cocos2d and OPENGLES V1 in QCAR
2. Use OPENGLES V1 in cocos2d and OPENGLES V2 in QCAR

Both the settings, gave us the same error "EXC_BAD_ACCESS".

Please do let me know if you find any other solution.

Regards,
Bhabani

Re: Cocos2d and QCAR project integration

October 10, 2011 - 11:39pm #5

hi,bhabanee
"EXC_BAD_ACCESS Error on accessing opengl methods".
This is also happend in my project if there is no view swtiching by touch screen.
So I guess there are some conflict in the opengl rendering.
1.QCAR use OPENGES2.0 by default
2.COCOS2D_iphone use OPENGLES1.1
3.these two are quite different in programming.
Later I will try OPENGLES1.1 in QCAR and hope to find some clue.

Re: Cocos2d and QCAR project integration

October 10, 2011 - 8:02am #4

Thanks Holyspot for your response. In my project, i can not rename Eaglview of cocos2d as lot of other frameworks are using it. However, i have renamed Eaglview of QCAR to Eaglownview.

Now, the main issue is, i can not destroy one view and use the other. My requirement asks me to use both the view at one time. If i comment one and use other view, it works fine. But, if i use both then we get EXC_BAD_ACCESS Error as both Eaglview (cocos2d) and Eaglownview (Qcar) accessing opengl methods. Hence there is a chance that one is allocating / initializing some object and other is releasing by accident.

Following is my code. Please check if you can help me out. We have been trying since long time to integrate Qcar. No solution yet. Hope to get some solution from you.

- (BOOL)application : (UIApplication *)application didFinishLaunchingWithOptions : (NSDictionary *)launchOptions
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];

window = [[UIWindow alloc] initWithFrame : screenBounds];

#pragma mark camera View
CGRect screenBounds = [[UIScreen mainScreen] bounds];

CGRect viewBounds;
viewBounds.origin.x = 0;
viewBounds.origin.y = 0;
viewBounds.size.width = screenBounds.size.height;
viewBounds.size.height = screenBounds.size.width;

// QCAR Eaglview
EAGLownView = [[EAGLViewOwn alloc] initWithFrame : viewBounds];

overlayViewNew = [[OverlayViewNew alloc] initWithFrame: screenBounds];
overlayviewControllerNew = [[OverlayViewControllerNew alloc] init];
[overlayviewControllerNew setView : overlayViewNew];

// Set the QCAR EAGLView's position (its centre) to be the centre of the window
CGPoint pos;
pos.x = screenBounds.size.width / 2;
pos.y = screenBounds.size.height / 2;
[[EAGLownView layer] setPosition : pos];

// Rotate the QCAR EAGLView by 90 degress (landscape to portrait)
CGAffineTransform rotate = CGAffineTransformMakeRotation(90 * M_PI / 180);
EAGLownView.transform = rotate;
[EAGLownView onCreate];
[EAGLownView setUserInteractionEnabled:NO];
[window addSubview : EAGLownView];

[window addSubview : overlayviewControllerNew.view];
[overlayviewControllerNew release];
[window makeKeyAndVisible];
[overlayviewControllerNew.view removeFromSuperview];
[overlayviewControllerNew.view release];

/*************************************************************************************************/
/*We can not destroy / remove view neither EAGL View of QCAR nor Cocos 2d as we need both the views to be shown*/
/*************************************************************************************************/

//Following code is for creating COCOS2D Eaglview
if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
[CCDirector setDirectorType:kCCDirectorTypeDefault];

CCDirector *director = [CCDirector sharedDirector];
rootViewControllerNew = [[RootViewController alloc] initWithNibName:nil bundle:nil];
rootViewControllerNew.wantsFullScreenLayout = YES;

EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
pixelFormat:kEAGLColorFormatRGBA8 // kEAGLColorFormatRGBA8
depthFormat:0];

//Following code is for adding Eaglview to CCDirector
[director setOpenGLView:glView];
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
[director setAnimationInterval:1.0/60];
[director setDisplayFPS:YES];

[CCDirector sharedDirector].openGLView.backgroundColor = [UIColor clearColor];
[CCDirector sharedDirector].openGLView.opaque = NO;
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);

[rootViewControllerNew setView:glView] ;
[window addSubview:rootViewControllerNew.view];
[rootViewControllerNew.view addSubview:EAGLownView];
[window makeKeyAndVisible];

[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

//Following code is for running our scene class into CCDirector
[[CCDirector sharedDirector] runWithScene: [mainMenuFG scene]];

return YES;
}

Re: Cocos2d and QCAR project integration

October 10, 2011 - 2:06am #3

Thanks for your advice to Bhabani, holyspot. Let us know how your investigation proceeds - it would be good to post a definitive 'how to' for other cocos2d developers.

Re: Cocos2d and QCAR project integration

October 7, 2011 - 6:41pm #2

hi,Bhabani
my project comprise both tech.
basically,u have to change the EaglView class name in cocos2d to another because QCAR search the EAglView class from rendering in runtime.
and because QCAR is written in c++,so u may have to change some files in your game from .m to .mm.
in my project ,i change the app scene by switch both view(EaglView of QCAR and another of cocos2d)
and now my project can run with a little issue(topic “error when switch to another animation scene” in this forum)
hope this can help.

bhabanee wrote:

Hello,

We have a cocos2d game. We want to add QCAR. Can we do it? We tried integrating both but faced issue as both uses OpenGL View (EaglView). Is there any solution to it?

Your prompt response will be appreciated.

-Bhabani
:cool:

Log in or register to post comments