Windows 8 DirectX and XAML

Is there anyone that can help me figure out how to create a Cocos2d-X project using SwapChainBackgroundPanel in order to combine DirectX and XAML? It appears that using XAML is about the only way of getting the soft keyboard to show on tablets (so all my custom input boxes are useless on Windows 8 tablets without keyboards).

Update

well, I’ve created a new project based upon the XAML/Direct2D template and included all Cocos2d-x sources in the project.

In DirectXPage.cpp I did the following:

  • create DirextXRender (the cocos2d renderer)
  • create the EAGLView
  • initialize the director
  • create and run HelloWorld
  • call the CCDirector::mainloop on every call to Render()

I also modified DirectXRender a bit to be more similar to the DirextXBase renderer (included in the template project). The program compiles and runs but the DIrectX screen (SwapChainBackgroundPanel) remains black. Driving me nuts!

I’ve doing some more trial and error combining of code and …. voila …… Cocos2d-X Helloworld behind a XAML window (see the attached screenshot).

Not really usable yet as the DirectX frame is flashing like crazy, but the overall idea is exactly what I’m looking for.

Update

Flickering solved. I was updating the frame even if there was nothing to update. Performance is now great and the flickering is gone. Next challange: making sure keyboard, mouse and touch get routed to the Cocos2D engine.

Hi Nibor,
I am looking for cocos2d-x + xaml solution too, and I found that you’ve done pretty well on it…
May I have a copy of your project so I can figure out how to make my own project work?
Here’s my mail: chanyuenpang@gmail.com, Thank you~

Yop Chan wrote:

Hi Nibor,
I am looking for cocos2d-x + xaml solution too, and I found that you’ve done pretty well on it…
May I have a copy of your project so I can figure out how to make my own project work?
Here’s my mail: chanyuenpang@gmail.com, Thank you~

It’s not really distributable yet. The project also uses hard references to files on my disk so it would not compile. Easiest thing to do would be to follow the steps from my first post. So create a new project from the XAML/DirectX template, include all cocos2d files, make sure all compiler options are the same, include all link libraries, etc. Make sure it compiles and runs with just the cocos files included in the project. Then modify the cocos file directXRender.cpp file to be similar to the template file DirectXBase (especially the part where the swapchain is linked to the panel!). Then in the DirectXPage.cpp do the things that you would do in appdelegate.cpp (create director, create eaglview, load scene). In de render() function you can call ccdirector::main loop() (at least that appears to be working). I still have to solve the problem that some classes do calls to sharedApplication (like ccmenu) but that results in a crash as ccapplication is not initialized (small problem to tackle). I also have to figure out how the new found XAML power can be harnessed from cocos.

OK…

