PeterO wrote: ↑Sun Jun 30, 2019 3:58 pm
And to get the xwindow id of the window you are using to pass to egl.
I have example code but I've just found a bug in it and I cant update github until I get home.
PeterO
This is where I am having issues, I can't get an XWindow
Code: Select all
x_display = XOpenDisplay(NULL);
if (x_display == NULL)
{
printf("Sorry to say we can't create an Xwindow and this will fail");
// return ; // we need to trap this;
}
this always fails
Here's my full code which I use on all non raspberry systems to work with X11... but can't get an X11 window to instansiate so it fails at the 1st hurdle.. I have not activated the fake GL drivers, so it should be running as a clean system.
I installed Mesa and xorg-dev for X11 ,
I set the lib folder to /usr/lib/arm-linux-gnueabihf to make sure it used the new libs...
But...I can't seem to get that X display to open up.. do I still need to do a BCM_init or something?
so...kinda stuck
Code: Select all
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#define EGL_FALSE 0
#define EGL_TRUE 1
static Display* x_display = NULL;
void Graphics::init_ogl(Target_State *state, int width, int height, int FBResX, int FBResY)
{
#define ES_WINDOW_RGB 0
state->width = width;
state->height = height;
eglBindAPI(EGL_OPENGL_ES_API);
EGLint numConfigs;
EGLint majorVersion;
EGLint minorVersion;
EGLDisplay display;
EGLContext context;
EGLSurface surface;
EGLConfig config;
EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE };
/* create a native window */
Window root;
XSetWindowAttributes swa;
XSetWindowAttributes xattr;
Atom wm_state;
XWMHints hints;
XEvent xev;
EGLConfig ecfg;
EGLint num_config;
Window win;
Screen *screen;
/*
* X11 native display initialization
*/
x_display = XOpenDisplay(NULL);
if (x_display == NULL)
{
printf("Sorry to say we can't create an Xwindow and this will fail");
exit (0); // we need to trap this;
}
root = DefaultRootWindow(x_display);
screen = ScreenOfDisplay(x_display, 0);
state->width = width;
state->height = height;
swa.event_mask = ExposureMask | PointerMotionMask | KeyPressMask | KeyReleaseMask;
swa.background_pixmap = None;
swa.background_pixel = 0;
swa.border_pixel = 0;
swa.override_redirect = true;
win = XCreateWindow(
x_display,
root,
0,
0,
width,
height,
0,
CopyFromParent,
InputOutput,
CopyFromParent,
CWEventMask,
&swa);
XSelectInput(x_display, win, KeyPressMask | KeyReleaseMask);
xattr.override_redirect = TRUE;
XChangeWindowAttributes(x_display, win, CWOverrideRedirect, &xattr);
hints.input = TRUE;
hints.flags = InputHint;
XSetWMHints(x_display, win, &hints);
char* title = (char*)"x11 window Maze3dHunt";
// 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);
state->nativewindow = (EGLNativeWindowType) win;
// Get Display
display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (display == EGL_NO_DISPLAY)
{
return; // EGL_FALSE;
}
// Initialize EGL
if (!eglInitialize(display, &majorVersion,&minorVersion))
{
printf("Sorry to say we have an EGLinit error and this will fail");
EGLint err = eglGetError();
return;// EGL_FALSE;
}
// Get configs
if (!eglGetConfigs(display, NULL, 0, &numConfigs))
{
printf("Sorry to say we have EGL config errors and this will fail");
EGLint err = eglGetError();
return;// EGL_FALSE;
}
// Choose config
if (!eglChooseConfig(display, attribute_list, &config, 1, &numConfigs))
{
printf("Sorry to say we have config choice issues, and this will fail");
EGLint err = eglGetError();
return;// EGL_FALSE;
}
// Create a surface
surface = eglCreateWindowSurface(display, config, state->nativewindow, NULL);
if (surface == EGL_NO_SURFACE)
{
EGLint err = eglGetError();
return;// EGL_FALSE;
}
// Create a GL context
context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs);
if (context == EGL_NO_CONTEXT)
{
EGLint err = eglGetError();
return;// EGL_FALSE;
}
// Make the context current
if (!eglMakeCurrent(display, surface, surface, context))
{
EGLint err = eglGetError();
return;// EGL_FALSE;
}
state->display = display;
state->surface = surface;
state->context = context;
// just for fun lets see what we can do with this GPU
printf("This SBC supports version %i.%i of EGL\n", majorVersion, minorVersion);
printf("This GPU supplied by :%s\n", glGetString(GL_VENDOR));
printf("This GPU supports :%s\n", glGetString(GL_VERSION));
printf("This GPU Renders with :%s\n", glGetString(GL_RENDERER));
printf("This GPU supports :%s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
printf("This GPU supports these extensions :%s\n", glGetString(GL_EXTENSIONS));
EGLBoolean GLtest = eglGetConfigAttrib( display,
config,
EGL_MAX_SWAP_INTERVAL,
&minorVersion);
EGLBoolean test = eglSwapInterval(display, 1); // 1 to lock speed to 60fps (assuming we are able to maintain it), 0 for immediate swap (may cause tearing) which will indicate actual frame rate
// on xu4 this seems to have no effect
// Some OpenGLES2.0 states that we might need
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glDepthMask(TRUE);
glDepthRangef(0.0f, 1.0f);
glClearDepthf(1.0f);
//these are the options you can have for the depth, play with them?
//#define GL_NEVER 0x0200
//#define GL_LESS 0x0201
//#define GL_EQUAL 0x0202
//#define GL_LEQUAL 0x0203
//#define GL_GREATER 0x0204
//#define GL_NOTEQUAL 0x0205
//#define GL_GEQUAL 0x0206
//
glViewport(0, 0, state->width, state->height);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glCullFace(GL_BACK);
if (glGetError() == GL_NO_ERROR) return ;
else
printf("Oh bugger, Some part of the EGL/OGL graphic init failed\n");
}
Very old computer game programmer, now teaching very young computer game programmers, some very bad habits.
http://www.scratchpadgames.net/
https://www.patreon.com/BrianBeuken