MoKa's picture

(eglInitialize)SelectGraphicsMode - Failed to initialize display connection, error ????????

I am trying to run OpenTK using Mono, with GLES 2.0 context on various platforms.
I downloaded PowerVR Insider SDK for PC (Windows and Linux), and been able to run that context on Windows XP SP3, and Ubuntu 11.10.
Both works well, and runs well.
Now I am trying to run it on i.MX53 card, that has Ubuntu 11.10 MX5 version, special for i.MX53 board that has ARM type processor.
By the documents, it does support GLES 2.0.
I was able to run OpenGL 1.0 context on it, but it uses Software Rasterizer to render it.
But when I am trying to run GLES 2.0 context, it fails. I installed PowerVR Insider SDK libraries for ARM specially. And it has executables (they are written in C++), they does run, and renders properly. But when I am trying to run my code, it does not initialize window.

So I did further researches to find it an issue and got closer. Not sure that it will be an issue, but I hope I will get help from community to find solution.

For windows its a bit weird, it does run several functions many times, like creating context, or versions etc. But i need just GLES 2.0 (EGL) and nothing else..
Here is some part of log:

START
Detected configuration: Windows / Mono
Running on Windows Platform
Egl is supported
Running on Egl Windows Platform
### implementation: OpenTK.Platform.Windows.WinGLNative, exists: True
...
GraphicsMode: Index: 2, Color: 32 (8888), Depth: 24, Stencil: 8, Samples: 0, Accum: 0 (0000), Buffers: 2, Stereo: False
...
### implementation - error: False, current: False, type: OpenTK.Platform.Windows.WinGLContext
Selecting pixel format (ARB)... 
success!
Disposing context 196609.
Destroying window: Windows.WindowInfo: Handle 329360, Parent (null)
### GameWindow - width: 1024, height: 768, mode: bpp: 32, depth: 24, index: 2, samples: 0, stencil: 8, stereo: False, options: Default, device: bpp: 32, width: 1280, height: 960, major: 2, minor: 0, flags: Embedded, sharedContext: null
### GraphicsContext - window: Windows.WindowInfo: Handle 525682, Parent (Windows.WindowInfo: Handle 525688, Parent (null))
Creating GraphicsContext.
GraphicsMode: Index: 2, Color: 32 (8888), Depth: 24, Stencil: 8, Samples: 0, Accum: 0 (0000), Buffers: 2, Stereo: False
IWindowInfo: Windows.WindowInfo: Handle 525682, Parent (Windows.WindowInfo: Handle 525688, Parent (null))
GraphicsContextFlags: Embedded
Requested version: 2.0
### Factory: OpenTK.Platform.Egl.EglWinPlatformFactory
maj: 2, min: 0
flags: Embedded
Window: 2, handle: 525682, surface: 0
...
maj: 1, min: 3
GetConfigs: 6
ChooseConfig: 1
config: r: 8, g: 8, b: 8, a: 8, d: 24, s: 8, sb: 0, s: 0
### implementation - error: False, current: True, type: OpenTK.Platform.Egl.EglContext
Loading extensions for OpenTK.Graphics.ES10.GL... 
106 extensions loaded in 21.8527 ms.
Loading extensions for OpenTK.Graphics.ES11.GL... 
247 extensions loaded in 42.1999 ms.
Loading extensions for OpenTK.Graphics.ES20.GL... 
177 extensions loaded in 32.7835 ms.

And after it runs well. Under Mono and under .Net works fine, and there is no difference in logs.

Now lets take a look on Linux (Ubuntu 11.10) from laptop log:

