Avp Incoming...!


Ok new code. I recommend you copy and run as is instead of merging the changes over as theres a number of small correction just to rule things out (floats being defined as such instead of defaulting to doubles for example).
This code with get a list of all compatible configs (including a depth buffer of 16) and will run through them one by one. Each config will run for 10 seconds. 5 Seconds with no texture and five with a texture. Once all the configs have run it will exit. I might have found the cause of the crash when it exited too. I forgot to close the display at the end with CloseXDisplay().
Alot of gl commands have been disabled or set to defaults. The only way i managed to reproduce no triangle was with face culling enabled(which is default in gl) and both front and back faces being culled

I have my fingers crossed again... :)

Code:
#include <stdio.h>
#include <GLES/gl.h>
#include <EGL/egl.h>
#include <SDL/SDL.h>
#include <SDL/SDL_syswm.h>
#include <math.h>

EGLDisplay g_eglDisplay = 0;
EGLConfig g_eglConfig = 0;
EGLContext g_eglContext = 0;
EGLSurface g_eglSurface = 0;

const int g_screenWidth = 640;
const int g_screenHeight = 480;

#define g_totalConfigsIn 20
int g_totalConfigsFound = 0;
EGLConfig g_allConfigs[g_totalConfigsIn];
Display *g_x11Display = NULL;

/*===========================================================
Initialise OpenGL settings
===========================================================*/
int InitOpenGL(EGLConfig config)
{
	// Get the SDL window handle
	SDL_SysWMinfo sysInfo; //Will hold our Window information
	SDL_VERSION(&sysInfo.version); //Set SDL version
	if(SDL_GetWMInfo(&sysInfo) <= 0) 
	{
		fprintf( stderr, "ERROR: Unable to get window handle");
		return 0;
	}
	
	 g_eglSurface = eglCreateWindowSurface(g_eglDisplay, config, (EGLNativeWindowType)sysInfo.info.x11.window, 0);
	if ( g_eglSurface == EGL_NO_SURFACE)
	{
		fprintf(stderr, "ERROR: Unable to create EGL surface!");
		return 0;
	}
	
	// Bind GLES and create the context
	eglBindAPI(EGL_OPENGL_ES_API);
	g_eglContext = eglCreateContext(g_eglDisplay, config, NULL, NULL);
	if (g_eglContext == EGL_NO_CONTEXT)
	{
		fprintf(stderr, "ERROR: Unable to create GLES context!");
		return 0;
	}
	
	if (eglMakeCurrent(g_eglDisplay,  g_eglSurface,  g_eglSurface, g_eglContext) == EGL_FALSE)
	{
		fprintf(stderr, "ERROR: Unable to make GLES context current");
		return 0;
	}

	return 1;
}

/*======================================================
 * Kill off any opengl specific details
  ====================================================*/
void TerminateOpenGL()
{
	eglMakeCurrent(g_eglDisplay, NULL, NULL, EGL_NO_CONTEXT);
	eglDestroyContext(g_eglDisplay, g_eglContext);
	eglDestroySurface(g_eglDisplay, g_eglSurface);
	
	g_eglSurface = 0;
	g_eglContext = 0;
}

/*========================================================
 *  Init base EGL
 * ======================================================*/
int InitEGL()
{
	// use EGL to initialise GLES
	g_x11Display = XOpenDisplay(NULL);
	if (!g_x11Display)
	{
		fprintf(stderr, "ERROR: unable to get display!");
		return 0;
	}
	
	g_eglDisplay = eglGetDisplay((EGLNativeDisplayType)g_x11Display);
	if (g_eglDisplay == EGL_NO_DISPLAY)
	{
		fprintf(stderr, "ERROR: Unable to initialise EGL display.");
		return 0;
	}
	
	// Initialise egl
	if (!eglInitialize(g_eglDisplay, NULL, NULL))
	{
			fprintf(stderr, "ERROR: Unable to initialise EGL display.");
			return 0;
	}
	
}

void TerminateEGL()
{
	eglTerminate(g_eglDisplay);
	g_eglDisplay = 0;
	XCloseDisplay(g_x11Display);
	g_x11Display = NULL;
}

/*=======================================================
* Detect available video resolutions
=======================================================*/
int FindAppropriateEGLConfigs()
{
	static const EGLint s_configAttribs[] =
	   {
		  EGL_RED_SIZE,     5,
		  EGL_GREEN_SIZE,   6,
		  EGL_BLUE_SIZE,    5,
		  EGL_DEPTH_SIZE,	16,
		  EGL_SURFACE_TYPE,         EGL_WINDOW_BIT,
		  EGL_RENDERABLE_TYPE,      EGL_OPENGL_ES_BIT,
		  EGL_NONE
	   };

	
	if (eglChooseConfig(g_eglDisplay, s_configAttribs, g_allConfigs, g_totalConfigsIn, &g_totalConfigsFound) != EGL_TRUE || g_totalConfigsFound == 0)
	{
		fprintf(stderr, "ERROR: Unable to query for available configs.");
		return 0;
	}
	fprintf(stderr, "Found %d available configs", g_totalConfigsFound);
	return 1;
}