Actually I am not familiar to neither cocos2d-x nor c++, thought I do handy on cocos2d and xaml(C#)…

I will try my best to make it follow what you’ve provided, but i think I will need your help~

I was able to get it working by using SwapChainBackgroundPanel in the xaml and some tweaks to the rendering example.
You can see it in action in my game, Noogra Nuts. I use the Xaml to show ads to the user.

Here’s my xaml:

And I’m calling the Render method of CCFrameWorkView on the “void GamePage::OnRendering(Object^ sender, Object^ args)” Method.

Oren Bengigi wrote:

I was able to get it working by using SwapChainBackgroundPanel in the xaml and some tweaks to the rendering example.
You can see it in action in my game, Noogra Nuts. I use the Xaml to show ads to the user.
>
Here’s my xaml:
>
[…]
>
And I’m calling the Render method of CCFrameWorkView on the “void GamePage::OnRendering(Object^ sender, Object^ args)” Method.

Thanks! I figured as much and that’s why I kept trying to get the SwapChainBackgroundPanel to function :wink: Using the render method of CCFrameWorkView I have not tried yet. I’ll try that tomorrow (that would indeed most likely solve the CCApplication “problem” (there is none in my solution ) I have now).

Yop Chan wrote:

OK…
>
Actually I am not familiar to neither cocos2d-x nor c**, thought I do handy on cocos2d and xaml…
>
I will try my best to make it follow what you’ve provided, but i think I will need your help~
Always willing to help you out . I do not think that you can use C# however. You still have to program all Cocos2d-x scenes using C**. This thread is mainly aimed at combining a DirectX view (i.e. Cocos2d-x) with XAML (C++ based) view, mainly to be able to invoke the soft keyboard on Windows 8 tablets (totally impossible with just a DirectX window).

I’ve setup the environment by importing the DirectXApp template to my cocos2d-x project, and the template itself runs well(I made the project start from App.xaml).

So the next step might be changing DirectXBase into DirectXRender, but there’s something wrong with the included files.

Every time when I include “DirectXRender.h” Error c4430 happens saying that “Error C4430: missing type specifier - int assumed”

This problem stop me from doing anything now, I’ve been trying myself for couple hours and the error still happens…

Can anyone help?

I’ve fixed early problem by putting everything in DirectXPage.cpp file.

I am modifying methods in DirectXRender to DirectXBase, and there still problems… not easy…

Yop Chan wrote:

I’ve fixed early problem by putting everything in DirectXPage.cpp file.
>
I am modifying methods in DirectXRender to DirectXBase, and there still problems… not easy…

I’ll upload my directxrender files and my directxpage.cpp later today when I’m at my computer. No need to trial and error to get to the same point I am :wink:

Yop Chan wrote:

I’ve fixed early problem by putting everything in DirectXPage.cpp file.
>
I am modifying methods in DirectXRender to DirectXBase, and there still problems… not easy…

Here are my versions (still not ready, but they do work).

How did you add the Template to your existing Cocos2d-X project? I’m quite new to VC so I took the hard road of manually importing all Cocos files in the Template project…

Seems like your files not working in my project…

How did you add the Template to your existing Cocos2d-X project? I’m quite new to VC so I took the hard road of manually importing all Cocos files in the Template project…

There are steps:

  1. move all necessary files into your project.
  2. right click app.xaml and set the property to “Application Definition”
  3. comment the original main function.

I’ll see if I can get the entire project zipped later today. What is the problem/error you are getting?

EDIT **
In my version there still is a problem with calls to CCApplication. I’ll fix that later today by using the solution Oren is using (or at least the solution I think he is using). My files would work for a simple Helloworld app, but if you use CCMenu for example, the app would crash due to an assert (CCApplication does not exist). So if you project uses CCMenu or any other calls to CCApplciation is it likely to crash.

I’ll see if I can get the entire project zipped later today. What is the problem/error you are getting?

That will be really helpful~

I’ve solve all the errors, I’ve get the background sound playing and touch events seems working either.
But the whole screen remains in black

I’ve zip my project and you may check on my DirectXPage.app, I am calling AppDelegate so the old logic needs not to be modified.

If you want I could check your project; you can mail a link and I’ll take a look. I’ll mail you a link to the testproject I made in a few minutes.

Did you link through to the SwapChainBackgroundPanel properly in DirectXRender.cpp ? (That’s where my mistake was when the screen stayed black).

Yop Chan wrote:

> I’ll see if I can get the entire project zipped later today. What is the problem/error you are getting?
>
That will be really helpful~
>
I’ve solve all the errors, I’ve get the background sound playing and touch events seems working either.
But the whole screen remains in black
>
I’ve zip my project and you may check on my DirectXPage.app, I am calling AppDelegate so the old logic needs not to be modified.

I think I’ve accomplish my goal and make every thing goes well.

Here’s my cocos2d-x + xaml template in github:

Yop Chan does your project supports multiple screen resolutions?

Thanks,

I’m willing to integrate a regular Cocos2dx-2.1.0-wp8-2.0-alpha.zip (https://cocos2d-x.googlecode.com/files/Cocos2dx-2.1.0-wp8-2.0-alpha.zip) project with a XAML page.

Could you help me?

Thanks.

any similar template for windows phone 8??

thank you,