START
System: Linux
Initializing threaded X11: 1.
Display connection: 148312096, Screen count: 1
Detected configuration: Linux / Mono
Initializing threaded X: success.
Running on X11 Platform
dlopen tries: libGL.so
Egl is supported
Initializing threaded X: success.
Running on Egl X11 Platform
Xinerama query failed.
Creating default GraphicsMode (24, 16, 0, 0, 0, 2, False).
Bits per pixel: 24
Depth: 16
Display: 148312096, Screen: 0, RootWindow: 289
Getting FB config.
### NativeWindow
Creating X11GLNative window.
Display: 148633016, Screen 0, Root window: 289
Registering atoms.
Bits per pixel: 24
Depth: 16
Display: 148312096, Screen: 0, RootWindow: 289
Getting FB config.
Opening render window... 
Initalizing X11 input driver.
First keycode: 8, last 255
6 keysyms per keycode.
X11GLNative window created successfully (id: 65011714).
### implementation: OpenTK.Platform.X11.X11GLNative, exists: True
### GameWindow - width: 1024, height: 768, mode: bpp: 24, depth: 24, index: 243, samples: 0, stencil: 0, stereo: False, options: Default, device: bpp: 24, width: 1280, height: 800, major: 2, minor: 0, flags: Embedded, sharedContext: null
### GraphicsContext - window: X11.WindowInfo: Display 148633016, Screen 0, Handle 65011714, Parent: (null)
Creating GraphicsContext.
GraphicsMode: Index: 243, Color: 24 (8880), Depth: 24, Stencil: 0, Samples: 0, Accum: 0 (0000), Buffers: 2, Stereo: False
IWindowInfo: X11.WindowInfo: Display 148633016, Screen 0, Handle 65011714, Parent: (null)
GraphicsContextFlags: Embedded
Requested version: 2.0
### Factory: OpenTK.Platform.Egl.EglX11PlatformFactory
maj: 2, min: 0
flags: Embedded
Window: 2, handle: 65011714, surface: 0
maj: 1, min: 3
GetConfigs: 4
ChooseConfig: 1
config: r: 8, g: 8, b: 8, a: 8, d: 24, s: 8, sb: 0, s: 0
### implementation - error: False, current: True, type: OpenTK.Platform.Egl.EglContext
Loading extensions for OpenTK.Graphics.ES10.GL... 
PVRVFrameSetGlesLibraryPath: /home/efortiori/Downloads/ProjectC/libGLES_CM.so
PVRVFrameSetGlesv2LibraryPath: /home/efortiori/Downloads/ProjectC/libGLESv2.so
106 extensions loaded in 10.4933 ms.
Loading extensions for OpenTK.Graphics.ES11.GL... 
247 extensions loaded in 19.1499 ms.
Loading extensions for OpenTK.Graphics.ES20.GL... 
177 extensions loaded in 12.6892 ms.
Making WindowBorder hidden.
Removed decorations through motif.
Success.

There is no much difference. Another platform is used, on Windows is native, and on Linux is X11. As well on windows GetConfigs gives 6, but on linux 4.

And now lets take a look at i.MX53 log:

Initializing threaded X11: 1.
Display connection: 35211328, Screen count: 1
Detected configuration: Linux / Mono
Initializing threaded X: success.
Running on X11 Platform
Egl is supported
Initializing threaded X: success.
Running on Egl X11 Platform
Xinerama query failed.
Creating default GraphicsMode (16, 16, 0, 0, 0, 2, False).
Bits per pixel: 16
Depth: 16
Display: 35211328, Screen: 0, RootWindow: 226
Getting FB config.
### NativeWindow
Creating X11GLNative window.
Display: 35552040, Screen 0, Root window: 226
Registering atoms.
Bits per pixel: 24
Depth: 16
Display: 35211328, Screen: 0, RootWindow: 226
Getting FB config.
Opening render window... 
Initalizing X11 input driver.
First keycode: 8, last 255
6 keysyms per keycode.
X11GLNative window created successfully (id: 56623106).
### implementation: OpenTK.Platform.X11.X11GLNative, exists: True
### GameWindow - width: 1024, height: 768, mode: bpp: 32, depth: 24, index: 65, samples: 0, stencil: 8, stereo: False, options: Default, device: bpp: 16, width: 1024, height: 768, major: 2, minor: 0, flags: Embedded, sharedContext: null
### GraphicsContext - window: X11.WindowInfo: Display 35552040, Screen 0, Handle 56623106, Parent: (null)
Creating GraphicsContext.
GraphicsMode: Index: 65, Color: 32 (8888), Depth: 24, Stencil: 8, Samples: 0, Accum: 0 (0000), Buffers: 2, Stereo: False
IWindowInfo: X11.WindowInfo: Display 35552040, Screen 0, Handle 56623106, Parent: (null)
GraphicsContextFlags: Embedded
Requested version: 2.0
### Factory: OpenTK.Platform.Egl.EglX11PlatformFactory
maj: 2, min: 0
flags: Embedded
Window: 35552040, handle: 56623106, surface: 0

