Forum > C++ > How to resize Opengles Surface ?

How to resize Opengles Surface ?

By valentin.vit Posted 2011-07-05 13:59 Comments 1
valentin.vit
  • Posts: 16

Hello,

I am trying to resize the window and the opengl Surface;

I did the following modification in CCEGL_View_win32.cpp
1.In bool CCEGLView::Create(LPCTSTR pTitle, int w, int h)
i have added the resize button to the window
// create window
m_hWnd = CreateWindowEx(
WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // Extended Style For The Window
kWindowClassName, // Class Name
pTitle, // Window Title
WS_CAPTION | WS_POPUPWINDOW|**WS_MAXIMIZEBOX|WS_MINIMIZEBOX**,* // Defined Window Style
0, 0, // Window Position
0, // Window Width
0, // Window Height
NULL, // No Parent Window
NULL, // No Menu
hInstance, // Instance
NULL );
2.In LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)

I have added resize event and viewport size modifications .

case WM_SIZE:
{
//do
{
//wSizeType = wParam;
//nWidth = LOWORD (lParam);
//nHeight = HIWORD (lParam);
POINT pt = {(short)LOWORD (lParam), (short)HIWORD (lParam)};

resize(pt.x, pt.y);

CCSize size;
size.width=(float)pt.x*m_fScreenScaleFactor;
size.height=(float)pt.y*m_fScreenScaleFactor;

setViewPortInPoints(0, 0, size.width, size.height);
//glViewport(0, 0, size.width, size.height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
ccglOrtho(0, size.width, 0, size.height, –1024*m_fScreenScaleFactor,
1024*m_fScreenScaleFactor );
// Calculate The Aspect Ratio Of The Window

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

} //while (0);
}

The window is resized but the opengles surface does not.
What I am missing ?

I need to destroy the surface and recreate it ? It is not enough to change the viewport dimensions ?

yangws
  • Posts: 30

#1 RE: 2011-07-20 06:45

Yes, you need delete the CCEGL and recreate it.
Because the EGL has a frame buffer which’s size equal with window size, need recreate it after change the window size for make the size of frame buffer match the size of window.

Loggin to reply

Copyright © 2010 - 2013 Cocos2d-x.orgClustrmaps