Search code examples
cocos2d-x

cocos2d-x 3.7 Initialize with hwnd


I'm going to make some tools for game using cocos2d. but i couldn't find any function to bind hwnd as cocos2d render window.

isn't there any functions like GLView::setHwnd or some way to archieve what i want?

my cocos2d-x version is 3.7.


Solution

  • The built in GLView is not going to support being initialized with an external hwnd.

    However the Cocos2d-x director is initialzied with a user created GLView, so all you need to do is specialize GLView / GLViewImpl, create and initialize your specialized GLView and pass that when initializing Cocos:

    auto director = Director::getInstance();
    auto glView = MyGLView::create();
    glView->initWithExternalHWND(_hwnd);
    director->setOpenGLView(glView);
    auto scene = MyScene::create();
    director->runWithScene(scene);