int SwapBuffers()
{
	eglSwapBuffers(g_eglDisplay, g_eglSurface);
}

struct SVert
{
	float x,y,z;
};

static GLubyte checkImage[64][64][4];
void CreateCheckImage()
{
	int i, j, c;
	
	for (i = 0; i < 64; ++i)
	{
		for (j = 0; j < 64; ++j)
		{
			c = ((((i&0x8)==0)^((j&0x8))==0))*255;
			checkImage[i][j][0] = (GLubyte)c;
			checkImage[i][j][1] = (GLubyte)c;
			checkImage[i][j][2] = (GLubyte)c;
			checkImage[i][j][3] = 255;
		}
	}
}

static struct SVert verts[] = {{0.0f, 1.0f, 0.0f},
							{-1.0f, -1.0f, 0.0f},
							{1.0f, -1.0f, 0.0f}};

static float uvs[] = {0.0f, 0.0f,
					  0.0f, 1.0f,
					  1.0f, 1.0f};

static unsigned short indicies[] = {0,1,2};

void InitLotsOfGL()
{
	glViewport(0, 0, g_screenWidth, g_screenHeight);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	float xmin, xmax, ymin, ymax;
	ymax = 1.0f * tan((60.0f * M_PI) / 360.0f);
	ymin = -ymax;
	xmin = ymin * ((float)g_screenWidth / g_screenHeight);
	xmax = ymax * ((float)g_screenWidth / g_screenHeight);

	glFrustumf(xmin, xmax, ymin, ymax, 1.0f, 30.0f);
	glMatrixMode(GL_MODELVIEW);

	glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
	
	glEnable(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, 0, verts);
	
	glTexCoordPointer(2, GL_FLOAT, 0, uvs);
	glEnable(GL_TEXTURE_COORD_ARRAY);
	
	// Create and load the texture
	int h;
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glGenTextures(1, &h);
	glBindTexture(GL_TEXTURE_2D, h);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	
	// Create the texture data in code (means no loading it from a file)
	CreateCheckImage();
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
	glBindTexture(GL_TEXTURE_2D, h);
	glFrontFace(GL_CCW);
	glDisable(GL_TEXTURE_2D);
	//glDepthRangef(0.0f, 1.0f);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_DEPTH_RANGE);
	glDisable(GL_STENCIL_TEST);
	glDisable(GL_CULL_FACE);
	glDisable(GL_ALPHA_TEST);
	glDisable(GL_BLEND);
	glDisable(GL_DITHER);
}

int main(int argc, char **argv)
{
	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
	atexit(SDL_Quit);
	
	InitEGL();
	FindAppropriateEGLConfigs();
	
	// Go through every config
	int configIndex;
	for (configIndex = 0; configIndex < g_totalConfigsFound; ++configIndex)
	{
		SDL_Surface *pSurface = SDL_SetVideoMode(g_screenWidth, g_screenHeight, 16, SDL_HWSURFACE);
	
		if (!InitOpenGL(g_allConfigs[configIndex]))
		{
			fprintf(stderr, "ERROR: Unable to initialise EGL. See previous error.");
			continue;
		}
		
		InitLotsOfGL();
		
		float angle = 0.0f;
		unsigned int timer = SDL_GetTicks() + 10000;
		while(SDL_GetTicks() < timer)
		{
			if (SDL_GetTicks() + 5000 > timer)
			{
				glEnable(GL_TEXTURE_2D);
			}
			
			glLoadIdentity();
			glTranslatef(0.0f, 0.0f, -3.6f);
			glRotatef(angle, 0.0f, 1.0f, 0.0f);
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, indicies);
			angle += 2.5f;
			SwapBuffers();
		}
		
		TerminateOpenGL();
		SDL_FreeSurface(pSurface);
	}
	
	TerminateEGL();
	return 0;
}
 
Well ive made some progress ;-)

First something isnt right with your gl code, i cant get it to do anything in raw or sdl+x11 mode.
I took a very basic draw triangle from TI demos and it works in both RAW and SDL+X11 modes. The key was removing the eglBindAPI(EGL_OPENGL_ES_API). I moved something else i think context, but i dont know if it did a thing.
Bad news is that the SDL+X11 still locks up the screen (cursor works...)

Update:
Bingo! i made it only use the first config and there no more lockup :)
I took out the SDL_freesurface, its not supposed to be used for the screen surface.

Code:
 #include <stdio.h>
#include <GL/GLES/gl.h>
#include <GL/EGL/egl.h>
#include <SDL/SDL.h>
#include <SDL/SDL_syswm.h>
#include <math.h>

EGLDisplay g_eglDisplay = 0;
EGLConfig g_eglConfig = 0;
EGLContext g_eglContext = 0;
EGLSurface g_eglSurface = 0;

#ifndef RAW_MODE
const int g_screenWidth = 640;
const int g_screenHeight = 480;
#else
const int g_screenWidth = 800;
const int g_screenHeight = 480;
#endif

#define g_totalConfigsIn 20
int g_totalConfigsFound = 0;
EGLConfig g_allConfigs[g_totalConfigsIn];
#ifndef RAW_MODE
Display *g_x11Display = NULL;
#endif

