Can't Open Gles Display


sixtyfifthbit

Member
Joined
Aug 24, 2007
Messages
168
I've been trying to make a library to use GLES 1.x but I can't even seem to get act one right - I cannot even open a GL display. Here is the code:

Code:
       static bool InitEGL(bool FSAA)
        {
            nEGL_Display = eglGetDisplay((NativeDisplayType)nX11_Display);
            if (EGL_NO_DISPLAY==nEGL_Display)
            {
                errorf("WARNING: eglGetDisplay((NativeDisplayType)nX11_Display) failed.\n"\
                    "Attempting eglGetDisplay(EGL_DEFAULT_DISPLAY)\n");

                nEGL_Display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
                if (EGL_NO_DISPLAY==nEGL_Display)
                {
                    errorf("Error: eglGetDisplay() failed.\n");
                    Shutdown();
                    return false;
                }
            }

            EGLint iMajorVersion, iMinorVersion;
            if (!eglInitialize(nEGL_Display, &iMajorVersion, &iMinorVersion))
            {
                EGLint iErr = eglGetError();
                errorf("Error: eglInitialize() failed (%s).\n",GetErrorString(iErr));
                Shutdown();
                return false;
            }

            EGLint pi32ConfigAttribs[10];
            int attrib = 0;
            pi32ConfigAttribs[attrib++] = EGL_SURFACE_TYPE;
            pi32ConfigAttribs[attrib++] = EGL_WINDOW_BIT;
            pi32ConfigAttribs[attrib++] = EGL_NONE;
            if ( FSAA )
            {
                pi32ConfigAttribs[attrib++] = EGL_SAMPLE_BUFFERS;
                pi32ConfigAttribs[attrib++] = 1;
                pi32ConfigAttribs[attrib++] = EGL_SAMPLES;
                pi32ConfigAttribs[attrib++] = 4;
            }
            pi32ConfigAttribs[attrib++] = EGL_NONE;

            EGLint iConfigs=0;
            if (!eglChooseConfig(nEGL_Display, pi32ConfigAttribs, &nEGL_Config, 1, &iConfigs) || (iConfigs != 1))
            {
                EGLint iErr = eglGetError();
                errorf("Error: eglChooseConfig() failed(%s).\n",GetErrorString(iErr));

                eglGetConfigs(nEGL_Display,NULL,0,&iConfigs);
                if (iConfigs)
                {
                    EGLConfig *cfgs=new EGLConfig[iConfigs];
                    eglGetConfigs(nEGL_Display,cfgs,iConfigs,&iConfigs);
                    for(int loop=0;loop<iConfigs;loop++)
                    {
                        EGLint scratch[4];
                        eglGetConfigAttrib(nEGL_Display,cfgs[loop],EGL_BUFFER_SIZE,&scratch[0]);
                        eglGetConfigAttrib(nEGL_Display,cfgs[loop],EGL_MAX_PBUFFER_WIDTH,&scratch[1]);
                        eglGetConfigAttrib(nEGL_Display,cfgs[loop],EGL_MAX_PBUFFER_HEIGHT,&scratch[2]);
                        eglGetConfigAttrib(nEGL_Display,cfgs[loop],EGL_SURFACE_TYPE,&scratch[3]);
                        errorf("%d:  %dx%dx%d, %X\n",loop,scratch[1],scratch[2],scratch[0],scratch[3]);
                    }
                    delete cfgs;
                }
                else
                    errorf("There are literally no configurations available.\n");

                Shutdown();
                return false;
            }

            nEGL_Surface = eglCreateWindowSurface(nEGL_Display, nEGL_Config, (NativeWindowType)nX11_Window, NULL);
            if (!TestEGLError("eglCreateWindowSurface"))
            {
                Shutdown();
                return false;
            }

            nEGL_Context = eglCreateContext(nEGL_Display, nEGL_Config, NULL, NULL);
            if (EGL_NO_CONTEXT==nEGL_Context)
            {
                EGLint iErr = eglGetError();
                errorf("Error: eglCreateContext() failed(%s).\n",GetErrorString(iErr));
                Shutdown();
                return false;
            }

            eglMakeCurrent(nEGL_Display, nEGL_Surface, nEGL_Surface, nEGL_Context);
            if (!TestEGLError("eglMakeCurrent"))
            {
                Shutdown();
                return false;
            }

    #ifdef __PLAT_PANDORA__
            nVSync = true;
    #else
            eglSwapInterval( nEGL_Display, 1 );
    #endif
            return true;
        }

        static bool InitX11()
        {
            Window sRootWindow;
            XSetWindowAttributes sWA;
            unsigned int ui32Mask;
            int i32Depth;

            nX11_Display = XOpenDisplay( ":0" );
            if (!nX11_Display)
            {
                errorf("Error: Unable to open X display\n");
                Shutdown();
                return false;
            }

            nX11_Screen = XDefaultScreen( nX11_Display );

            sRootWindow = RootWindow(nX11_Display, nX11_Screen);
            i32Depth    = DefaultDepth(nX11_Display, nX11_Screen);
            nX11_Visual = new XVisualInfo;
            XMatchVisualInfo( nX11_Display, nX11_Screen, i32Depth, TrueColor, nX11_Visual);
            if (!nX11_Visual)
            {
                errorf("Error: Unable to acquire visual\n");
                Shutdown();
                return false;
            }

            // Colormap of the specified visual type for the display.
            nX11_Colormap = XCreateColormap( nX11_Display, sRootWindow, nX11_Visual->visual, AllocNone );
            sWA.colormap = nX11_Colormap;

            // List of events to be handled by the application. Add to these for handling other events.
            sWA.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask;

            // Display capabilities list.
            ui32Mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap;

            // Creates the X11 window
            nX11_Window = XCreateWindow( nX11_Display, RootWindow(nX11_Display, nX11_Screen), 0, 0, nWidth, nHeight,
                0, CopyFromParent, InputOutput, CopyFromParent, ui32Mask, &sWA);

            // Make the window viewable and flush the output buffer.
            XMapWindow(nX11_Display, nX11_Window);
            XFlush(nX11_Display);

            return true;
        }

        bool Initialize(bool FSAA)
        {
            if (SDL_Init(SDL_INIT_VIDEO)!=0)
            {
                errorf("Unable to initialize SDL: %s\n", SDL_GetError());
                return false;
            }

            if (!InitX11())
            {
                errorf("Unable to initialize X11\n");
                return false;
            }

            if (!InitEGL(FSAA))
            {
                errorf("Unable to initialize EGL\n");
                return false;
            }

            Enable2D();

            char cmd[512];
            strcpy( cmd, "xset r rate 500 10" );
            system( cmd );

            return true;
        }

