Developers Manual > Cocos2d-x > Modules > Debugging > How to debug games for ipad retina on low-resolution PC

How to debug games for Ipad retina on low-resolution PC

When debugging mobile games, sometimes the resolution of the mobile device exceeds the resolution of monitor the developer is using. Example: Retina display Ipads have a resolution of 2048 x 1536.

GLView::setFrameZoomFactor function was born to resolve this issue.

The Principle

EGLView::setFrameZoomFactor resets the size of game window and the projection by multiplying a zoom factor.

On win32:

1
2
3
4
5
6
7
    void GLView::setFrameZoomFactor(float fZoomFactor)
    {
        m_fFrameZoomFactor = fZoomFactor;
        resize(m_obScreenSize.width * fZoomFactor, m_obScreenSize.height * fZoomFactor);
        centerWindow();
        Director::getInstance()->setProjection(Director::getInstance()->getProjection());
    }

GLView on win32, mac and linux also overrides two functions, setViewPortInPoints and setScissorInPoints.

When the projection is reset, GLView::setViewPortInPoints will be invoked.
The implementation of GLView::setViewPortInPoints is different from GLView::setViewPortInPoints.
All the parameters are multiply with m_fFrameZoomFactor.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    void GLView::setViewPortInPoints(float x , float y , float w , float h)
    {
        glViewport((GLint)(x * m_fScaleX * m_fFrameZoomFactor + m_obViewPortRect.origin.x * m_fFrameZoomFactor),
            (GLint)(y * m_fScaleY  * m_fFrameZoomFactor + m_obViewPortRect.origin.y * m_fFrameZoomFactor),
            (GLsizei)(w * m_fScaleX * m_fFrameZoomFactor),
            (GLsizei)(h * m_fScaleY * m_fFrameZoomFactor));
    }

    void GLView::setScissorInPoints(float x , float y , float w , float h)
    {
        glScissor((GLint)(x * m_fScaleX * m_fFrameZoomFactor + m_obViewPortRect.origin.x * m_fFrameZoomFactor),
                  (GLint)(y * m_fScaleY * m_fFrameZoomFactor + m_obViewPortRect.origin.y * m_fFrameZoomFactor),
                  (GLsizei)(w * m_fScaleX * m_fFrameZoomFactor),
                  (GLsizei)(h * m_fScaleY * m_fFrameZoomFactor));
    }

Also, while cocos2d-x get the touch events from system, we divide x and y of postion by m_fFrameZoomFactor.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    LRESULT EGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    {
        BOOL bProcessed = FALSE;

        switch (message)
        {
        case WM_LBUTTONDOWN:
    .....
            if (m_pDelegate && MK_LBUTTON == wParam)
            {
                POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)};
                Point pt(point.x, point.y);
                pt.x /= m_fFrameZoomFactor;  // added this line
                pt.y /= m_fFrameZoomFactor;  // added this line
                Point tmp = ccp(pt.x, m_obScreenSize.height - pt.y);
                if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp))
                {
                    m_bCaptured = true;
                    SetCapture(m_hWnd);
                    int id = 0;
                    handleTouchesBegin(1, &id, &pt.x, &pt.y);
                }
            }
            break;
    ................

Where to invoke GLView::setFrameZoomFactor?

This function can only be invoked in platform relative codes. e.g. proj.win32/main.cpp, proj.mac/AppController.mm and proj.linux/main.cpp.
Just adding one line code will enable this useful feature.

For example, on win32

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    int APIENTRY _tWinMain(HINSTANCE hInstance,
                           HINSTANCE hPrevInstance,
                           LPTSTR    lpCmdLine,
                           int       nCmdShow)
    {
        UNREFERENCED_PARAMETER(hPrevInstance);
        UNREFERENCED_PARAMETER(lpCmdLine);

        // create the application instance
        AppDelegate app;
        GLView* eglView = Director::getInstance()->getOpenGLView();
        eglView->setFrameSize(2048, 1536);
        // The resolution of ipad3 is very large. In general, PC's resolution is smaller than it.
        // So we need to invoke 'setFrameZoomFactor'(only valid on desktop(win32, mac, linux)) to make the window smaller.
        eglView->setFrameZoomFactor(0.4f);
        return Application::sharedApplication()->run();
    }

The result:

Now, you are able to debug large resolution game on low resolution desktop. Hope you join it. :)

HelloWorld2048x1536.jpg (154.8 kB) dumganhar, 2012-10-30 08:34

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.