And then it gives error:

OpenTK.Graphics.GraphicsModeException: Failed to initialize display connection, error 33966456
  at OpenTK.Platform.Egl.EglGraphicsMode.SelectGraphicsMode (ColorFormat color, Int32 depth, Int32 stencil, Int32 samples, ColorFormat accum, Int32 buffers, Boolean stereo, IntPtr di) [0x00000] in <filename unknown>:0 
  at OpenTK.Platform.Egl.EglContext..ctor (OpenTK.Graphics.GraphicsMode mode, OpenTK.Platform.Egl.EglWindowInfo window, IGraphicsContext sharedContext, Int32 major, Int32 minor, GraphicsContextFlags flags) [0x00000] in <filename unknown>:0 
  at OpenTK.Platform.Egl.EglX11PlatformFactory.CreateGLContext (OpenTK.Graphics.GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, Boolean directRendering, Int32 major, Int32 minor, GraphicsContextFlags flags) [0x00000] in <filename unknown>:0 
  at OpenTK.Graphics.GraphicsContext..ctor (OpenTK.Graphics.GraphicsMode mode, IWindowInfo window, Int32 major, Int32 minor, GraphicsContextFlags flags) [0x00000] in <filename unknown>:0 
  at OpenTK.GameWindow..ctor (Int32 width, Int32 height, OpenTK.Graphics.GraphicsMode mode, System.String title, GameWindowFlags options, OpenTK.DisplayDevice device, Int32 major, Int32 minor, GraphicsContextFlags flags, IGraphicsContext sharedContext) [0x00000] in <filename unknown>:0

Interesting thing, that when it does eglInitialize on display from window that comes before. In OpenTK.Platform.Egl.EglContext constructor.
But then it calls new EglGraphicsMode().SelectGraphicsMode and it calls eglInitialize there, it falls exactly here. So what an issue here?

If needed, I am able to provide any other tests. Remember, tests that comes with PowerVR Insider SDK, using X11 works, but mine doesn't (using OpenTK).

King Regards, Max.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
MoKa's picture

Ok, I made public some classes, enums and strucs, to be able to use Platform interfaces (X11 and EGL).
And, after parsing simple example based on C++ code, I manage to run GLES 2.0 context on i.MX53!

Here is dirty raw code to make it:

int xThreads = OpenTK.Platform.X11.Functions.XInitThreads(); // XInitThreads
 
IntPtr defaultDisplay = OpenTK.Platform.X11.Functions.sys_XOpenDisplay(IntPtr.Zero); // Get default display
 
OpenTK.Platform.X11.Functions.XLockDisplay(defaultDisplay); // lock display
 
int screenCount = OpenTK.Platform.X11.Functions.XScreenCount(defaultDisplay); // get screens count
 
OpenTK.Platform.X11.Functions.XUnlockDisplay(defaultDisplay); // unlock display
 
int defaultScreen = OpenTK.Platform.X11.Functions.XDefaultScreen(defaultDisplay); // get default screen
 
IntPtr rootWindow = OpenTK.Platform.X11.Functions.XRootWindow(defaultDisplay, defaultScreen); // get root window
 
uint defaultDepth = OpenTK.Platform.X11.Functions.XDefaultDepth(defaultDisplay, defaultScreen); // get default depth
 
OpenTK.Platform.X11.XVisualInfo visualInfo = new OpenTK.Platform.X11.XVisualInfo(); // VisualInfo
 
OpenTK.Platform.X11.Functions.XMatchVisualInfo(defaultDisplay, defaultScreen, defaultDepth, 4, ref visualInfo); // get VisualInfo
 
IntPtr colorMap = OpenTK.Platform.X11.Functions.XCreateColormap(defaultDisplay, rootWindow, visualInfo.Visual, 0); // create ColorMap
 
