Hello,
I’ve been using the PowerVR OpenGL ES 2.0 emulation library on Windows and recently looked into ~portable context creation via SDL… This is my first foray into EGL.
Here’s my code so far:
#include "g_window.hpp"
namespace Window{
GLuint BackBuffer;
GLuint Width;
GLuint Height;
GLuint BPP;
GLuint ZBufferDepth;
GLuint StencilDepth;
EGLDisplay Display;
EGLContext Context;
EGLConfig Config;
EGLSurface Surface;
#if defined(WINDOWS) || defined(WIN32)
HWND Handle;
HDC Device;
#endif
};
const EGLint SurfaceAttribs[] = {
EGL_RENDER_BUFFER, EGL_BACK_BUFFER,
EGL_NONE
};
const EGLint ConfigAttribs[] = {
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
};
const char* EGLErrorString()
{
EGLint nErr = eglGetError();
switch(nErr){
case EGL_SUCCESS:
return "EGL_SUCCESS";
case EGL_BAD_DISPLAY:
return "EGL_BAD_DISPLAY";
case EGL_NOT_INITIALIZED:
return "EGL_NOT_INITIALIZED";
case EGL_BAD_ACCESS:
return "EGL_BAD_ACCESS";
case EGL_BAD_ALLOC:
return "EGL_BAD_ALLOC";
case EGL_BAD_ATTRIBUTE:
return "EGL_BAD_ATTRIBUTE";
case EGL_BAD_CONFIG:
return "EGL_BAD_CONFIG";
case EGL_BAD_CONTEXT:
return "EGL_BAD_CONTEXT";
case EGL_BAD_CURRENT_SURFACE:
return "EGL_BAD_CURRENT_SURFACE";
case EGL_BAD_MATCH:
return "EGL_BAD_MATCH";
case EGL_BAD_NATIVE_PIXMAP:
return "EGL_BAD_NATIVE_PIXMAP";
case EGL_BAD_NATIVE_WINDOW:
return "EGL_BAD_NATIVE_WINDOW";
case EGL_BAD_PARAMETER:
return "EGL_BAD_PARAMETER";
case EGL_BAD_SURFACE:
return "EGL_BAD_SURFACE";
default:
return "unknown";
}
}
void Window::Init(){
BackBuffer = 0;
Width = 800;
Height = 480;
BPP = 32;
ZBufferDepth = 0;
StencilDepth = 0;
EGLint nConfigs;
SDL_Init(SDL_INIT_VIDEO);
SDL_SetVideoMode(Width, Height, BPP, SDL_SWSURFACE);
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if (!SDL_GetWMInfo(&info)){
PRINT_ERROR("Could Not Obtain SDL window.")
};
#if defined(WINDOWS) || defined(WIN32)
Handle = info.window;
Device = GetDC(Handle);
Display = eglGetDisplay(Device);
#else
Display = eglGetDisplay((EGLNativeDisplayType) EGL_DEFAULT_DISPLAY);
#endif
if (Display == EGL_NO_DISPLAY){
PRINT_ERROR("Display Initialize failed: %s", EGLErrorString());
}
if (!eglInitialize(Display, NULL, NULL)){
PRINT_ERROR("Display Initialize failed: %s", EGLErrorString());
}
if (!eglChooseConfig(Display, ConfigAttribs, &Config, 1, &nConfigs)){
PRINT_ERROR("Configuration failed: %s", EGLErrorString());
}
if (nConfigs != 1){
PRINT_ERROR("Configuration failed: %s", EGLErrorString());
}
Surface = eglCreateWindowSurface(Display, &Config, info.window, NULL);
if (Surface == EGL_NO_SURFACE){
EGLErrorString();
Surface = eglCreateWindowSurface(Display, &Config, NULL, NULL);
if (Surface == EGL_NO_SURFACE){
PRINT_ERROR("Surface Creation failed: %s", EGLErrorString());
}
}
eglBindAPI(EGL_OPENGL_ES_API);
Context = eglCreateContext(Display, &Config, NULL, NULL);
if (Context == EGL_NO_CONTEXT){
PRINT_ERROR("Context Creation failed: %s", EGLErrorString());
}
if (!eglMakeCurrent(Display, Surface, Surface, Context)){
PRINT_ERROR("Make Current failed: %s", EGLErrorString());
};
};
void Window::Destroy(){
eglSwapBuffers(Display, Surface);
eglMakeCurrent(Display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroyContext(Display, Context);
eglDestroySurface(Display, Surface);
eglTerminate(Display);
};
void Window::Render(){
eglSwapBuffers(Display, Surface);
};
When i Init() the window it produces the following error:
Surface Creation failed: EGL_BAD_CONFIG
Basically, I’m stuck for ideas, no changes in the ConfigAttribs make a difference. Have i missed something EGL-wise or could it be something to do with SDL?
PS: I did notice the similar topic below mine, but my problem seems unrelated.