int TestEGLError( void )
{
    EGLint iErr = eglGetError();
    while (iErr != EGL_SUCCESS)
    {
        printf("EGL failed (%d).n", iErr);
        return 0;
    }

    return 1;
}

/*===========================================================
Initialise OpenGL settings
===========================================================*/
int InitOpenGL(EGLConfig config)
{
        // Bind GLES and create the context
        eglBindAPI(EGL_OPENGL_ES_API);
    if (!TestEGLError() )
    {
        return 0;
    }
      
        g_eglContext = eglCreateContext(g_eglDisplay, config, NULL, NULL);
        if (g_eglContext == EGL_NO_CONTEXT)
        {
        TestEGLError();
                fprintf(stderr, "ERROR: Unable to create GLES context!n");
                return 0;
        }  
  
#ifndef RAW_MODE
        // Get the SDL window handle
        SDL_SysWMinfo sysInfo; //Will hold our Window information
        SDL_VERSION(&sysInfo.version); //Set SDL version
        if(SDL_GetWMInfo(&sysInfo) <= 0) 
        {
            TestEGLError();
                fprintf( stderr, "ERROR: Unable to get window handlen");
                return 0;
        }
       
        g_eglSurface = eglCreateWindowSurface(g_eglDisplay, config, (EGLNativeWindowType)sysInfo.info.x11.window, 0);
#else
        g_eglSurface = eglCreateWindowSurface(g_eglDisplay, config, (EGLNativeWindowType)0, 0);
#endif
        if ( g_eglSurface == EGL_NO_SURFACE)
        {
        TestEGLError();
                fprintf(stderr, "ERROR: Unable to create EGL surface!n");
                return 0;
        }
        
        if (eglMakeCurrent(g_eglDisplay,  g_eglSurface,  g_eglSurface, g_eglContext) == EGL_FALSE)
        {
        TestEGLError();
                fprintf(stderr, "ERROR: Unable to make GLES context currentn");
                return 0;
        }

        return 1;
}

/*======================================================
 * Kill off any opengl specific details
  ====================================================*/
void TerminateOpenGL()
{
        eglMakeCurrent(g_eglDisplay, NULL, NULL, EGL_NO_CONTEXT);
        eglDestroyContext(g_eglDisplay, g_eglContext);
        eglDestroySurface(g_eglDisplay, g_eglSurface);
        
        g_eglSurface = 0;
        g_eglContext = 0;
}

/*========================================================
 *  Init base EGL
 * ======================================================*/
int InitEGL()
{
        // use EGL to initialise GLES
#ifndef RAW_MODE
        g_x11Display = XOpenDisplay(NULL);

        if (!g_x11Display)
        {
                fprintf(stderr, "ERROR: unable to get display!n");
                return 0;
        }

        g_eglDisplay = eglGetDisplay((EGLNativeDisplayType)g_x11Display);
#else
        g_eglDisplay = eglGetDisplay((EGLNativeDisplayType)0);    
#endif
        if (g_eglDisplay == EGL_NO_DISPLAY)
        {
        TestEGLError();
                fprintf(stderr, "ERROR: Unable to initialise EGL display.n");
                return 0;
        }
        
        // Initialise egl
        if (!eglInitialize(g_eglDisplay, NULL, NULL))
        {
        TestEGLError();
        fprintf(stderr, "ERROR: Unable to initialise EGL display.n");
        return 0;
        }
        
}

void TerminateEGL()
{
        eglTerminate(g_eglDisplay);
        g_eglDisplay = 0;
#ifndef RAW_MODE    
        XCloseDisplay(g_x11Display);
        g_x11Display = NULL;
#endif
}

/*=======================================================
* Detect available video resolutions
=======================================================*/
int FindAppropriateEGLConfigs()
{
        static const EGLint s_configAttribs[] =
           {
                  EGL_RED_SIZE,     5,
                  EGL_GREEN_SIZE,   6,
                  EGL_BLUE_SIZE,    5,
                  EGL_DEPTH_SIZE,       16,
                  EGL_SURFACE_TYPE,         EGL_WINDOW_BIT,
                  EGL_RENDERABLE_TYPE,      EGL_OPENGL_ES_BIT,
                  EGL_NONE
           };

        
        if (eglChooseConfig(g_eglDisplay, s_configAttribs, g_allConfigs, g_totalConfigsIn, &g_totalConfigsFound) != EGL_TRUE || g_totalConfigsFound == 0)
        {
        TestEGLError();
                fprintf(stderr, "ERROR: Unable to query for available configs.n");
                return 0;
        }
        fprintf(stderr, "Found %d available configsn", g_totalConfigsFound);
        return 1;
}

void SwapBuffers()
{
        eglSwapBuffers(g_eglDisplay, g_eglSurface);
}

struct SVert
{
        float x,y,z;
};

static GLubyte checkImage[64][64][4];
void CreateCheckImage()
{
        int i, j, c;
        
        for (i = 0; i < 64; ++i)
        {
                for (j = 0; j < 64; ++j)
                {
                        c = ((((i&0x8)==0)^((j&0x8))==0))*255;
                        checkImage[i][j][0] = (GLubyte)c;
                        checkImage[i][j][1] = (GLubyte)c;
                        checkImage[i][j][2] = (GLubyte)c;
                        checkImage[i][j][3] = 255;
                }
        }
}

