Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Integrating SFML to Cocos2d-x?  (Read 3219 times)

0 Members and 1 Guest are viewing this topic.

kehvatsu

  • Newbie
  • *
  • Posts: 3
    • View Profile
Integrating SFML to Cocos2d-x?
« on: July 04, 2013, 11:13:49 pm »
Hi,

Is it possible to integrate SFML Events to Cocos2d-x OpenGL window? I can't get it to work because I don't understand enough of OpenGL to initialize SFML. Can I somehow initialize SFML window with already created Cocos2d-x OpenGL window? I'm only interested in receiving Events from SFML to use as input in my game.

This is the main game loop in Cocos2d-x:

int Application::run()
{

    PVRFrameEnableControlWindow(false);

    // Main message loop:
    MSG msg;
    LARGE_INTEGER nFreq;
    LARGE_INTEGER nLast;
    LARGE_INTEGER nNow;


    QueryPerformanceFrequency(&nFreq);
    QueryPerformanceCounter(&nLast);

    // Initialize instance and cocos2d.

    if (!applicationDidFinishLaunching())
    {
        return 0;
    }

    EGLView* pMainWnd = EGLView::sharedOpenGLView();
    pMainWnd->centerWindow();
    ShowWindow(pMainWnd->getHWnd(), SW_SHOW);

    while (1)
    {
        if (! PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            // Get current time tick.
            QueryPerformanceCounter(&nNow);

                        //CCLog("MAIN LOOP: %lld",nNow.QuadPart);

            // If it's the time to draw next frame, draw it, else sleep a while.
            if (nNow.QuadPart - nLast.QuadPart > _animationInterval.QuadPart)
            {
                nLast.QuadPart = nNow.QuadPart;
                Director::sharedDirector()->mainLoop();
            }
            else
            {
                Sleep(0);
            }
            continue;
        }

        if (WM_QUIT == msg.message)
        {
            // Quit message loop.
            break;
        }

        // Deal with windows message.
        if (! _accelTable || ! TranslateAccelerator(msg.hwnd, _accelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}

I tried to create the sf::RenderWindow like this:
sf::RenderWindow r_wnd;
r_wnd.create(pMainWnd->getHWnd());
 

But this only creates a black screen.

Any ideas?

Thanks.



« Last Edit: July 05, 2013, 08:38:12 am by Laurent »

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Integrating SFML to Cocos2d-x?
« Reply #1 on: July 05, 2013, 08:36:25 am »
I've no idea. I never used this framework.

But it seems that you're trying to create an SFML view inside an OpenGL view.. SFML don't reuse any view, it creates its own. That might explain why it fails.

Do you get an error message on sf::err() output? (Check your console.)
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Integrating SFML to Cocos2d-x?
« Reply #2 on: July 05, 2013, 08:43:39 am »
Quote
I'm only interested in receiving Events from SFML to use as input in my game.
Don't use SFML for that.

Doesn't Cocos2d-x provide events? You can also use Win32 events, since you're already writting Windows specific code.
Laurent Gomila - SFML developer

kehvatsu

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Integrating SFML to Cocos2d-x?
« Reply #3 on: July 05, 2013, 03:53:51 pm »
Thanks,

I decided to go with windows events. I just would have liked to make it cross-platform with SFML but that doesn't seem to be possible. Cocos2d-x is not designed for desktop use so it needs quite a bit of modifications. It has no support for right mouse button, mouse wheel, full screen, keyboard...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Integrating SFML to Cocos2d-x?
« Reply #4 on: July 05, 2013, 04:08:15 pm »
Quote
I just would have liked to make it cross-platform
Hmm, then there's a lof of work because the small piece of code that you posted is already full of Windows specific code :P
Laurent Gomila - SFML developer

 

anything