#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <SDL/SDL.h>
#include <GLES/gl.h>
#define _INT_TO_FIXED(i) ((GLfixed)((i)<<16))
#define _FLOAT_TO_FIXED(i) ((GLfixed)((i)*65536.0f))
void Terminate()
{
chdir("/usr/gp2x");
execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", NULL);
}
int main()
{
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) <0) return -1;
atexit(Terminate);
//WARNING: The surface "screen" is just a dummy surface for save screen information.
SDL_Surface *screen = SDL_SetVideoMode(320, 240, 16, SDL_OPENGL);
if(!screen) return -1;
SDL_Joystick *joy;
/* Check and open joystick device */
if (SDL_NumJoysticks() > 0) {
joy = SDL_JoystickOpen(0);
if(!joy) {
fprintf (stderr, "Couldn't open joystick 0: %s\n", SDL_GetError ());
}
}
glClearColorx(0,0,0,0);
glViewport(0,0,320,240);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthox(0,_INT_TO_FIXED(320),0,_INT_TO_FIXED(240),0,_INT_TO_FIXED(-1));
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);
glEnableClientState(GL_VERTEX_ARRAY);
const GLfixed vertices[]={_FLOAT_TO_FIXED(-0.5f),_FLOAT_TO_FIXED(-0.5f),_FLOAT_TO_FIXED(-0.5f),_FLOAT_TO_FIXED(0.5f),
_FLOAT_TO_FIXED(0.5f),_FLOAT_TO_FIXED(-0.5f),_FLOAT_TO_FIXED(0.5f),_FLOAT_TO_FIXED(0.5f)};
int done =0;
while(!done)
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
if(event.type == SDL_JOYBUTTONDOWN)
done=1;
}
glClear(GL_COLOR_BUFFER_BIT);
glColor4x(_INT_TO_FIXED(1),0,_INT_TO_FIXED(1),_INT_TO_FIXED(1));
glPushMatrix();
glTranslatex(_FLOAT_TO_FIXED((float)64*0.5f),_FLOAT_TO_FIXED((float)64*0.5f),0);
glScalex(_INT_TO_FIXED(64),_INT_TO_FIXED(64),0);
glVertexPointer(2,GL_FIXED,0,vertices);
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
glPopMatrix();
SDL_GL_SwapBuffers();
SDL_Delay(30);
}
SDL_JoystickClose(joy);
SDL_Quit();
return 0;
}