static struct SVert verts[] = {{0.0f, 1.0f, 0.0f},
                                                        {-1.0f, -1.0f, 0.0f},
                                                        {1.0f, -1.0f, 0.0f}};

static float uvs[] = {0.0f, 0.0f,
                                          0.0f, 1.0f,
                                          1.0f, 1.0f};

static unsigned short indicies[] = {0,1,2};

void InitLotsOfGL()
{
        glViewport(0, 0, g_screenWidth, g_screenHeight);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

        float xmin, xmax, ymin, ymax;
        ymax = 1.0f * tan((60.0f * M_PI) / 360.0f);
        ymin = -ymax;
        xmin = ymin * ((float)g_screenWidth / g_screenHeight);
        xmax = ymax * ((float)g_screenWidth / g_screenHeight);

        glFrustumf(xmin, xmax, ymin, ymax, 1.0f, 30.0f);
        glMatrixMode(GL_MODELVIEW);

        glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
        
        glEnable(GL_VERTEX_ARRAY);
        glVertexPointer(3, GL_FLOAT, 0, verts);
        
        glTexCoordPointer(2, GL_FLOAT, 0, uvs);
        glEnable(GL_TEXTURE_COORD_ARRAY);
        
        // Create and load the texture
        int h;
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        glGenTextures(1, &h);
        //glBindTexture(GL_TEXTURE_2D, h);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        
        // Create the texture data in code (means no loading it from a file)
        CreateCheckImage();
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
        //glBindTexture(GL_TEXTURE_2D, h);
        glFrontFace(GL_CCW);
        glDisable(GL_TEXTURE_2D);
        //glDepthRangef(0.0f, 1.0f);
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_DEPTH_RANGE);
        glDisable(GL_STENCIL_TEST);
        glDisable(GL_CULL_FACE);
        glDisable(GL_ALPHA_TEST);
        glDisable(GL_BLEND);
        glDisable(GL_DITHER);
}

void DrawTri( void )
{
    #define VERTTYPE    GLfloat
    #define VERTTYPEENUM    GL_FLOAT
    #define f2vt(x)        (x)
    #define myglLoadMatrix    glLoadMatrixf
    #define myglClearColor    glClearColor  
  
      myglClearColor(f2vt(0.6f), f2vt(0.8f), f2vt(1.0f), f2vt(1.0f)); // clear blue
  
    glClear(GL_COLOR_BUFFER_BIT);

    VERTTYPE pfVertices[] = {    f2vt(-.4f),f2vt(-.4f),f2vt(0),
                                f2vt(+.4f),f2vt(-.4f),f2vt(0),
                                f2vt(0),f2vt(.4f),f2vt(0)
    };
    
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3,VERTTYPEENUM,0,pfVertices);

    // Set color data in the same way (red, green, blue, alpha)
    VERTTYPE pfColors[] = {    f2vt(1.0f), f2vt(1.0f), f2vt(0.66f), f2vt(1.0f),
                            f2vt(1.0f), f2vt(1.0f), f2vt(0.66f), f2vt(1.0f),
                            f2vt(1.0f), f2vt(1.0f), f2vt(0.66f), f2vt(1.0f)};

    glEnableClientState(GL_COLOR_ARRAY);
    glColorPointer(4,VERTTYPEENUM,0,pfColors);

    glDrawArrays(GL_TRIANGLES, 0, 3);
}

int main(int argc, char **argv)
{
#ifndef RAW_MODE
        SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
#else
        SDL_Init(SDL_INIT_TIMER);
#endif
        atexit(SDL_Quit);
        InitEGL();
        FindAppropriateEGLConfigs();
        
        // Go through every config
        int configIndex = 0;
        //for (configIndex = 0; configIndex < g_totalConfigsFound; ++configIndex)
        //{
        printf( "Config %dn", configIndex );
#ifndef RAW_MODE
        printf( "Using SDL window surfacen" );
                SDL_Surface *pSurface = SDL_SetVideoMode(g_screenWidth, g_screenHeight, 16, SDL_HWSURFACE);
#endif
        
                if (!InitOpenGL(g_allConfigs[configIndex]))
                {
            TestEGLError();  
                        fprintf(stderr, "ERROR: Unable to initialise EGL. See previous error.n");
                        //continue;
                }
#ifdef RAW_MODE
                InitLotsOfGL();
                
                float angle = 0.0f;
#endif
                unsigned int timer = SDL_GetTicks() + 10000;
                while(SDL_GetTicks() < timer)
                {
#ifdef RAW_MODE          
                        if (SDL_GetTicks() + 5000 > timer)
                        {
                                glEnable(GL_TEXTURE_2D);
                        }
                        
                        glLoadIdentity();
                        glTranslatef(0.0f, 0.0f, -3.6f);
                        glRotatef(angle, 0.0f, 1.0f, 0.0f);
                        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                        glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, indicies);
                        angle += 2.5f;
#else
            DrawTri();
#endif
                        SwapBuffers();
                }
                printf( "Releasing Opengl-esn" );
                TerminateOpenGL();
        //}
        
        printf( "Releasing EGLn" );
        TerminateEGL();
        return 0;
}
 
