Page 1 of 1

OpenGL ES on X Error

Posted: Sat Sep 09, 2017 4:52 pm
by Platin21
Hello,

So i will write it out short and simply. I have a problem with egl wich prints out libEGL warning: DRI2: failed to authenticate.
I created an simple XWindow and tryed to attach an egl context to it but it fails on eglInitialize. And yes searched all ready for a solution but can not find one. Tryed some Librarys but im not very satisfied. I'm using the actual raspbian stretch with libgles2-mesa-dev, libegl1-mesa-dri,mesa-utils. And i link to EGL;GLESv2;X11;

Code: Select all

#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);
  }
}
Thanks for any help!

Re: OpenGL ES on X Error

Posted: Sun Sep 10, 2017 8:31 am
by ghans
Did you enable the new experimental GPU driver ? The old , stable one does not cooperate with X and is accessed completely orthogonal to X.

ghans

Re: OpenGL ES on X Error

Posted: Sun Sep 10, 2017 8:46 am
by Platin21
It is enabled via Rapsi-config. I use full KMS. Also it would not return a correct egl display if it would be the old driver.

Re: OpenGL ES on X Error

Posted: Mon Sep 25, 2017 7:01 pm
by Platin21
What i also not understand is why are there no libGLESv2.so files in the armhf folder even i use full kms how can the use it when there is no egl library or GLES library where the link to? Another thing is with a manual installation of vc4 it works like a charm in jessie but i this is not possible on stretch.

Re: OpenGL ES on X Error

Posted: Thu Oct 26, 2017 3:01 pm
by Platin21
Very interssting is that i found out this could be actually
taht i link to the wrong lib even if i get an right
egldisplay wich makes for me no sense but it is so.
This opens the Question how to link to the vc4 lib in a way were we can use X?

Re: OpenGL ES on X Error

Posted: Fri Oct 27, 2017 6:05 am
by ghans
The foundation renamed some libraries in August 2017 to clear up some confusion.

libGLESv2.so became libbrcmGLESv2.so
libEGL.so became libbrcmEGL.so

and so on. Why ? It turns out Mesa ships libraries with exactly the same name and people were gettting confused which libraries were from Mesa and which from Broadcom. This is especially fatal since the libraries Mesa provides are better integrated with X , but less stable and a bit slower (speed has increased dramatically since hardware rendering was added).

ghans

Re: OpenGL ES on X Error

Posted: Fri Oct 27, 2017 6:44 am
by gkreidl
ghans wrote:
Fri Oct 27, 2017 6:05 am
The foundation renamed some libraries in August 2017 to clear up some confusion.

libGLESv2.so became libbrcmGLESv2.so
libEGL.so became libbrcmEGL.so

and so on. Why ? It turns out Mesa ships libraries with exactly the same name and people were gettting confused which libraries were from Mesa and which from Broadcom. This is especially fatal since the libraries Mesa provides are better integrated with X , but less stable and a bit slower (speed has increased dramatically since hardware rendering was added).

ghans
.. and this has turned compiling some packages against these libraries into a real nightmare.

Re: OpenGL ES on X Error

Posted: Fri Oct 27, 2017 4:34 pm
by Platin21
So when i want to link to the mesa library and use an Xwindow where do i find the EGL implementation?

Re: OpenGL ES on X Error

Posted: Tue Oct 31, 2017 10:26 am
by Platin21
Or to say it in other words wich argument do i need to pass to gcc to accept my XWindow.
Today i use: gcc main.cpp -lX11 -lEGL -lGLESv2 wich compiles but throws the DRI2 warning wich then doesn't let me draw anything to the screen.
I can use:

Code: Select all

 
 $ sudo ln -fs /usr/lib/chromium-browser/libGLESv2.so /usr/lib/arm-linux-gnueabihf/libGLESv2.so
 $ sudo ln -fs /usr/lib/chromium-browser/libEGL.so /usr/lib/arm-linux-gnueabihf/libEGL.so
 
Wich surprisingly works ? But it is not a solution more a workaround.