Avp Incoming...!


Lonewolf9383

Still Fresh
Joined
May 9, 2008
Messages
35
Hi everyone. I don't post on these forums much but ive been lurking around waiting for my panda and working on a gp2x game :)
Well i got fed up waiting and decided to start porting AvP over to open GLES 1 and i'm happy to say its compiling and linking (with a couple of minor bugs). I used the original source from http://icculus.org/avp.
Now i just need my panda to finish it off (Doh) :( .

Until then i have plenty of other things to look at. The network stuff is currently disabled so going to investigate it a bit and perhaps look at a little auto aim feature (toggle it in menus) for making it a bit more playable without a mouse.

Well thats my good news for the day. Back to lurking me thinks... :ph34r:
 
Lonewolf9383 said:
Hi everyone. I don't post on these forums much but ive been lurking around waiting for my panda and working on a gp2x game :)
Well i got fed up waiting and decided to start porting AvP over to open GLES 1 and i'm happy to say its compiling and linking (with a couple of minor bugs). I used the original source from http://icculus.org/avp.
Now i just need my panda to finish it off (Doh) :( .

Until then i have plenty of other things to look at. The network stuff is currently disabled so going to investigate it a bit and perhaps look at a little auto aim feature (toggle it in menus) for making it a bit more playable without a mouse.

Well thats my good news for the day. Back to lurking me thinks... :ph34r:

interesting, i spend some time on this, but converting opengl to opengles was beyond what i knew. I tried to use nanogl. I have a couple questions...
did you convert all of the SDL menu stuff over to EGL (SDL with opengles doesnt work with standard SDL 1.2)
have you run this through the opengles emulator?

id be happy to assist with getting this done earlier if it means testing, coding, etc
 
Last edited by a moderator:
This is my first adventure into GLES land so its a bit of a learning curve. I didnt think about if SDL was compatable with GLES. After setting up the GLES emulator libs i was able to test it and your right they dont play nice with each other :(

I spent a bit of time on it over the weekend and have managed to get EGL to use the SDL window. The only problem is the rendered screen is a mess (black with white boxes where the GUI text and panels should be). At a guess its something to do with textures but im not sure. I will have to try narowing it down to either SDL, EGL, GLES or the game code.
The good news is the main menu runs in its own SDL window. When it starts the game its recreated with the ingame resolution and only then does it use GLES. This means the menu can stay as it is and then i can just setup the ingame window with all the EGL stuff.

I am trying to keep it cross platform as much as i can so it can run both OpenGL and GLES. So far its been fairly easy to do this as the majority of GL calls are identical. As it turns out changing the code from gl to gles was quite easy its the window setup stuff thats taking the time :rolleyes:

Thanks for the tips. I might take you up on the offer to test once i have something working. It will be very interesting to see how well it runs on the pandora as is.
 
Lonewolf9383 said:
This is my first adventure into GLES land so its a bit of a learning curve. I didnt think about if SDL was compatable with GLES. After setting up the GLES emulator libs i was able to test it and your right they dont play nice with each other :(

I spent a bit of time on it over the weekend and have managed to get EGL to use the SDL window. The only problem is the rendered screen is a mess (black with white boxes where the GUI text and panels should be). At a guess its something to do with textures but im not sure. I will have to try narowing it down to either SDL, EGL, GLES or the game code.
The good news is the main menu runs in its own SDL window. When it starts the game its recreated with the ingame resolution and only then does it use GLES. This means the menu can stay as it is and then i can just setup the ingame window with all the EGL stuff.

I am trying to keep it cross platform as much as i can so it can run both OpenGL and GLES. So far its been fairly easy to do this as the majority of GL calls are identical. As it turns out changing the code from gl to gles was quite easy its the window setup stuff thats taking the time :rolleyes:

Thanks for the tips. I might take you up on the offer to test once i have something working. It will be very interesting to see how well it runs on the pandora as is.

This reminds me, I'm looking to learn OpenGLES also as I need it to port some SDL programs, and I thought there wouldn't be any need to touch anything other than the OpenGL calls, thanks to the extra changes Cpasjuste added to SDL.
I'm meaning this: http://pandorawiki.org/Combining_OpenGL_ES_1.1_and_SDL_to_create_a_window_on_the_Pandora

Is it actually included on the pandora? As in, avoiding having to compile our own version an include it on the pnd, or better, if it is included on the official SDL source.

What is the status of such changes.
 
Last edited by a moderator:
Eureka!!! Ive spent the last few days trying to get a version of EGL playing nice with SDL 1.2 and i think ive cracked it (it works on my GLES emulator + standard SDL 1.2 lib). If it works on the pandora then there will be no need for confusing which SDL lib is required.
Anyone willing to try a simple test on there pandora for me?

Im not sure which version of SDL 1.2 is included in the stock pandora but its probably just the standard version without cpasjustes changes (at a guess).

I spent some time looking through the available options:

  • SDL 1.3 is still not mature enough in my opinion. It also requires a number of changes as its not backwards compatable. One day i might take a look if it get the time but for me at the moment its a big unknown :(
  • Cpasjuste SDL 1.2 modified version is definatly promising. I wanted to avoid it however as it starts to move into 'pandora' specific code. In order for it to run on other GLES platforms they would also need the custom changes to sdl (or a completly different method of window management!).
  • EGL + SDL - Requires additional code to set up the rendering context. Allows use with standard SDL 1.2 libs. Ive put the appropriate code on the wiki for anyone whos interested (http://pandorawiki.org/Combining_OpenGL_ES_1.1_and_SDL_to_create_a_window_on_the_Pandora)
So back to AVP. The good news is that its running under GLES emulator and its looking good. Just the one function to convert over (which is currently only being used for the loading bar). I managed to play through the first marine level under GLES.
All in all its looking good B)
 
Lonewolf9383 said:
I managed to play through the first marine level under GLES.
All in all its looking good B)

Great news indeed :lol: !

Keep going Lonewolf ;) and may the force be with you :)
 
Last edited by a moderator:
Nice work Lonewolf, i am looking forward to this one!
 
Lonewolf9383 said:
Eureka!!! Ive spent the last few days trying to get a version of EGL playing nice with SDL 1.2 and i think ive cracked it (it works on my GLES emulator + standard SDL 1.2 lib). If it works on the pandora then there will be no need for confusing which SDL lib is required.
Anyone willing to try a simple test on there pandora for me?

I told you i was more than willing to test anything (just point me to the source) ;-)
Im skeptical about the stock SDL 1.2 working with opengles. Adventus had something similar with the glesn64 pluginm where he was trying to ue SDL with gles and it worked in the emulator but NOT on the pandora. But if your method works all the better.
 
Last edited by a moderator:
Pickle said:
Lonewolf9383 said:
Eureka!!! Ive spent the last few days trying to get a version of EGL playing nice with SDL 1.2 and i think ive cracked it (it works on my GLES emulator + standard SDL 1.2 lib). If it works on the pandora then there will be no need for confusing which SDL lib is required.
Anyone willing to try a simple test on there pandora for me?

I told you i was more than willing to test anything (just point me to the source) ;-)
Im skeptical about the stock SDL 1.2 working with opengles. Adventus had something similar with the glesn64 pluginm where he was trying to ue SDL with gles and it worked in the emulator but NOT on the pandora. But if your method works all the better.
Yes this is interesting... I personally had trouble getting SDL and GLES working nicely together directly. I ended up having to use EGL to create the window and forgo SDL input handling... and write direct linux input handling for Pandora.
If it works on the Pandora itself, that's great news.
 
