Another
eglGetDisplay example.
void
CXXXView::OnInitialUpdate()
{
CView::OnInitialUpdate();
if
(m_eglDisplay != EGL_NO_DISPLAY)
return
;
const
EGLint attrs[] = {
EGL_LEVEL, 0,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NATIVE_RENDERABLE, EGL_FALSE,
EGL_DEPTH_SIZE, EGL_DONT_CARE,
EGL_NONE
};
EGLint numConfig =0;
m_eglDisplay = eglGetDisplay(GetDC()->GetSafeHdc());
if
(m_eglDisplay == EGL_NO_DISPLAY)
if
((m_eglDisplay = eglGetDisplay((EGLNativeDisplayType) EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY)
return
;
EGLint major = 0;
EGLint minor = 0;
if
(!eglInitialize(m_eglDisplay, &major, &minor))
return
;
if
(major < 1 || minor < 3)
{
printf
(
"System does not support at least EGL 1.3 \n"
);
return
;
}
EGLConfig eglConfig;
if
(!eglChooseConfig(m_eglDisplay, attrs, &eglConfig, 1, &numConfig))
return
;
if
((m_eglSurface = eglCreateWindowSurface(m_eglDisplay, eglConfig, (EGLNativeWindowType) GetSafeHwnd(), NULL)) == EGL_NO_SURFACE)
return
;
EGLint ai32ContextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
if
((m_eglContext = eglCreateContext(m_eglDisplay, eglConfig, EGL_NO_CONTEXT, ai32ContextAttribs)) == EGL_NO_CONTEXT)
return
;
if
(!eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext))
return
;
glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
}
void
CXXXView::PostNcDestroy()
{
eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroyContext(m_eglDisplay, m_eglContext);
eglDestroySurface(m_eglDisplay, m_eglSurface);
eglTerminate(m_eglDisplay);
CView::PostNcDestroy();
}
void
CXXXView::onDraw(
void
)
{
glClear(GL_COLOR_BUFFER_BIT);
IGameImporter * gameImport = NULL;
auto pDoc = GetDocument();
if
(pDoc && pDoc->IsKindOf(RUNTIME_CLASS(CXXXDoc)))
gameImport =
dynamic_cast
<cxxxdoc *=
""
> (pDoc)->getGameImport();
eglSwapBuffers(m_eglDisplay, m_eglSurface);
}
BOOL
CXXXView::OnEraseBkgnd(CDC* pDC)
{
return
FALSE;
}
void
CXXXView::OnSize(
UINT
nType,
int
cx,
int
cy)
{
CView::OnSize(nType, cx, cy);
glViewport(0, 0, cx, cy);
}
BOOL
CXXXApp::OnIdle(
LONG
lCount)
{
CMainFrame * pFrame = (CMainFrame *) AfxGetMainWnd();
CView * pView = pFrame->GetActiveView();
if
(pView && pView->IsKindOf(RUNTIME_CLASS(CXXXView)))
dynamic_cast
<cxxxview *=
""
> (pView)->onDraw();
return
TRUE;
}
#define WM_TVN_SELCHANGED (WM_USER+3)
class
CViewTree :
public
CTreeCtrl
{
public
:
afx_msg
void
OnTvnSelchanged(NMHDR *pNMHDR,
LRESULT
*pResult);
};
BEGIN_MESSAGE_MAP(CViewTree, CTreeCtrl)
ON_NOTIFY_REFLECT(TVN_SELCHANGED, &CViewTree::OnTvnSelchanged)
END_MESSAGE_MAP()
void
CViewTree::OnTvnSelchanged(NMHDR *pNMHDR,
LRESULT
*pResult)
{
LPNMTREEVIEW pNMTreeView =
reinterpret_cast
<lpnmtreeview>(pNMHDR);
GetParent()->SendNotifyMessage(WM_TVN_SELCHANGED, (
WPARAM
) pNMTreeView, (
LPARAM
) pResult);
*pResult = 0;
}