Thats great news its good to here somethings working. Its odd that the call to eglBindAPI was messing it up. Can you try and get the result from the eglQueryAPI() I am interested in what value it will return ;) . Are you sure it was that change that made all the difference?
I also noticed your using glDrawArrays in the DrawTri function instead of glDrawElements, I wander if that makes a difference.
SDL_freesurface - Doh i really need to read the docs more than just the funcs names :eek:
 
Lonewolf9383 said:
Thats great news its good to here somethings working. Its odd that the call to eglBindAPI was messing it up. Can you try and get the result from the eglQueryAPI() I am interested in what value it will return ;) . Are you sure it was that change that made all the difference?
I also noticed your using glDrawArrays in the DrawTri function instead of glDrawElements, I wander if that makes a difference.
SDL_freesurface - Doh i really need to read the docs more than just the funcs names :eek:

hmm weird eglBindAPI works ok now. Anyway I added some egl error checking and updated the source in the previous post.
 
Last edited by a moderator:
I made a small change to use glDrawArrays instead of glDrawElements in SDL mode as i think thats worth investigating. I also noticed that in the main function the #ifdef RAW_MODE seemed to be the wrong way around (should be #ifndef). I don't know if that was intentional? ;) . I also cleanup up the multiple configs part seems the first config appears to be valid and working.
Cheers for all the testing, hopefully we can get to the bottom of it and we find an easy way to port games with SDL :)

Code:
#include <stdio.h>
#include <GLES/gl.h>
#include <EGL/egl.h>
#include <SDL/SDL.h>
#include <SDL/SDL_syswm.h>
#include <math.h>

EGLDisplay g_eglDisplay = 0;
EGLConfig g_eglConfig = 0;
EGLContext g_eglContext = 0;
EGLSurface g_eglSurface = 0;

#ifndef RAW_MODE
const int g_screenWidth = 640;
const int g_screenHeight = 480;
#else
const int g_screenWidth = 800;
const int g_screenHeight = 480;
#endif

EGLConfig g_allConfig;
#ifndef RAW_MODE
Display *g_x11Display = NULL;
#endif

int TestEGLError( void )
{
    EGLint iErr = eglGetError();
    while (iErr != EGL_SUCCESS)
    {
        printf("EGL failed (%d).n", iErr);
        return 0;
    }

    return 1;
}

/*===========================================================
Initialise OpenGL settings
===========================================================*/
int InitOpenGL(EGLConfig config)
{
        // Bind GLES and create the context
        eglBindAPI(EGL_OPENGL_ES_API);
		if (!TestEGLError() )
		{
			return 0;
		}
      
        g_eglContext = eglCreateContext(g_eglDisplay, config, NULL, NULL);
        if (g_eglContext == EGL_NO_CONTEXT)
        {
        TestEGLError();
                fprintf(stderr, "ERROR: Unable to create GLES context!n");
                return 0;
        }  
  
#ifndef RAW_MODE
        // Get the SDL window handle
        SDL_SysWMinfo sysInfo; //Will hold our Window information
        SDL_VERSION(&sysInfo.version); //Set SDL version
        if(SDL_GetWMInfo(&sysInfo) <= 0) 
        {
            TestEGLError();
                fprintf( stderr, "ERROR: Unable to get window handlen");
                return 0;
        }
       
        g_eglSurface = eglCreateWindowSurface(g_eglDisplay, config, (EGLNativeWindowType)sysInfo.info.x11.window, 0);
#else
        g_eglSurface = eglCreateWindowSurface(g_eglDisplay, config, (EGLNativeWindowType)0, 0);
#endif
        if ( g_eglSurface == EGL_NO_SURFACE)
        {
			TestEGLError();
            fprintf(stderr, "ERROR: Unable to create EGL surface!n");
            return 0;
        }
        
        if (eglMakeCurrent(g_eglDisplay,  g_eglSurface,  g_eglSurface, g_eglContext) == EGL_FALSE)
        {
			TestEGLError();
            fprintf(stderr, "ERROR: Unable to make GLES context currentn");
            return 0;
        }

        return 1;
}

/*======================================================
 * Kill off any opengl specific details
  ====================================================*/
void TerminateOpenGL()
{
        eglMakeCurrent(g_eglDisplay, NULL, NULL, EGL_NO_CONTEXT);
        eglDestroyContext(g_eglDisplay, g_eglContext);
        eglDestroySurface(g_eglDisplay, g_eglSurface);
        
        g_eglSurface = 0;
        g_eglContext = 0;
}

/*========================================================
 *  Init base EGL
 * ======================================================*/