Last edited by a moderator:
Thanks for testing it out pickle :)

Ive included some simple test code below, just copy it and save it into a .c file. Its very simple and just displays a rotating textured triangle. The texture is generated in code so theres no need for any other files. Ive tried to include enough error checks to try and catch where in the EGL code it might go wrong. If theres an error in the config part then its possible that it just needs to use another config.

I'm hoping this works straight away though *Fingers crossed*

It will need to be linked against the libs 'EGL', 'SDL' and 'GLES'

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;

int FindAppropriateEGLConfig(EGLConfig *pReturnConfig);

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

/*===========================================================
Initialise OpenGL settings
===========================================================*/
int InitOpenGL()
{
	// use EGL to initialise GLES
	//g_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
        Display *display = XOpenDisplay(NULL);
	if (!display)
	{
		fprintf(stderr, "ERROR: unable to get display!");
		return 0;
	}
	
	g_eglDisplay = eglGetDisplay((EGLNativeDisplayType)display);	
        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;
	}
	
	// Find a matching config
	if (!FindAppropriateEGLConfig(&g_eglConfig))
	{
		fprintf(stderr, "ERROR: Unable to find appropriate EGL config.");
		return 0;
	}
	
	// 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, g_eglConfig, (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, g_eglConfig, 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);
	eglDestroySurface(g_eglDisplay, g_eglSurface);
	eglDestroyContext(g_eglDisplay, g_eglContext);
	g_eglSurface = 0;
	g_eglContext = 0;
	g_eglConfig = 0;
	eglTerminate(g_eglDisplay);
	g_eglDisplay = 0;
}

/*=======================================================
* Detect available video resolutions
=======================================================*/
int FindAppropriateEGLConfig(EGLConfig *pReturnConfig)
{
	EGLBoolean result;
	EGLConfig configs[6];
	
	EGLint numConfigsIn = 0;
	EGLint numConfigsOut = 0;
	
	static const EGLint s_configAttribs[] =
	   {
		  EGL_RED_SIZE,      5,
		  EGL_GREEN_SIZE,    6,
		  EGL_BLUE_SIZE,      5,
		  EGL_SURFACE_TYPE,         EGL_WINDOW_BIT,
		  EGL_RENDERABLE_TYPE,      EGL_OPENGL_ES_BIT,
		  EGL_NONE
	   };

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

	EGLConfig *pConfigs = malloc(sizeof(EGLConfig) * numConfigsOut);
	memset(pConfigs, 0, sizeof(EGLConfig) * numConfigsOut);
	numConfigsIn = numConfigsOut;
	numConfigsOut = 0;
	if (eglChooseConfig(g_eglDisplay, s_configAttribs, pConfigs, numConfigsIn, &numConfigsOut) != EGL_TRUE)
	{
		EGLint error =  eglGetError();
		printf("ERROR: Unable to get config on second attempt!");
		return 0;
	}

	// Find the first one
	*pReturnConfig = pConfigs[0];
	free(pConfigs);
	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};

