📄 opengles2_0_egl_demo.cpp
字号:
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_HELP_ABOUT:
DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
break;
#ifndef SHELL_AYGSHELL
case IDM_FILE_EXIT:
DestroyWindow(hWnd);
break;
#endif // !SHELL_AYGSHELL
#ifdef WIN32_PLATFORM_PSPC
case IDM_OK:
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
#endif // WIN32_PLATFORM_PSPC
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_CREATE:
#ifndef SHELL_AYGSHELL
g_hWndCommandBar = CommandBar_Create(g_hInst, hWnd, 1);
CommandBar_InsertMenubar(g_hWndCommandBar, g_hInst, IDR_MENU, 0);
CommandBar_AddAdornments(g_hWndCommandBar, 0, 0);
#endif // !SHELL_AYGSHELL
#ifdef SHELL_AYGSHELL
SHMENUBARINFO mbi;
memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hWnd;
mbi.nToolBarId = IDR_MENU;
mbi.hInstRes = g_hInst;
if (!SHCreateMenuBar(&mbi))
{
g_hWndMenuBar = NULL;
}
else
{
g_hWndMenuBar = mbi.hwndMB;
}
// Initialize the shell activate info structure
memset(&s_sai, 0, sizeof (s_sai));
s_sai.cbSize = sizeof (s_sai);
#endif // SHELL_AYGSHELL
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
#ifndef SHELL_AYGSHELL
CommandBar_Destroy(g_hWndCommandBar);
#endif // !SHELL_AYGSHELL
#ifdef SHELL_AYGSHELL
CommandBar_Destroy(g_hWndMenuBar);
#endif // SHELL_AYGSHELL
PostQuitMessage(0);
break;
#if defined(SHELL_AYGSHELL) && !defined(WIN32_PLATFORM_WFSP)
case WM_ACTIVATE:
// Notify shell of our activate message
SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
break;
case WM_SETTINGCHANGE:
SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
break;
#endif // SHELL_AYGSHELL && !WIN32_PLATFORM_WFSP
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
#ifndef SHELL_AYGSHELL
RECT rectChild, rectParent;
int DlgWidth, DlgHeight; // dialog width and height in pixel units
int NewPosX, NewPosY;
// trying to center the About dialog
if (GetWindowRect(hDlg, &rectChild))
{
GetClientRect(GetParent(hDlg), &rectParent);
DlgWidth = rectChild.right - rectChild.left;
DlgHeight = rectChild.bottom - rectChild.top ;
NewPosX = (rectParent.right - rectParent.left - DlgWidth) / 2;
NewPosY = (rectParent.bottom - rectParent.top - DlgHeight) / 2;
// if the About box is larger than the physical screen
if (NewPosX < 0) NewPosX = 0;
if (NewPosY < 0) NewPosY = 0;
SetWindowPos(hDlg, 0, NewPosX, NewPosY,
0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
#endif // !SHELL_AYGSHELL
#ifdef SHELL_AYGSHELL
{
// Create a Done button and size it.
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
}
#endif // SHELL_AYGSHELL
return (INT_PTR)TRUE;
case WM_COMMAND:
#ifndef SHELL_AYGSHELL
if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
#endif // !SHELL_AYGSHELL
#ifdef SHELL_AYGSHELL
if (LOWORD(wParam) == IDOK)
#endif
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
case WM_CLOSE:
EndDialog(hDlg, message);
return (INT_PTR)TRUE;
}
return (INT_PTR)FALSE;
}
void initializeEGL()
{
EGLint config_list[] = {
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5,
#if defined(OPENGLES_TEST)
EGL_DEPTH_SIZE, 24,
#endif
EGL_NONE
};
EGLint num_config;
g_dpy = GetDC(gHWND);
display = eglGetDisplay(g_dpy);
if (eglInitialize(display, NULL, NULL) == EGL_FALSE || eglGetError() != EGL_SUCCESS)
{
printf("eglInitialize Error!\r\n");
return;
}
eglChooseConfig(display, config_list, &config, 1, &num_config);
eglBindAPI(EGL_OPENGL_ES_API);
surface = eglCreateWindowSurface( display, config, (NativeWindowType)(gHWND) , NULL);
if ( surface == EGL_NO_SURFACE || eglGetError() != EGL_SUCCESS )
{
printf("eglCreateWindowSurface Error!\r\n");
return ;
}
context = eglCreateContext( display, config, NULL, NULL );
if ( context == EGL_NO_CONTEXT || eglGetError() != EGL_SUCCESS )
{
printf("eglCreateContext Error!\r\n");
return ;
}
if ( eglMakeCurrent( display, surface, surface, context ) == EGL_FALSE || eglGetError() != EGL_SUCCESS )
{
printf("eglMakeCurrent Error!\r\n");
return;
}
}
void deinitializeEGL()
{
eglMakeCurrent (display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroySurface(display, surface);
eglDestroyContext(display, context);
eglTerminate(display);
ReleaseDC(gHWND, (HDC)g_dpy);
}
void render()
{
HDC memdc;
HBITMAP bitmap;
RECT rect;
int width, height;
#if 0
GetClientRect( gHWND, &rect );
width = rect.right - rect.left;
height = rect.bottom - rect.top;
bitmap = CreateCompatibleBitmap((HDC)display, width, height);
#endif
DemoList[selectedDemo].pfnRender();
// glFlush ();
eglSwapBuffers(display, surface);
#if 0
glClearColor( 1.0f, 0.0f, 0.0f, 1.0f ); // Red
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
eglSwapBuffers(display, surface);
glClearColor( 0.0f, 1.0f, 0.0f, 1.0f ); // Green
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
eglSwapBuffers(display, surface);
glFinish();
eglWaitGL();
eglCopyBuffers( display, surface, bitmap ); // Get Red Buffer
/*
glClearColor( 0.0f, 1.0f, 0.0f, 1.0f ); // Green
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glFinish();
eglWaitGL();
eglCopyBuffers( display, surface, bitmap ); // Still Get Red Buffer, not Green Buffer
*/
//eglCopyBuffers(display, surface, bitmap);
memdc = CreateCompatibleDC( (HDC)display );
SelectObject( memdc, bitmap );
BitBlt( (HDC)display, 0, 0, width, height, memdc, 0, 0, SRCCOPY );
#endif
// printf("[%d] demo eglSwapBuffers Done\n", selectedDemo);
if (EGL_SUCCESS != eglGetError())
{
RETAILMSG(1, (TEXT("eglSwapBuffers error: %x\r\n"), eglGetError()));
}
DeleteDC( memdc );
DeleteObject( bitmap );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -