Lonewolf9383
Still Fresh
- Joined
 - May 9, 2008
 
- Messages
 - 35
 
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...
 
	
	
	
		
				
			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;
}
	
	