I have been working with cocos2dx for the past couple of months and have grown to like it a lot! But if there is one area where it could be lacking is its ability to build UI (preferably using some form of vector graphics).
To do this we have been looking at an engine called Noesis (that is based on XAML) that has the ability to build and render UI. It also claims that it can be used with any openGL pipeline and has been integrated with a few openGL based Game engines successfully. There is a GLKit integration with Noesis already!
The idea here is to subclasss “Node” and to create a draw function that uses Noesis’ renderer to perform the drawing commands. The draw function can be called by the scene’s draw function adding the custom node.
The recommended drawing flow (as guided by the author of Noesis) was the following.
// Offscreen
xamlRenderer->Render(commands.offscreenCommands.GetPtr());
// Draw scene with cocos2d
// Render GUI on top of cocos scene
xamlRenderer->Render(commands.commands.GetPtr());
//Invalidate cocos state
cocos2d::GL::invalidateStateCahche()
I got the Noesis Library (lib.a) and the header files and was able to successfully include and link it with my xcode project running cocos2dx. But im facing run time issues (crashes) when i try to render the xaml. The following code shows how i have set my draw functions for my XAML node and following that is the screenshot for the errors im getting!
Has anybody successfully tried this integration before? If not what am i doing wrong and what needs to be done to get this to work?
void MyXAMLNode::loadElement(){
Noesis::PtrNoesis::FrameworkElement xaml=Noesis::GUI::LoadXamlNoesis::FrameworkElement(“Tux.xaml”);
xamlRenderer = Noesis::GUI::CreateRenderer(xaml.GetPtr());
}
void MyXAMLNode::drawRenderCommands(){
xamlRenderer->SetSize(this->getContentSize().width , this->getContentSize().height); Noesis::GUI::Tick();
static Noesis::Float64 t; t += 1/60; xamlRenderer->Update(t);
xamlRenderer->Render(xamlRenderer->WaitForUpdate().commands.GetPtr());
cocos2d::GL::invalidateStateCache();
}
void MyXAMLNode::drawOffScreenCommands(){
xamlRenderer->Render(xamlRenderer->WaitForUpdate().offscreenCommands.GetPtr());
xamlRenderer->SetSize(this->getContentSize().width , this->getContentSize().height); Noesis::GUI::Tick();
static Noesis::Float64 t; t += 1/60; xamlRenderer->Update(t);
}