It might not be the best but this is what I used
Code:
#include "SDL/SDL.h"
#include "GL/GL.h"
#include "GL/GLU.h"
#define scrX 1024
#define scrY 768
#define scrZ 32
#define SDLFLAGS SDL_OPENGL|SDL_HWSURFACE
GLvoid init(void);
GLvoid process(void);
GLvoid finalise(void);
GLvoid Events(int*, SDL_Event);
GLuint texid[2];
int main(int argc, char *argv[]){
init();
process();
finalise();
return 0;
}
GLvoid init(void){
// Set up SDL
if(SDL_Init(SDL_INIT_VIDEO) < 0){
printf("Error loading SDL: %s\n",SDL_GetError());
}
if(SDL_SetVideoMode(scrX, scrY, scrZ, SDLFLAGS) < 0){
printf("Error setting video mode SDL: %s\n",SDL_GetError());
}
SDL_ShowCursor(SDL_DISABLE);
SDL_WM_SetCaption("OpenGL",NULL);
// Set up view port
glViewport (0, 0, scrX, scrY);
// Set up perspective etc...
gluPerspective( 45.0f, (GLfloat)(scrX)/(GLfloat)(scrY), 0.1f, 1000.0f );
glMatrixMode (GL_MODELVIEW);
glShadeModel (GL_SMOOTH);
glClearColor (0.0f, 0.0f, 0.5f, 0.0f);
glClearDepth (1.0f);
glEnable (GL_DEPTH_TEST);
glDepthFunc (GL_LEQUAL);
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glLoadIdentity();
}
void process(void){
int done = 0;
SDL_Event event;
while (!done){
Events(&done, event);
SDL_GL_SwapBuffers();
}
}
GLvoid Events(int *done, SDL_Event event){
//static Uint8 *keys = SDL_GetKeyState(NULL);;
while ( SDL_PollEvent(&event) ){
if( event.type == SDL_QUIT ){
*done = 1;
}
if ( event.type == SDL_KEYDOWN ){
if ( event.key.keysym.sym == SDLK_ESCAPE ){
*done = 1;
}
}
}
}
void finalise(void){
SDL_Quit();
}