Alien vs Predator Port


Basically you shouldnt use any SDL_GL functions. The official SDL only supported GLX, there are some modified SDL's that do add an SDL_OPENGLES. At one time i think one of those was ported, but its not maintained.

The approach Ive taken is my eglport project. I created a couple of simple functions to put around the SDL calls, which handle integration with SDL.

http://sourceforge.net/projects/eglport/?source=directory
 
Basically you shouldnt use any SDL_GL functions. The official SDL only supported GLX, there are some modified SDL's that do add an SDL_OPENGLES. At one time i think one of those was ported, but its not maintained.

The approach Ive taken is my eglport project. I created a couple of simple functions to put around the SDL calls, which handle integration with SDL.

http://sourceforge.net/projects/eglport/?source=directory
I've been trying EGLPort, by doing the following to set up the display:


#if defined(_USE_EGL)
EGL_Open( );
flags &= ~SDL_HWSURFACE;
flags &= ~SDL_OPENGL;
flags |= SDL_SWSURFACE ;
#endif
if ((surface = SDL_SetVideoMode(Width, Height, 0, flags)) == NULL) {
fprintf(stderr, "(OpenGL) SDL SetVideoMode failed: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}

#if defined(_USE_EGL)
EGL_Init( );
#endif

And then to swap the buffers:


void InGameFlipBuffers()
{
#if defined(_USE_EGL)
EGL_SwapBuffers( );
#else
SDL_GL_SwapBuffers();
#endif
}
I presume this is correct? I have found if I do not use EGLPort, I am able to get the loading screen text to display (which is using the hardware GL over SDL display) but then it hangs in SDL_GL_SwapBuffers. If I use EGLPort, I do not get anything on screen (including the loading screen text being missing) however it doesn't crash, I can get into game, run around and make noises. I guess I need to make that little test scenario I talked about before, where after initialising the screen and EGLPort just sit in a main loop rendering a GL triangle to the screen and polling SDL events to see if I can get *anything* to draw with EGLPort.
 
Also I think there was some reports with problems with the stuff inside the define EGL_VERSION_1_2:


peglBindAPI( EGL_OPENGL_ES_API );
I would try commenting this part out.

Small things that may not matter

flags = SDL_SWSURFACE;

Set the screen BPP to 16 from 0
 
Here, in the wiki about porting to GLES says EGL has to be open immediately after SDL video initialization. I used it a few times and it worked ok.
In my code snippet in the post above yours I indicate my order is:


EGL_Open SDL_SetVideoMode EGL_Init

I believe this matches the Wiki suggestion.

Also I think there was some reports with problems with the stuff inside the define EGL_VERSION_1_2:


peglBindAPI( EGL_OPENGL_ES_API );
I would try commenting this part out.

Small things that may not matter

flags = SDL_SWSURFACE;

Set the screen BPP to 16 from 0
Thank you, I will try this when I get home tonight. FWIW I am also using nanoGL to handle things like glBegin/glEnd, I presume there is no issue mixing these two together, I also presume there isn't anything recommended over nanoGL for this purpose?
 
Here, in the wiki about porting to GLES says EGL has to be open immediately after SDL video initialization. I used it a few times and it worked ok.
In my code snippet in the post above yours I indicate my order is:


EGL_Open SDL_SetVideoMode EGL_Init

I believe this matches the Wiki suggestion.
Your doing it correctly

How do you shutdown SW SDL?

I dont really suggest using nanogl, there is a new maintained GL wrapper lib. I think linuxbochs wrote it? But I think it wraps the SDL_GL too, so might have to rework the code to use it.
 
Last edited by a moderator:
Here, in the wiki about porting to GLES says EGL has to be open immediately after SDL video initialization. I used it a few times and it worked ok.
In my code snippet in the post above yours I indicate my order is:


EGL_Open SDL_SetVideoMode EGL_Init

I believe this matches the Wiki suggestion.
Oh, sorry. I was referring to do SDL_Init( SDL_INIT_VIDEO ) and immediately after EGL_Open(). But it's probably not important.
 
How do you shutdown SW SDL?
The AVP code is doing this:


// Destroy
SDL_FreeSurface(surface);
SDL_QuitSubSystem(SDL_INIT_VIDEO);

// Create
SDL_InitSubSystem(SDL_INIT_VIDEO);
EGL_Open( );
// etc.

This does work on PC, but maybe something extra is required on Pandora?

I dont really suggest using nanogl, there is a new maintained GL wrapper lib. I think linuxbochs wrote it? But I think it wraps the SDL_GL too, so might have to rework the code to use it.
I have attempted to use this, but not been successful so far, however if/when I get this working, I will definitely try using the GL wrapper lib and compare performance/compatibility. If possible I'd rather use the GL lib over nano GL. Thanks for the (wealth) of pointers so far by the way, and thank you to everyone else who is helping, I am reading everything and appreciate it.
 
i really hope you get this working. I bought the game back in the day, but due to graphic card incompatibilities it didn't work 100% properly on my machine (texture glitches etc.) :(
 
No 'progress' but a little finding, with the following:


// Display

{
Display * g_Display = XOpenDisplay( ":0" );
EGLint iMajorVersion, iMinorVersion;

if ( ! g_Display )
{
printf( "Failed to XOpenDisplay( \":0\" )\n" );
_exit( 1 );
}

g_EglDisplay = eglGetDisplay( ( NativeDisplayType ) g_Display );
if (g_EglDisplay == EGL_NO_DISPLAY)
{
printf( "Failed to eglGetDisplay\n" );
_exit( 1 );
}

if ( ! eglInitialize( g_EglDisplay, &iMajorVersion, &iMinorVersion ) )
{
printf( "eglInitialize failed\n" );
_exit( 1 );
}
}
flags = SDL_SWSURFACE;
bitDepth = 16;

// SDL

if ((surface = SDL_SetVideoMode(Width, Height, bitDepth, flags)) == NULL) {
fprintf(stderr, "(OpenGL) SDL SetVideoMode failed: %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}

// EGL
{
SDL_SysWMinfo sysInfo; //Will hold our Window information

EGLint pi32ConfigAttribs[5];
int attrib = 0;
int iConfigs;
EGLConfig eglConfig;
int result = 0;
pi32ConfigAttribs[attrib++] = EGL_SURFACE_TYPE;
pi32ConfigAttribs[attrib++] = EGL_WINDOW_BIT;
pi32ConfigAttribs[attrib++] = EGL_NONE;
pi32ConfigAttribs[attrib++] = EGL_NONE;

if ( ! eglChooseConfig( g_EglDisplay, pi32ConfigAttribs, &eglConfig, 1, &iConfigs) || (iConfigs != 1))
{
printf( "eglChooseConfig failed\n" );
_exit( 1 );
}

g_EglContext = eglCreateContext( g_EglDisplay, eglConfig, NULL, NULL );
if (g_EglContext == EGL_NO_CONTEXT)
{
printf( "eglCreateContext failed\n" );
_exit( 1 );
}

// Get the SDL window handle
SDL_VERSION(&sysInfo.version); //Set SDL version

if(SDL_GetWMInfo(&sysInfo) <= 0)
{
printf( "EGL ERROR: Unable to get SDL window handle: %s\n", SDL_GetError() );
_exit( 1 );
}
g_Window = (NativeWindowType)sysInfo.info.x11.window;

g_EglSurface = eglCreateWindowSurface( g_EglDisplay, eglConfig, (NativeWindowType)g_Window, NULL );
if ( g_EglDisplay == EGL_NO_SURFACE )
{
printf( "eglCreateWindowSurface failed\n" );
_exit( 1 );
}

result = eglMakeCurrent( g_EglDisplay, g_EglSurface, g_EglSurface, g_EglContext );

if (result != EGL_TRUE)
{
printf( "EGL ERROR: Unable to make GLES context current\n" );
_exit( 1 );
}

// TEST
eglSwapBuffers( g_EglDisplay, g_EglSurface );
eglSwapBuffers( g_EglDisplay, g_EglSurface );
}

It will hang when I attempt to step over the first eglSwapBuffers call, which indicates it isn't a bad draw command or something hanging the GPU, as nothing is being drawn. There must be something not quite right with the EGL set up which is resulting in the eglSwapBuffers causing the hang.

The above code is pieced together from various sources of using EGL/SDL together, I'm sure I am missing something, but I can't quite figure it out right now..!
 
FWIW, I also tried putting a sleep call (for a couple of seconds) before the eglSwapBuffers and stepped over that (just in case there was another thread causing the problem) but it stepped over the sleep (after waiting a couple of seconds) without any problem. So I believe the issue is to do with the buffers/windows/EGL set up.
 
As a further test, I found that this tiny sample will crash/hang on the swap buffers (using the latest EGLPort linked to in this thread):


int main( int argc, char *argv[ ] )
{
SDL_Surface* screen = NULL;

SDL_Init( SDL_INIT_VIDEO );
if ( EGL_Open( ) )
{
fprintf( stderr, "Failed to EGL_Open\n" );
_exit( 1 );
}

screen = SDL_SetVideoMode( 480, 320, 0, SDL_SWSURFACE );
if ( ! screen )
{
fprintf( stderr, "Failed to SDL_SetVideoMode\n" );
_exit( 1 );
}

if ( EGL_Init( ) )
{
fprintf( stderr, "Failed to EGL_Init\n" );
_exit( 1 );
}

EGL_SwapBuffers( );

EGL_Close( );
SDL_Quit( );

return 0;
}

It feels like I have narrowed this down to a case that really should work (shouldn't it?). So what must I be doing wrong now? I am guessing something very silly, I do not use Linux at all (except on Pandora) and have hardly touched SDL, so there is probably quite an array of stupid things I may have done.
 
well i just can repeat myself, i'm using my own GLES with SDL initialization routines in apkenv and it just works.

just guessing, though: EGL_SwapBuffers is waiting for VSYNC internally, maybe this doesnt work. can you just comment the lines out (it's something with ioctl)
 
Hmm why do you do half of EGL init before SDL_SetVideoMode() and and half after?

I'd also take g_Display from wminfo.info.x11.display, not open it yourself as that may do separate connection to X where SDL's sysInfo.info.x11.window is invalid.

EDIT: that was refering to previous code, not "tiny sample" later.

EDIT2: it kind of applies to second sample too..
 
Last edited by a moderator:
Hmm why do you do half of EGL init before SDL_SetVideoMode() and and half after?

I was doing this based on the code here: http://pandorawiki.org/Porting_to_GLES_from_GL in section 'Adding EGL Context'

I'd also take g_Display from wminfo.info.x11.display, not open it yourself as that may do separate connection to X where SDL's sysInfo.info.x11.window is invalid.
Okay, I believe this doesn't apply to the second 'tiny sample' though.

well i just can repeat myself, i'm using my own GLES with SDL initialization routines in apkenv and it just works.
Yes, thank you for your input, I will try the code in apkenv next, I have looked at it, it is just in the process of narrowing things down I got to the above small segment which goes wrong, so I thought I'd ask about that first.

just guessing, though: EGL_SwapBuffers is waiting for VSYNC internally, maybe this doesnt work. can you just comment the lines out (it's something with ioctl)
I wondered about the same, but the VSYNC code isn't getting hit, it is the call to eglSwapBuffers (the real call going into the GL lib) that ends up hanging.

In other news, I removed the dependency on nanoGL now, and have converted all necessarily GL calls to GLES and fixed up glBegin/glEnd to do something suitable. On PC the game looks okay (have hardly tested, just jumped into the first alien level and ran around for 5 seconds to make sure I could see stuff generally okay). Fingers crossed I can get to the bottom of the SDL/GL context stuff!
 
Back
Top