一个非常简单/困难的问题。 我需要下载哪些软件包才能创建一个带有EGL / OpenGLES上下文的简单X11窗口。 正如我今天所知,dri2无法进行身份验证。 但它不能是我链接到错误的库,否则它不会接受eglGetDisplay的X11窗口。
我的代码(如果有关系):
#include <X11/Xlib.h>
#include <EGL/egl.h>
#include <EGL/eglplatform.h>
#include <GLES2/gl2.h>
#include <iostream>
struct Pane {
Window win;
Display *display;
Atom windowDeletMessage;
int x11_file;
EGLDisplay egl_display;
EGLContext egl_context;
EGLSurface egl_surface;
EGLConfig egl_config;
EGLint egl_num_config;
EGLint egl_minor;
EGLint egl_major;
};
void setup_window(Pane &self) {
self.display = XOpenDisplay(nullptr);
if (self.display == nullptr) {
exit(0);
}
auto s = DefaultScreen(self.display);
self.win = XCreateSimpleWindow(self.display,
RootWindow(self.display, s),
10,
10,
800,
600,
1,
BlackPixel(self.display, s),
WhitePixel(self.display, s));
self.windowDeletMessage = XInternAtom(self.display, "WM_DELETE_WINDOW", false);
XSetWMProtocols(self.display, self.win, &self.windowDeletMessage, 1);
XStoreName(self.display, self.win, "Default Window");
XSelectInput(self.display,self.win, KeyPressMask | KeyReleaseMask | LeaveWindowMask | EnterWindowMask | PointerMotionMask | ResizeRedirectMask);
XMapWindow(self.display, self.win);
XFlush(self.display);
self.x11_file = ConnectionNumber(self.display);
}
void GetEvent(Pane &self, XEvent &e) {
// Event handling...
}
void setup_egl(Pane &self)
{
const EGLint Attributes[] = //Note to much is to much
{
EGL_RED_SIZE,8,
EGL_GREEN_SIZE,8,
EGL_BLUE_SIZE,8,
EGL_ALPHA_SIZE,8,
EGL_NONE,
};
self.egl_display = eglGetDisplay(self.display);
if(self.egl_display == EGL_NO_DISPLAY)
{
printf("EGL Failed to Obtain Window!") // Note this is not Error handling!
exit(103);
}
if(eglInitialize(self.egl_display,&self.egl_major,&self.egl_minor) == EGL_FALSE)
{
printf("EGL Failed to Initzialize!""");
exit(104);
};
eglChooseConfig(self.egl_display, Attributes, &self.egl_config, 1, &self.egl_num_config);
self.egl_context = eglCreateContext(self.egl_display, self.egl_config,EGL_NO_CONTEXT,nullptr);
self.egl_surface = eglCreateWindowSurface(self.egl_display, self.egl_config, self.win, nullptr);
eglMakeCurrent(self.egl_display, self.egl_surface, self.egl_surface, self.egl_context);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
eglSwapBuffers(self.display, self.egl_surface);
}
int main(int argc, char **argv) {
Pane pane;
setup_window(pane);
setup_egl(pane);
XEvent e;
while (true) {
GetEvent(pane, e);
glClear(GL_COLOR_BUFFER_BIT);
}
}
<小时/> 修改
因为我使用的是USB驱动器而不是SD卡。因此raspi-config无法访问SD卡上的配置文件,因此无法启用完整的KMS。