On Linux X86, I get:
Code:
Egl scizka: /usr/lib/libEGL.so
Egl scizka2: /usr/lib/libEGL.so
Error: eglChooseConfig() failed(Success!).
There are literally no configurations available.
Unable to initialize EGL

...and on the Pandora:
Code:
WARNING: eglGetDisplay((NativeDisplayType)nX11_Display) failed (Success!).
Attempting eglGetDisplay(EGL_DEFAULT_DISPLAY)
Error: eglInitialize() failed (BAD ALLOC).
server does not have extension for "r rate" option
Unable to initialize EGL

I haven't the faintest idea what is wrong on the Pandora, but I assume the issue on the X86 has to do with the GLES simulation libraries. Any ideas?
 
atari_eric said:
I haven't the faintest idea what is wrong on the Pandora, but I assume the issue on the X86 has to do with the GLES simulation libraries. Any ideas?

Havnt gone through your code in full detail but its not necessary to init SDL video and open an X11 window. Pick a method SDL or X11.
 
Last edited by a moderator:
Pickle said:
atari_eric said:
I haven't the faintest idea what is wrong on the Pandora, but I assume the issue on the X86 has to do with the GLES simulation libraries. Any ideas?

Havnt gone through your code in full detail but its not necessary to init SDL video and open an X11 window. Pick a method SDL or X11.

Yeah, I'm not certain why I have that in there. Taking it out doesn't change anything though - it's the same problem.
 