int InitEGL()
{
        // use EGL to initialise GLES
#ifndef RAW_MODE
        g_x11Display = XOpenDisplay(NULL);

        if (!g_x11Display)
        {
                fprintf(stderr, "ERROR: unable to get display!n");
                return 0;
        }

        g_eglDisplay = eglGetDisplay((EGLNativeDisplayType)g_x11Display);
#else
        g_eglDisplay = eglGetDisplay((EGLNativeDisplayType)0);    
#endif
        if (g_eglDisplay == EGL_NO_DISPLAY)
        {
        TestEGLError();
                fprintf(stderr, "ERROR: Unable to initialise EGL display.n");
                return 0;
        }
        
        // Initialise egl
        if (!eglInitialize(g_eglDisplay, NULL, NULL))
        {
        TestEGLError();
        fprintf(stderr, "ERROR: Unable to initialise EGL display.n");
        return 0;
        }
        
}

void TerminateEGL()
{
        eglTerminate(g_eglDisplay);
        g_eglDisplay = 0;
#ifndef RAW_MODE    
        XCloseDisplay(g_x11Display);
        g_x11Display = NULL;
#endif
}

/*=======================================================
* Detect available video resolutions
=======================================================*/
int FindAppropriateEGLConfigs()
{
        static const EGLint s_configAttribs[] =
           {
                  EGL_RED_SIZE,     5,
                  EGL_GREEN_SIZE,   6,
                  EGL_BLUE_SIZE,    5,
                  EGL_DEPTH_SIZE,       16,
                  EGL_SURFACE_TYPE,         EGL_WINDOW_BIT,
                  EGL_RENDERABLE_TYPE,      EGL_OPENGL_ES_BIT,
                  EGL_NONE
           };

        int totalConfigs = 0;
        if (eglChooseConfig(g_eglDisplay, s_configAttribs, &g_allConfig, 1, &totalConfigs) != EGL_TRUE || totalConfigs == 0)
        {
			TestEGLError();
            fprintf(stderr, "ERROR: Unable to query for available configs.n");
            return 0;
        }
        return 1;
}

void SwapBuffers()
{
        eglSwapBuffers(g_eglDisplay, g_eglSurface);
}

struct SVert
{
        float x,y,z;
};

static GLubyte checkImage[64][64][4];
void CreateCheckImage()
{
        int i, j, c;
        
        for (i = 0; i < 64; ++i)
        {
                for (j = 0; j < 64; ++j)
                {
                        c = ((((i&0x8)==0)^((j&0x8))==0))*255;
                        checkImage[i][j][0] = (GLubyte)c;
                        checkImage[i][j][1] = (GLubyte)c;
                        checkImage[i][j][2] = (GLubyte)c;
                        checkImage[i][j][3] = 255;
                }
        }
}

static struct SVert verts[] = {{0.0f, 1.0f, 0.0f},
							   {-1.0f, -1.0f, 0.0f},
							   {1.0f, -1.0f, 0.0f}};

static float uvs[] = {0.0f, 0.0f,
					  0.0f, 1.0f,
					  1.0f, 1.0f};

//static unsigned short indicies[] = {0,1,2};

void InitLotsOfGL()
{
        glViewport(0, 0, g_screenWidth, g_screenHeight);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

        float xmin, xmax, ymin, ymax;
        ymax = 1.0f * tan((60.0f * M_PI) / 360.0f);
        ymin = -ymax;
        xmin = ymin * ((float)g_screenWidth / g_screenHeight);
        xmax = ymax * ((float)g_screenWidth / g_screenHeight);

        glFrustumf(xmin, xmax, ymin, ymax, 1.0f, 30.0f);
        glMatrixMode(GL_MODELVIEW);

        glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
        
        glEnable(GL_VERTEX_ARRAY);
        glVertexPointer(3, GL_FLOAT, 0, verts);
        
        glTexCoordPointer(2, GL_FLOAT, 0, uvs);
        glEnable(GL_TEXTURE_COORD_ARRAY);
        
        // Create and load the texture
        int h;
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        glGenTextures(1, &h);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        
        // Create the texture data in code (means no loading it from a file)
        CreateCheckImage();
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
        glFrontFace(GL_CCW);
        glDisable(GL_TEXTURE_2D);
        //glDepthRangef(0.0f, 1.0f);
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_DEPTH_RANGE);
        glDisable(GL_STENCIL_TEST);
        glDisable(GL_CULL_FACE);
        glDisable(GL_ALPHA_TEST);
        glDisable(GL_BLEND);
        glDisable(GL_DITHER);
}

void DrawTri( void )
{
    #define VERTTYPE    GLfloat
    #define VERTTYPEENUM    GL_FLOAT
    #define f2vt(x)        (x)
    #define myglLoadMatrix    glLoadMatrixf
    #define myglClearColor    glClearColor  
  
      myglClearColor(f2vt(0.6f), f2vt(0.8f), f2vt(1.0f), f2vt(1.0f)); // clear blue
  
    glClear(GL_COLOR_BUFFER_BIT);

    VERTTYPE pfVertices[] = {    f2vt(-.4f),f2vt(-.4f),f2vt(0),
                                f2vt(+.4f),f2vt(-.4f),f2vt(0),
                                f2vt(0),f2vt(.4f),f2vt(0)
    };
    
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3,VERTTYPEENUM,0,pfVertices);

    // Set color data in the same way (red, green, blue, alpha)
    VERTTYPE pfColors[] = {    f2vt(1.0f), f2vt(1.0f), f2vt(0.66f), f2vt(1.0f),
                            f2vt(1.0f), f2vt(1.0f), f2vt(0.66f), f2vt(1.0f),
                            f2vt(1.0f), f2vt(1.0f), f2vt(0.66f), f2vt(1.0f)};

    glEnableClientState(GL_COLOR_ARRAY);
    glColorPointer(4,VERTTYPEENUM,0,pfColors);

    glDrawArrays(GL_TRIANGLES, 0, 3);
}

