NativeWindowType X11Windowing::createNativeWindow(NativeDisplayType _dpy, int width, int height) { Display *dpy = (Display *) _dpy; long defaultScreen = DefaultScreen( dpy ); Window rootWindow = RootWindow(dpy, defaultScreen); int depth = DefaultDepth(dpy, defaultScreen); XVisualInfo *visualInfo = new XVisualInfo; XMatchVisualInfo(dpy, defaultScreen, depth, TrueColor, visualInfo); if (visualInfo == NULL) { fprintf(stderr, "couldn't find matching visual\n"); return NULL; } Colormap x11Colormap = XCreateColormap(dpy, rootWindow, visualInfo->visual, AllocNone); XSetWindowAttributes sWA; sWA.colormap = x11Colormap; sWA.event_mask = StructureNotifyMask | ExposureMask; sWA.background_pixel = 0; sWA.border_pixel = 0; unsigned int attributes_mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap; Window win = XCreateWindow( dpy, rootWindow, 0, 0, width, height, 0, CopyFromParent, InputOutput, CopyFromParent, attributes_mask, &sWA); XMapWindow(dpy, win); XFlush(dpy); return NativeWindowType(win); }
//================================================================================================================================= /// /// Funtion to create the EGL window. /// /// \param hWnd the parent window HWND. /// \param hInstance the class instance. /// /// \return 1 = pass; 0 = fail. //================================================================================================================================= int CreateEGLContext( HWND hWnd, HINSTANCE hInstance ) { EGLint attribList[MAX_EGL_ATTRIBUTES]; EGLint numConfigs; EGLint majorVersion; EGLint minorVersion; /// Build up the attribute list BuildAttribList( attribList ); // Get Display g_egl.dsp = eglGetDisplay( EGL_DEFAULT_DISPLAY ); if ( g_egl.dsp == EGL_NO_DISPLAY ) { assert( 0 && "eglGetDisplay failed" ); return FALSE; } // Initialize EGL if ( ! eglInitialize( g_egl.dsp, &majorVersion, &minorVersion) ) { assert( 0 && "eglInitialize failed" ); return FALSE; } // Get configs if ( ! eglGetConfigs( g_egl.dsp, NULL, 0, &numConfigs ) ) { assert( 0 && "eglGetConfigs failed" ); return FALSE; } // Choose config if ( !eglChooseConfig(g_egl.dsp, attribList, &g_egl.cfg, 1, &numConfigs) ) { assert( 0 && "eglChooseConfig failed" ); return FALSE; } // Create a surface g_egl.surf = eglCreateWindowSurface( g_egl.dsp, g_egl.cfg, NativeWindowType( hWnd ), NULL ); if ( g_egl.surf == EGL_NO_SURFACE ) { assert( 0 && "eglCreateWindowSurface failed" ); return FALSE; } // Create a GL context EGLint ctxAttribList[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; g_egl.cxt = eglCreateContext( g_egl.dsp, g_egl.cfg, EGL_NO_CONTEXT, ctxAttribList ); if ( g_egl.cxt == EGL_NO_CONTEXT ) { assert( 0 && "eglCreateContext failed" ); return FALSE; } // Make the context current if ( ! eglMakeCurrent( g_egl.dsp, g_egl.surf, g_egl.surf, g_egl.cxt ) ) { assert( 0 && "eglMakeCurrent failed" ); return FALSE; } return TRUE; }