OpenTK.Platform.X11.XSetWindowAttributes attributes = new OpenTK.Platform.X11.XSetWindowAttributes(); // create WindowAttributes
attributes.colormap = colorMap; // set ColorMap
attributes.event_mask = (IntPtr)(OpenTK.Platform.X11.EventMask.StructureNotifyMask | OpenTK.Platform.X11.EventMask.ExposureMask | OpenTK.Platform.X11.EventMask.ButtonPressMask | OpenTK.Platform.X11.EventMask.ButtonReleaseMask | OpenTK.Platform.X11.EventMask.KeyPressMask | OpenTK.Platform.X11.EventMask.KeyReleaseMask); // set EventMask
 
IntPtr mask = (IntPtr)(OpenTK.Platform.X11.SetWindowValuemask.BackPixel | OpenTK.Platform.X11.SetWindowValuemask.BorderPixel | OpenTK.Platform.X11.SetWindowValuemask.EventMask | OpenTK.Platform.X11.SetWindowValuemask.ColorMap); // create Mask
 
int width = 640 < OpenTK.Platform.X11.Functions.XDisplayWidth(defaultDisplay, defaultScreen) ? 640 : OpenTK.Platform.X11.Functions.XDisplayWidth(defaultDisplay, defaultScreen); // calculate Width
int height = 480 < OpenTK.Platform.X11.Functions.XDisplayHeight(defaultDisplay, defaultScreen) ? 480 : OpenTK.Platform.X11.Functions.XDisplayHeight(defaultDisplay, defaultScreen); // calculate Height
 
IntPtr window = OpenTK.Platform.X11.Functions.XCreateWindow(defaultDisplay, rootWindow, 0, 0, width, height, 0, 0, 1, IntPtr.Zero, mask, ref attributes); // create Window
 
OpenTK.Platform.X11.Functions.XMapWindow(defaultDisplay, window); // map Window
 
OpenTK.Platform.X11.Functions.XFlush(defaultDisplay); // Flush
 
IntPtr eglDisplay = Egl.GetDisplay(defaultDisplay); // get EGL Display
 
int major;
int minor;
 
bool init = Egl.Initialize(eglDisplay, out major, out minor); // Initialize EGL
 
int EGL_OPENGL_ES_API = 0x30A0;
 
Egl.BindAPI(EGL_OPENGL_ES_API); // EGL Bind API (ES)
 
int[] conf = new int[5] { Egl.SURFACE_TYPE, Egl.WINDOW_BIT, Egl.RENDERABLE_TYPE, Egl.OPENGL_ES2_BIT, Egl.NONE }; // configure
 
IntPtr[] eglConfig = new IntPtr[1]; // surface config
int num_configs;
 
Egl.ChooseConfig(eglDisplay, conf, eglConfig, 1, out num_configs); // get EGL Configs
 
IntPtr eglSurface = Egl.CreateWindowSurface(eglDisplay, eglConfig[0], window, null); // create Surface
 
int[] contextAttribs = new int[] { Egl.CONTEXT_CLIENT_VERSION, 2, Egl.NONE }; // context attributes
 
IntPtr eglContext = Egl.CreateContext(eglDisplay, eglConfig[0], IntPtr.Zero, contextAttribs); // create Context
 
bool eglCurrent = Egl.MakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext); // Make Current

And it works! It creates window and context, no errors.

Right now I am doing investigation into OpenTK to make it work properly as this small code.

MoKa's picture

Some update.

Unfortunately, I was unable to do any changes in OpenTK it self, looks like my skill is too low, but imho, architecture is really weird. Sometimes there is calls of Lazy functions or "API" multiple times, without any actual reason for it. And other weird things. Flow is uncontrollable :(

So, if there is someone who is still working on library improvements, and could fix that issue? Based on flow that I presented in previous post.

It would be really cool..

the Fiddler's picture

OpenTK was not designed with OpenGL ES or EGL in mind, hence the strangeness. This will be improved in later versions.

Someone modified OpenTK recently, to improve support for embedded systems. I don't have the link right now (at work), but a search should reveal more information. These improvements will be ported back to the core distribution in the future.