OpenGL View

OpenGL View

Overview

The cocos2d-x engine use GLView and GLViewImpl to creating window with OpenGL/OpenGL ES context and receiving input and events. GLView is an abstract class and GLViewImpl is its subclass which really do the things. In different platforms GLViewImpl are not the same.

Steps of Hook

If you want to have you own GLViewImpl you can do according to the following steps (The example is on windows platform, plain Win32 is used for window and input management, and WGL (with extensions) is used to create contexts).

1.Write a new GLViewImpl

Note:In order to avoid the conflict with the default GLViewImpl provided by engine, your GLView subclass name should not be the same with GLViewImpl, so in the example we names it GLViewNew.You can download the file to get the details and there are some important things you should pay attention to.

You need at least to achieve the following functions:


 
1
2
3
4
5
6
7
static GLViewNew* create (const std:: string& viewName); //a static method, create window and OpenGL context and also set event callbacks
void pollEvents() override; // event processing (window and input)
bool isOpenGLReady() override; 
void swapBuffers() override; //usually we use double buffer
void end() override; //called by Director::end(),in this function we should make windowShouldClose() return true, so that the loop can exit
bool windowShouldClose() override; //very important,the key whether mainloop could exits normally, and we need to make sure that when we close the window manually the function can return true to exit mainloop
HWND getWin32Window() override; //return the window handle

2.Add the files to your projects and include the head file in appDelegate.cpp

3.Modefy the code in appDelegate.cpp


 
1
2
3
4
5
6
7
8
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewNew::create("My Game");//use GLViewNew instead of GLViewImpl
        director->setOpenGLView(glview);
    }

Now you have your own GLView implement,you can create any type of window and context you want,enjoy it.And we are going to provide an interface to make context attributions setting easyly.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值