diff -r ffa851df0825 -r 2fb8b9db1c86 symbian-qemu-0.9.1-12/libsdl-trunk/test/testdyngl.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/symbian-qemu-0.9.1-12/libsdl-trunk/test/testdyngl.c Fri Jul 31 15:01:17 2009 +0100 @@ -0,0 +1,209 @@ +/* + * Small SDL example to demonstrate dynamically loading + * OpenGL lib and functions + * + * (FYI it was supposed to look like snow in the wind or something...) + * + * Compile with : + * gcc testdyngl.c `sdl-config --libs --cflags` -o testdyngl -DHAVE_OPENGL + * + * You can specify a different OpenGL lib on the command line, i.e. : + * ./testdyngl /usr/X11R6/lib/libGL.so.1.2 + * or + * ./testdyngl /usr/lib/libGL.so.1.0.4496 + * + */ + +#include +#include + +#include "SDL.h" + +#ifdef __MACOS__ +#define HAVE_OPENGL +#endif + +#ifdef HAVE_OPENGL + +#include "SDL_opengl.h" + +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ +static void quit(int rc) +{ + SDL_Quit(); + exit(rc); +} + +void* get_funcaddr(const char* p) +{ + void* f=SDL_GL_GetProcAddress(p); + if (f) + { + return f; + } + else + { + printf("Unable to get function pointer for %s\n",p); + quit(1); + } + return NULL; +} + +typedef struct +{ + void(APIENTRY*glBegin)(GLenum); + void(APIENTRY*glEnd)(); + void(APIENTRY*glVertex3f)(GLfloat, GLfloat, GLfloat); + void(APIENTRY*glClearColor)(GLfloat, GLfloat, GLfloat, GLfloat); + void(APIENTRY*glClear)(GLbitfield); + void(APIENTRY*glDisable)(GLenum); + void(APIENTRY*glEnable)(GLenum); + void(APIENTRY*glColor4ub)(GLubyte,GLubyte,GLubyte,GLubyte); + void(APIENTRY*glPointSize)(GLfloat); + void(APIENTRY*glHint)(GLenum,GLenum); + void(APIENTRY*glBlendFunc)(GLenum,GLenum); + void(APIENTRY*glMatrixMode)(GLenum); + void(APIENTRY*glLoadIdentity)(); + void(APIENTRY*glOrtho)(GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble); + void(APIENTRY*glRotatef)(GLfloat,GLfloat,GLfloat,GLfloat); + void(APIENTRY*glViewport)(GLint,GLint,GLsizei,GLsizei); + void(APIENTRY*glFogf)(GLenum,GLfloat); +} +glfuncs; + +void init_glfuncs(glfuncs* f) +{ + f->glBegin=get_funcaddr("glBegin"); + f->glEnd=get_funcaddr("glEnd"); + f->glVertex3f=get_funcaddr("glVertex3f"); + f->glClearColor=get_funcaddr("glClearColor"); + f->glClear=get_funcaddr("glClear"); + f->glDisable=get_funcaddr("glDisable"); + f->glEnable=get_funcaddr("glEnable"); + f->glColor4ub=get_funcaddr("glColor4ub"); + f->glPointSize=get_funcaddr("glPointSize"); + f->glHint=get_funcaddr("glHint"); + f->glBlendFunc=get_funcaddr("glBlendFunc"); + f->glMatrixMode=get_funcaddr("glMatrixMode"); + f->glLoadIdentity=get_funcaddr("glLoadIdentity"); + f->glOrtho=get_funcaddr("glOrtho"); + f->glRotatef=get_funcaddr("glRotatef"); + f->glViewport=get_funcaddr("glViewport"); + f->glFogf=get_funcaddr("glFogf"); +} + +#define NB_PIXELS 1000 + +int main(int argc,char *argv[]) +{ + glfuncs f; + int i; + SDL_Event event; + int done=0; + GLfloat pixels[NB_PIXELS*3]; + const char *gl_library = NULL; /* Use the default GL library */ + + if (argv[1]) { + gl_library = argv[1]; + } + + if (SDL_Init(SDL_INIT_VIDEO)<0) + { + printf("Unable to init SDL : %s\n",SDL_GetError()); + return(1); + } + + if (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1)<0) + { + printf("Unable to set GL attribute : %s\n",SDL_GetError()); + quit(1); + } + + if (SDL_GL_LoadLibrary(gl_library)<0) + { + printf("Unable to dynamically open GL lib : %s\n",SDL_GetError()); + quit(1); + } + + if (SDL_SetVideoMode(640,480,0,SDL_OPENGL)==NULL) + { + printf("Unable to open video mode : %s\n",SDL_GetError()); + quit(1); + } + + /* Set the window manager title bar */ + SDL_WM_SetCaption( "SDL Dynamic OpenGL Loading Test", "testdyngl" ); + + init_glfuncs(&f); + + for(i=0;i