int main(int argc, char **argv)
{
#ifndef RAW_MODE
        SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
#else
        SDL_Init(SDL_INIT_TIMER);
#endif
        atexit(SDL_Quit);
        InitEGL();
        FindAppropriateEGLConfigs();
        
#ifndef RAW_MODE
        printf( "Using SDL window surfacen" );
		SDL_Surface *pSurface = SDL_SetVideoMode(g_screenWidth, g_screenHeight, 16, SDL_HWSURFACE);
#endif
        
		if (!InitOpenGL(g_allConfig))
		{
            TestEGLError();  
			fprintf(stderr, "ERROR: Unable to initialise EGL. See previous error.n");
			exit(0);
		}
#ifndef RAW_MODE
		InitLotsOfGL();
                
		float angle = 0.0f;
#endif
		unsigned int timer = SDL_GetTicks() + 10000;
		while(SDL_GetTicks() < timer)
		{
#ifndef RAW_MODE          
			if (SDL_GetTicks() + 5000 > timer)
			{
					glEnable(GL_TEXTURE_2D);
			}
			
			glLoadIdentity();
			glTranslatef(0.0f, 0.0f, -3.6f);
			glRotatef(angle, 0.0f, 1.0f, 0.0f);
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			//glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, indicies);
			glDrawArrays(GL_TRIANGLES, 0, 3);
			angle += 2.5f;
#else
            DrawTri();
#endif
			SwapBuffers();
		}
		printf( "Releasing Opengl-esn" );
		TerminateOpenGL();
        
        printf( "Releasing EGLn" );
        TerminateEGL();
        return 0;
}
 
A quick status update on AVP. I have managed to replace the screen resolution selection stuff so that it lists all supported resolutions (instead of the fixed set of options). Playing it in 320x240 mode is 'interesting' :p. The graphics system should now all be ready to go on the pandora (once SDL/EGL is finally sorted of course!).
Next thing i am investigating is the Joystick input. At the moment it only supports a single analogue stick which isn't really enough for the duel nubbers!
 
Lonewolf9383 said:
A quick status update on AVP. I have managed to replace the screen resolution selection stuff so that it lists all supported resolutions (instead of the fixed set of options). Playing it in 320x240 mode is 'interesting' :p . The graphics system should now all be ready to go on the pandora (once SDL/EGL is finally sorted of course!).
Next thing i am investigating is the Joystick input. At the moment it only supports a single analogue stick which isn't really enough for the duel nubbers!

The SDL/EGL is working fine (although i havnt tried your latest update to GL code). The define in the main was just me switching between the your gl code and my simple triangle.
Also im using it in my Ken's Lab with glDrawElements as a replacement for QUADS and its working for the most part (textures are goofed)

One idea for the analogs, you can use the left and just make it SDL_Pushevent the arrow keys for direction and use the second one to try into the mouse code (but its sounds like you have something to tie into)

I think we can give a go at seeing if anything runs at all, id rather try something today/tonight before the week starts.
 
Last edited by a moderator:
Hi guy, i was wondering if you guys have anymore news on AvsP?, thanks :)
 
Afraid theres not much to share yet. I am kind of stuck till i get my hands on a Pandora to debug it. Pickle has been helping out and giving it a test on his Pandora and the main menu is working great but starting up the game freezes for some reason. Not sure if hes had much of a chance to test some more since i heard from him last.
The good news is i have joysticks fully implemented. The old code used to only allow for a single analogue input (plus the crap hat). Ive replaced it with support for two analogue and also improved the input by smoothing it out to make it more controllable. It also supports setting up sensitivity so it can be tweaked easily. Joystick buttons can also be mapped to any of the controls (i was surprised to find that wasn't already the case!)
Next thing on my list is to tackle multi player, it seems the most obvious thing as its something i can test on my laptop and shouldn't need changing when we get it up and running :)
 
Lonewolf9383 said:
Afraid theres not much to share yet. I am kind of stuck till i get my hands on a Pandora to debug it. Pickle has been helping out and giving it a test on his Pandora and the main menu is working great but starting up the game freezes for some reason. Not sure if hes had much of a chance to test some more since i heard from him last.

Still at the same point, but mainly cause the wiz contest sucked up the weekend ;-)
 
Last edited by a moderator:
I just found this thread, and just wanted to say I'm very excited for this! My OpenGL and GLES experience is somewhat limited, but I'll see what I can contribute when I get my pandora (in about 2 months....). :)
 
Don't know how I missed it either, but thanks to you both for your efforts. This pleases me greatly.
 
Glad to hear you guys have made a little further progress with this, as it will be a killer app (plenty of killing at least) for the Pandora and you will be Dev Gods in at least my eyes :)
 