int main(int argc, char **argv)
{
	SDL_Init(SDL_INIT_VIDEO);
	atexit(SDL_Quit);
	
	SDL_Surface *pSurface = SDL_SetVideoMode(g_screenWidth, g_screenHeight, 16, SDL_HWSURFACE);
	
	if (!InitOpenGL())
	{
		fprintf(stderr, "ERROR: Unable to initialise EGL. See previous error.");
	}
	
	glViewport(0, 0, g_screenWidth, g_screenHeight);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	float xmin, xmax, ymin, ymax;
	ymax = 1.0f * tan(60 * M_PI / 360.0);
	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, 0, 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);
	glEnable(GL_TEXTURE_2D);
	
	float angle = 0.0f;
	while(1)
	{
		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 += 1.0f;
		SwapBuffers();
	}
	return 0;
}
 
Lonewolf9383,

Code:
g_eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
will most likely fail with the current EGL libs found on pandora. if you want to see an example of a working EGL usecase on pandora, check the code linked in this thread.
 
Last edited by a moderator:
Lonewolf9383 said:
Thanks for testing it out pickle :)

Ive included some simple test code below, just copy it and save it into a .c file. Its very simple and just displays a rotating textured triangle. The texture is generated in code so theres no need for any other files. Ive tried to include enough error checks to try and catch where in the EGL code it might go wrong. If theres an error in the config part then its possible that it just needs to use another config.

I'm hoping this works straight away though *Fingers crossed*

It will need to be linked against the libs 'EGL', 'SDL' and 'GLES'

ok will test when im home
Although i meant the avp source :D , but anyway this should prove the SDL point which is critical.
 
Last edited by a moderator:
Thanks for the tip darkblu you might have just saved us some headaches :)
I amended the code to include the fix.

I considered sending over avp but then realised theres so many things that could go wrong with it at this point it would be a nightmare! lol :unsure:
 
Lonewolf9383 said:
I considered sending over avp but then realised theres so many things that could go wrong with it at this point it would be a nightmare! lol :unsure:

yeah, not a bad idea....but some bad news it only does a blue screen, no triangle
 
Last edited by a moderator:
Thats odd, i didn't expect that. The fact that its drawing the blue screen suggests the context is being created and used correctly so thats a good sign. SDL and EGL might not be great friends but at least we got them to the negotiating table :p
Can you try disabling the texturing by commenting out the line
'glBindTexture(GL_TEXTURE_2D, h);'.
Did you change anything in the code such as the screen resolution? I removed most of the gl initialisation code to keep the sample small but i guess GLES on the pandora may have slightly different defaults to the GLES emulator im using.
 
Lonewolf9383 said:
Thats odd, i didn't expect that. The fact that its drawing the blue screen suggests the context is being created and used correctly so thats a good sign. SDL and EGL might not be great friends but at least we got them to the negotiating table :p
Can you try disabling the texturing by commenting out the line
'glBindTexture(GL_TEXTURE_2D, h);'.
Did you change anything in the code such as the screen resolution? I removed most of the gl initialisation code to keep the sample small but i guess GLES on the pandora may have slightly different defaults to the GLES emulator im using.

yeah i get the same color window in quake 1/2, so seems its doing something. I did a little look over, but see anything bad. I do a closer compare to my EGL routines and see if can get something going.
Another odd thing is that i added a simple timeout for the while loop and at the end of the loop the system locks up, only the mouse courser moves.
 
Last edited by a moderator:
It seems there might be problems with some GLES defaults. I found reference to the depth buffer defaulting to 0 instead of 1 like in the standard GL (i've lost the link now doh! :( )
You might want to try changing the config attribs to include depth size:

Code:
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
           };

A call to glDepthRangef(0.0f, 1.0f); after setting the viewport might help too.
I will take a look at setting up more values tonight as well as a way to try every config that is found one after the other. Perhaps the first config thats returned is not the best one.
The crash on exit might be because i forgot to put a call to TerminateOpenGL() after the while loop. It needs to be called before the SDL window is destroyed.
 
Lonewolf9383 said:
The crash on exit might be because i forgot to put a call to TerminateOpenGL() after the while loop. It needs to be called before the SDL window is destroyed.

I thought so too, so i added it but stills locks up.
 
Last edited by a moderator:
Back
Top