Last edited by a moderator:
just a question - are audiorace, frogatto or super geometry dust working? these are 3 games i know they're using GLES.

if they dont work on the pandora, it might be worth a reflash of the firmware. if not, there's something with your code.

there's also torpor's wakebreaker sources available that also use GLES: http://w1xer.at/pandora/
 
From the errors, and following through the code, it looks like your X window management is iffy.

Here's the X window code that I use in GLESGAE without much issue:
Code:
X11RenderWindow::X11RenderWindow()
: mDisplay(XOpenDisplay(0))	// Display*
, mWindow(0)			// Window
, mDeleteMessage()		// Atom
{
}

X11RenderWindow::~X11RenderWindow()
{
	if (0 != mWindow)
		close();

	XCloseDisplay(mDisplay);
}

void X11RenderWindow::open(const char* windowName, const unsigned int width, const unsigned int height)
{
	// Store the width and height.
	mWidth = width;
	mHeight = height;

	// Create the actual window and store the pointer.
	mWindow = XCreateWindow(mDisplay			// Pointer to the Display
				, DefaultRootWindow(mDisplay)	// Parent Window
				, 0				// X of top-left corner
				, 0				// Y of top-left corner
				, width				// requested width
				, height			// requested height
				, 0				// border width
				, CopyFromParent		// window depth
				, CopyFromParent		// window class - InputOutput / InputOnly / CopyFromParent
				, CopyFromParent		// visual type
				, 0				// value mask
				, 0);				// attributes

	// Map the window to the display.
	XMapWindow(mDisplay, mWindow);

	// Set the name
	XStoreName(mDisplay, mWindow, windowName);

	// Setup input
	XSelectInput(mDisplay, mWindow, ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask);

	// register interest in the delete window message
	mDeleteMessage = XInternAtom(mDisplay, "WM_DELETE_WINDOW", false);
	XSetWMProtocols(mDisplay, mWindow, &mDeleteMessage, 1);
}

void X11RenderWindow::close()
{
	XDestroyWindow(mDisplay, mWindow);
	mWindow = 0;
}

And just for completeness sake, here's what I do for my ES 1 Context.. I'm not really after anything in particular, so my options are as wide and general as possible:
Code:
void GLES1RenderContext::initialise()
{
	// Get the EGL Display..
	mDisplay = eglGetDisplay( (reinterpret_cast<EGLNativeDisplayType>(mWindow->getDisplay())) );
	if (EGL_NO_DISPLAY == mDisplay) {
		printf("failed to get egl display..\n");
	}

	// Initialise the EGL Display
	if (0 == eglInitialize(mDisplay, NULL, NULL)) {
		printf("failed to init egl..\n");
	}

	// Now we want to find an EGL Surface that will work for us...
	EGLint eglAttribs[] = {
		EGL_BUFFER_SIZE, 16	// 16bit Colour Buffer
	,	EGL_NONE
	};

	EGLConfig  eglConfig;
	EGLint     numConfig;
	if (0 == eglChooseConfig(mDisplay, eglAttribs, &eglConfig, 1, &numConfig)) {
		printf("failed to get context..\n");
	}

	// Create the actual surface based upon the list of configs we've just gotten...
	mSurface = eglCreateWindowSurface(mDisplay, eglConfig, reinterpret_cast<EGLNativeWindowType>(mWindow->getWindow()), NULL);
	if (EGL_NO_SURFACE == mSurface) {
		printf("failed to get surface..\n");
	}

	// Setup the EGL Context
	EGLint contextAttribs[] = {
		EGL_CONTEXT_CLIENT_VERSION, 1
	,	EGL_NONE
	};

	// Create our Context
	mContext = eglCreateContext (mDisplay, eglConfig, EGL_NO_CONTEXT, contextAttribs);
	if (EGL_NO_CONTEXT == mContext) {
		printf("failed to get context...\n");
	}

	// Bind the Display, Surface and Contexts together
	eglMakeCurrent(mDisplay, mSurface, mSurface, mContext);

	// Set up our viewport
	glViewport(0, 0, mWindow->getWidth(), mWindow->getHeight());

	// Set a non-black clear colour
	glClearColor(0.4F, 0.4F, 0.4F, 1.0F);
}

