Opengl es 如何使用Openes2.0+创建窗口并用颜色填充它;X11?

Opengl es 如何使用Openes2.0+创建窗口并用颜色填充它;X11?,opengl-es,opengl-es-2.0,x11,xlib,egl,Opengl Es,Opengl Es 2.0,X11,Xlib,Egl,我尽可能地在谷歌上搜索,但什么也没找到 我想做的是: 使用X11(Xlib)创建一个窗口并显示它 使用OpenGL ES 2.0使用颜色填充窗口 为了在我的ArchLinux上支持OpenGL ES 2.0,我使用了MESA。我知道如何使用Xlib创建一个简单的X窗口,我有EGL和OpenGL ES的基本知识,但我不明白如何将它们(X11+EGL+OpenGL ES 2.0)结合使用 如果有人至少写了一个简短的代码示例,说明如何准备一个X窗口,并将其与OpenGL ES 2.0正确连接,然后

我尽可能地在谷歌上搜索,但什么也没找到

我想做的是:

  • 使用X11(Xlib)创建一个窗口并显示它
  • 使用OpenGL ES 2.0使用颜色填充窗口
为了在我的ArchLinux上支持OpenGL ES 2.0,我使用了MESA。我知道如何使用Xlib创建一个简单的X窗口,我有EGL和OpenGL ES的基本知识,但我不明白如何将它们(X11+EGL+OpenGL ES 2.0)结合使用

如果有人至少写了一个简短的代码示例,说明如何准备一个X窗口,并将其与OpenGL ES 2.0正确连接,然后开始渲染,我会非常高兴。

创建窗口:

Window root;
XSetWindowAttributes swa;
XSetWindowAttributes  xattr;
Atom wm_state;
XWMHints hints;
XEvent xev;
EGLConfig ecfg;
EGLint num_config;
Window win;

/*
 * X11 native display initialization
 */

x_display = XOpenDisplay(NULL);
if ( x_display == NULL )
{
    return EGL_FALSE;
}

root = DefaultRootWindow(x_display);

swa.event_mask  =  ExposureMask | PointerMotionMask | KeyPressMask;
win = XCreateWindow(
           x_display, root,
           0, 0, esContext->width, esContext->height, 0,
           CopyFromParent, InputOutput,
           CopyFromParent, CWEventMask,
           &swa );

xattr.override_redirect = FALSE;
XChangeWindowAttributes ( x_display, win, CWOverrideRedirect, &xattr );

hints.input = TRUE;
hints.flags = InputHint;
XSetWMHints(x_display, win, &hints);

// make the window visible on the screen
XMapWindow (x_display, win);
XStoreName (x_display, win, title);

// get identifiers for the provided atom name strings
wm_state = XInternAtom (x_display, "_NET_WM_STATE", FALSE);

memset ( &xev, 0, sizeof(xev) );
xev.type                 = ClientMessage;
xev.xclient.window       = win;
xev.xclient.message_type = wm_state;
xev.xclient.format       = 32;
xev.xclient.data.l[0]    = 1;
xev.xclient.data.l[1]    = FALSE;
XSendEvent (
   x_display,
   DefaultRootWindow ( x_display ),
   FALSE,
   SubstructureNotifyMask,
   &xev );
设置颜色:

   glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
   // Set the viewport
   glViewport ( 0, 0, esContext->width, esContext->height );

   // Clear the color buffer
   glClear ( GL_COLOR_BUFFER_BIT );
资料来源:

创建窗口:

Window root;
XSetWindowAttributes swa;
XSetWindowAttributes  xattr;
Atom wm_state;
XWMHints hints;
XEvent xev;
EGLConfig ecfg;
EGLint num_config;
Window win;

/*
 * X11 native display initialization
 */

x_display = XOpenDisplay(NULL);
if ( x_display == NULL )
{
    return EGL_FALSE;
}

root = DefaultRootWindow(x_display);

swa.event_mask  =  ExposureMask | PointerMotionMask | KeyPressMask;
win = XCreateWindow(
           x_display, root,
           0, 0, esContext->width, esContext->height, 0,
           CopyFromParent, InputOutput,
           CopyFromParent, CWEventMask,
           &swa );

xattr.override_redirect = FALSE;
XChangeWindowAttributes ( x_display, win, CWOverrideRedirect, &xattr );

hints.input = TRUE;
hints.flags = InputHint;
XSetWMHints(x_display, win, &hints);

// make the window visible on the screen
XMapWindow (x_display, win);
XStoreName (x_display, win, title);

// get identifiers for the provided atom name strings
wm_state = XInternAtom (x_display, "_NET_WM_STATE", FALSE);

memset ( &xev, 0, sizeof(xev) );
xev.type                 = ClientMessage;
xev.xclient.window       = win;
xev.xclient.message_type = wm_state;
xev.xclient.format       = 32;
xev.xclient.data.l[0]    = 1;
xev.xclient.data.l[1]    = FALSE;
XSendEvent (
   x_display,
   DefaultRootWindow ( x_display ),
   FALSE,
   SubstructureNotifyMask,
   &xev );
设置颜色:

   glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
   // Set the viewport
   glViewport ( 0, 0, esContext->width, esContext->height );

   // Clear the color buffer
   glClear ( GL_COLOR_BUFFER_BIT );
资料来源:


    • 对我来说,opengles图书样本代码实际上失败了。如果您看到相同的初始化失败,那么调用
      eglBindAPI(EGL\u OPENGL\u ES\u API)
      似乎可以修复它。

      对我来说,opengles书籍示例代码实际上失败了。如果您看到相同的初始化失败,那么调用
      eglBindAPI(EGL\u OPENGL\u ES\u API)
      似乎可以修复它