-
bool CEglClass::InitGLES(void *hwnd)
-
{
-
EGLConfig configs[10];
-
EGLint matchingConfigs;
-
EGLint configAttribs[] = {
-
EGL_SURFACE_TYPE, EGL_PIXMAP_BIT,
-
EGL_CONFORMANT, EGL_OPENGL_ES_BIT,
-
EGL_NONE
-
};
-
EGLint aEGLContextAttributes[] = {
-
EGL_CONTEXT_CLIENT_VERSION, 1,
-
EGL_NONE
-
};
-
m_hwnd = hwnd;
-
m_hdc = ::GetDC((HWND)m_hwnd);
-
EGLDisplay glesDisplay = eglGetDisplay((NativeDisplayType)m_hdc); if(!eglInitialize(glesDisplay, NULL, NULL))
-
{
-
timeLogger.Log(_T(“eglInitialize Failed!”));return false;
-
}
-
EGLint buffersize = 0;
-
EGLint config_num = 0;
-
eglGetConfigs(glesDisplay, configs, 10, &config_num);
-
eglGetConfigAttrib(glesDisplay, configs[0], EGL_BUFFER_SIZE, &buffersize);
-
timeLogger.Log(_T(“display buffer size is %d\n”), buffersize);
-
eglChooseConfig(glesDisplay, configAttribs, NULL, 10, &matchingConfigs); if(!eglChooseConfig(glesDisplay, configAttribs, &configs[0], 10, &matchingConfigs))
-
{return false;
-
}
-
-
EGLint surfaceAttr[] =
-
{//EGL_RENDER_BUFFER,
-
EGL_SINGLE_BUFFER, //EGL1.1不支持,支持的话开了这个直接用glFlush就可以了
-
EGL_NONE
-
};
-
EGLSurface glesSurface = eglCreateWindowSurface(glesDisplay, configs[0], (NativeWindowType)m_hwnd, surfaceAttr); if(!glesSurface)
-
{
-
EGLint errCode = eglGetError();
-
tstring err;switch (errCode)
-
{case EGL_NO_SURFACE:
-
err = _T(“no surface”);break;case EGL_BAD_DISPLAY:
-
err = _T(“bad display”); break;case EGL_BAD_CONFIG:
-
err = _T(“bad config”); break;case EGL_BAD_ATTRIBUTE:
-
err = _T(“bad ATTRIBUTE”); break;case EGL_BAD_MATCH:
-
err = _T(“bad Match”); break;
-
}
-
timeLogger.Log(err.c_str());
-
glesSurface = eglCreateWindowSurface(glesDisplay, configs[0], (NativeWindowType)m_hwnd, NULL);if (!glesSurface)
-
{ return false;
-
}
-
}
-
EGLContext glesContext = eglCreateContext(glesDisplay, configs[0], EGL_NO_CONTEXT, aEGLContextAttributes); if(!glesContext)
-
{
-
glesContext = eglCreateContext(glesDisplay, configs[0], EGL_NO_CONTEXT, NULL);if (!glesContext)
-
{
-
-
timeLogger.Log(_T(“eglCreateContext Failed!”)); return false;
-
}
-
} if (!eglMakeCurrent(glesDisplay, glesSurface, glesSurface, glesContext))
-
{
-
EGLint errCode = eglGetError();
-
tstring err;switch (errCode)
-
{case EGL_BAD_ALLOC :
-
err = _T(” EGL_BAD_ALLOC “); break;case EGL_BAD_DISPLAY:
-
err = _T(“bad display”); break;case EGL_BAD_CONFIG:
-
err = _T(“bad config”); break;case EGL_BAD_NATIVE_PIXMAP :
-
err = _T(“bad EGL_BAD_NATIVE_PIXMAP “); break;case EGL_BAD_NATIVE_WINDOW :
-
err = _T(” EGL_BAD_NATIVE_WINDOW “); break;case EGL_BAD_CURRENT_SURFACE :
-
err = _T(” EGL_BAD_CURRENT_SURFACE “); break;case EGL_BAD_MATCH:
-
err = _T(“bad Match”); break;case EGL_CONTEXT_LOST :
-
err = _T(“EGL_CONTEXT_LOST “); break;
-
}
-
timeLogger.Log(err.c_str());
-
timeLogger.Log(_T(“eglMakeCurrent Failed!”));return false;
-
}
-
m_display = glesDisplay;
-
m_surface = glesSurface;
-
}
windows EGL环境初始化
版权声明:本文为qq_21743659原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。