void GLES1RenderContext::shutdown()
{
	eglDestroyContext(mDisplay, mContext);
	eglDestroySurface(mDisplay, mSurface);
	eglTerminate(mDisplay);
}

It's also about the only code in my engine that currently has printfs to track what it's doing ;)
I should probably fix that...

But yes, you should be able to more or less copy/paste my code in then start adding your custom variables without much issue... the problem does seem to be in your X calls though, so try using my simple "use the defaults" attempt first :)

-edit-
Formatting...
 
Thank you for your help, but your edits didn't change anything. In fact, I just copied your code verbatim from the Pandora Wiki and it failed too.

I had SGD running on this once - does the author have the code open-sourced?

EDIT: Okay it seems like an OS problem - I just ran it on the off-NAND OS and it ran with no errors. Apparently Torpor's/Jilse's tar file for compiling directly on the Pandora is bollocks - you can compile stuff, but it won't run. Useless, to me at least. This means either trying to kludge together a cross-compiling setup, or seeing if I can convert H6A4 into a dev OS (because devving on the NAND is BAD, and I've got a SD of H6A4 ready to go). Any suggestions on which way to go?
 
Last edited by a moderator:
If you look over in the Extend Utils topic, I'm writing up guides and stuff on using a Debian chroot to dev in, so there's another option for you.

Personally, I do prefer just creating a bootable SD card with everything I need on it - be that booting Angstrom ( with _careful_ use of opkg ) or Debian.. as it's just a bit easier.. though I do like my Extend Utils as well as I can test in bare Angstrom, while compiling and using all the tools from Debian in a specific Terminal. Either way, lots of options anyway. For simplicity, just go with a boot SD.
 
If you don't mind, please explain what is happening with the Wakebreaker code you are compiling? I don't have Jilse's setup for compiling available but I am 100% positive that when I compiled Wakebreaker, it ran just fine. So whats different for you?

Once you have the binary compiled, it should just run. If it doesn't, please let me know the errors and we'll find out why. Wakebreaker is usually built and runs clean.
 
torpor said:
If you don't mind, please explain what is happening with the Wakebreaker code you are compiling? I don't have Jilse's setup for compiling available but I am 100% positive that when I compiled Wakebreaker, it ran just fine. So whats different for you?

Once you have the binary compiled, it should just run. If it doesn't, please let me know the errors and we'll find out why. Wakebreaker is usually built and runs clean.

At last check, I couldn't even compile Wakebreaker - it was the first thing I tried. And since last night's discovery, I've written over my dev SD with H6A4 in hopes of getting gcc, et al. on it and continuing anew, so now I don't have Jilse's setup either.
 
Last edited by a moderator:
Thats very bizaare, because following the bollocks method Wakebreaker builds cleanly and simply, and it works. So I don't understand whats going on here although I'd love to see some logs if you've got them ..
 
torpor said:
Thats very bizaare, because following the bollocks method Wakebreaker builds cleanly and simply, and it works. So I don't understand whats going on here although I'd love to see some logs if you've got them ..

Okay, it looks like it's an issue with the libgles-omap3-dev files from the angstrom repo - everything works fine until I get the dev version from there. There are definitely libraries updated that could affect execution, but I don't know how to revert things to how they were before, especially while keeping the header files, etc. I need for development. Is there a better source for the GLES dev files?
 
Last edited by a moderator:
Hmmm. You could get them from a toolchain and overwrite the ones you have now with them.
 
I installed the ones in my Dev Extend manually.. change to /tmp or someplace then do something like sudo opkg install --download-only libgles-omap3-dev
Then ar x whatever.it.is.ipk followed by tar -zxvf data.tar.gz ( it's always data.tar.gz ) and it should extract a usr folder which you can move to root or where ever you need it.

Might not be completely accurate instructions, but I'm sure you get the gist of it :)

[edit]It downloaded other files for me, but unless you get errors compiling, I'd probably ignore them too[/edit]
 
Back
Top