great work guys, i really cannot wait for this one. I wished there was something i could do to help, but a) not having any experience in programming and b)my pandora left nub dying (i am going to be without a pandora for a while) i cannot really help, other than be just morale support :D (not that you need it of course)
 
I gave this another look last night and tried a couple things like direct linking libGLES_CM.so, but it still always locks up at starting a level.
The app does spit out some lines about Triangles, its from the default case, Opentriangels or Drawtriangles (cant remember)
 
Hey sorry for the lack of updates. The great news is i have networking up and running using SDL_Net on linux and its looking solid (It was great refreshing my old networking skills:) ). Just need to give it a proper test online as i have only run all the clients from the same machine so far but everything looks like its working just like the original game (without the game lobby stuff - it only allows you to connect directly to an ip address).

Pickle - Its great to hear your still finding some time to try and get it working :) . When you tried linking directly to the lib did you just force it using -l on the command line during linking/compiling or did you actually change the code so that all the pgl* function calls directly call the gl* functions? If you just added it to the linker then it probably ignored it as none of the functions in the lib are called directly. If theres no dependencies then the linker normally ignores a lib completely.
I have been tempted to create another test program for you to run that will ensure all the pgl* functions are being found correctly. Would it help?
When it spits out the triangle stuff it might be a little misleading. All it does at that point is add them to an array of verts and faces. It only makes the gl draw calls when either that array is full or the rendering requirements change (texture changes etc..).
 
Lonewolf9383 said:
Hey sorry for the lack of updates. The great news is i have networking up and running using SDL_Net on linux and its looking solid (It was great refreshing my old networking skills:) ). Just need to give it a proper test online as i have only run all the clients from the same machine so far but everything looks like its working just like the original game (without the game lobby stuff - it only allows you to connect directly to an ip address).

Pickle - Its great to hear your still finding some time to try and get it working :) . When you tried linking directly to the lib did you just force it using -l on the command line during linking/compiling or did you actually change the code so that all the pgl* function calls directly call the gl* functions? If you just added it to the linker then it probably ignored it as none of the functions in the lib are called directly. If theres no dependencies then the linker normally ignores a lib completely.
I have been tempted to create another test program for you to run that will ensure all the pgl* functions are being found correctly. Would it help?
When it spits out the triangle stuff it might be a little misleading. All it does at that point is add them to an array of verts and faces. It only makes the gl draw calls when either that array is full or the rendering requirements change (texture changes etc..).

I defined the pgl names as their real gl names and linked during compile time (-lGLES_CM)
 
Last edited by a moderator:
That will rule out my idea of it being related to the pgl* function pointers then.If thats the case then theres a good chance its not related to gl at all which is going to make it harder to track down :(. Perhaps as a final test commenting out the SwapBuffers() call might be worth a try. I had a quick look through the code as i remembered some asm written directly for 386 processors. Turns out all thats already disabled though. Have you been able to run it through a debugger?
 
Lonewolf9383 said:
That will rule out my idea of it being related to the pgl* function pointers then.If thats the case then theres a good chance its not related to gl at all which is going to make it harder to track down :( . Perhaps as a final test commenting out the SwapBuffers() call might be worth a try. I had a quick look through the code as i remembered some asm written directly for 386 processors. Turns out all thats already disabled though. Have you been able to run it through a debugger?

why would commenting out swapbuffers help?
i doubt there is any i386 asm since the compiler would complain about not being able to compile it.
I have and can run it in the debugger, but once it gets to the lockup spot everything locks, so its going to be difficult to pinpoint the bad area.
 
Last edited by a moderator:
Pickle said:
Lonewolf9383 said:
That will rule out my idea of it being related to the pgl* function pointers then.If thats the case then theres a good chance its not related to gl at all which is going to make it harder to track down :( . Perhaps as a final test commenting out the SwapBuffers() call might be worth a try. I had a quick look through the code as i remembered some asm written directly for 386 processors. Turns out all thats already disabled though. Have you been able to run it through a debugger?

why would commenting out swapbuffers help?
i doubt there is any i386 asm since the compiler would complain about not being able to compile it.
I have and can run it in the debugger, but once it gets to the lockup spot everything locks, so its going to be difficult to pinpoint the bad area.
Commenting out the swap buffers would rule out the gpu stalling everything. I don't know too much about its design or driver but its possible that its doing more than just swapping the buffers in that single call (Accessing memory no longer allocated etc.). I admit its very unlikely but with it being GLES 1 (Not the thing of the moment!) instead of 2 there could be some 'interesting' shortcuts being made. Maybe i'm just skeptical though lol :p
The fact thats its locking up the entire system is a bit of a nightmare, i know it locks up my Ubuntu machine when using the codelite debugger and the mouse is fixed to the avp window (ctrl-g locks/unlocks) at the time of a breakpoint or assert. It seems to have some sort of panic attack or something! Have you tried running gdb using the command line version? If you have it visible when the world goes *boom* it might give a hint of the error just before the crash? Its really frustrating that i can't test this myself...come on pandora! :(
 
Last edited by a moderator:
Back
Top