annotate test/testdyngl.c @ 1439:4d3bb026cd16

Fixed warnings in -pedantic mode
author Sam Lantinga <slouken@libsdl.org>
date Sun, 26 Feb 2006 05:02:14 +0000
parents b5d4f280c960
children ae78374ac894
rev   line source
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 * Small SDL example to demonstrate dynamically loading
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 * OpenGL lib and functions
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 *
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 * (FYI it was supposed to look like snow in the wind or something...)
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 *
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 * Compile with :
847
0afe0e38e02c *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 842
diff changeset
8 * gcc testdyngl.c `sdl-config --libs --cflags` -o testdyngl -DHAVE_OPENGL
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 *
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 * You can specify a different OpenGL lib on the command line, i.e. :
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 * ./testdyngl /usr/X11R6/lib/libGL.so.1.2
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 * or
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 * ./testdyngl /usr/lib/libGL.so.1.0.4496
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14 *
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 */
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 #include <stdio.h>
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 #include <stdlib.h>
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 #include "SDL.h"
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #ifdef HAVE_OPENGL
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #include "SDL_opengl.h"
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
1151
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 990
diff changeset
26 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 990
diff changeset
27 static void quit(int rc)
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 990
diff changeset
28 {
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 990
diff changeset
29 SDL_Quit();
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 990
diff changeset
30 exit(rc);
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 990
diff changeset
31 }
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 990
diff changeset
32
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 void* get_funcaddr(const char* p)
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 {
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 void* f=SDL_GL_GetProcAddress(p);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 if (f)
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 {
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 return f;
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 }
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 else
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 {
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 printf("Unable to get function pointer for %s\n",p);
1151
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 990
diff changeset
43 quit(1);
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 }
1439
4d3bb026cd16 Fixed warnings in -pedantic mode
Sam Lantinga <slouken@libsdl.org>
parents: 1436
diff changeset
45 return NULL;
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 }
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 typedef struct
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 {
885
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
50 void(APIENTRY*glBegin)(GLenum);
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
51 void(APIENTRY*glEnd)();
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
52 void(APIENTRY*glVertex3f)(GLfloat, GLfloat, GLfloat);
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
53 void(APIENTRY*glClearColor)(GLfloat, GLfloat, GLfloat, GLfloat);
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
54 void(APIENTRY*glClear)(GLbitfield);
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
55 void(APIENTRY*glDisable)(GLenum);
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
56 void(APIENTRY*glEnable)(GLenum);
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
57 void(APIENTRY*glColor4ub)(GLubyte,GLubyte,GLubyte,GLubyte);
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
58 void(APIENTRY*glPointSize)(GLfloat);
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
59 void(APIENTRY*glHint)(GLenum,GLenum);
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
60 void(APIENTRY*glBlendFunc)(GLenum,GLenum);
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
61 void(APIENTRY*glMatrixMode)(GLenum);
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
62 void(APIENTRY*glLoadIdentity)();
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
63 void(APIENTRY*glOrtho)(GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble);
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
64 void(APIENTRY*glRotatef)(GLfloat,GLfloat,GLfloat,GLfloat);
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
65 void(APIENTRY*glViewport)(GLint,GLint,GLsizei,GLsizei);
9f6ad2286011 Date: Wed, 28 Apr 2004 16:52:41 -0400
Sam Lantinga <slouken@libsdl.org>
parents: 847
diff changeset
66 void(APIENTRY*glFogf)(GLenum,GLfloat);
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 }
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 glfuncs;
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 void init_glfuncs(glfuncs* f)
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 {
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 f->glBegin=get_funcaddr("glBegin");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 f->glEnd=get_funcaddr("glEnd");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 f->glVertex3f=get_funcaddr("glVertex3f");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 f->glClearColor=get_funcaddr("glClearColor");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 f->glClear=get_funcaddr("glClear");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 f->glDisable=get_funcaddr("glDisable");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 f->glEnable=get_funcaddr("glEnable");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 f->glColor4ub=get_funcaddr("glColor4ub");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 f->glPointSize=get_funcaddr("glPointSize");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 f->glHint=get_funcaddr("glHint");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 f->glBlendFunc=get_funcaddr("glBlendFunc");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 f->glMatrixMode=get_funcaddr("glMatrixMode");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 f->glLoadIdentity=get_funcaddr("glLoadIdentity");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 f->glOrtho=get_funcaddr("glOrtho");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 f->glRotatef=get_funcaddr("glRotatef");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 f->glViewport=get_funcaddr("glViewport");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 f->glFogf=get_funcaddr("glFogf");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 }
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 #define NB_PIXELS 1000
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 int main(int argc,char *argv[])
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 {
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 glfuncs f;
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 int i;
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 SDL_Event event;
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 int done=0;
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 GLfloat pixels[NB_PIXELS*3];
1436
b5d4f280c960 Use the right dynamic GL on MacOS Classic
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
100 #if defined(__WIN32__)
b5d4f280c960 Use the right dynamic GL on MacOS Classic
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
101 const char *gl_library = "OpenGL32.DLL";
b5d4f280c960 Use the right dynamic GL on MacOS Classic
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
102 #elif defined(__MACOS__)
b5d4f280c960 Use the right dynamic GL on MacOS Classic
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
103 const char *gl_library = "OpenGLLibrary";
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1386
diff changeset
104 #elif defined(__MACOSX__)
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1386
diff changeset
105 const char *gl_library = "/usr/X11R6/lib/libGL.1.dylib";
1436
b5d4f280c960 Use the right dynamic GL on MacOS Classic
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
106 #elif defined(__IRIX__)
b5d4f280c960 Use the right dynamic GL on MacOS Classic
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
107 const char *gl_library = "libGL.so";
910
4ab6d1fd028f Date: Sat, 26 Jun 2004 14:58:42 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 885
diff changeset
108 #elif defined(__QNXNTO__)
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1386
diff changeset
109 const char *gl_library = "libGL.so.3";
842
0eec9985767d Load the correct library on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 839
diff changeset
110 #else
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1386
diff changeset
111 const char *gl_library = "libGL.so.1";
842
0eec9985767d Load the correct library on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 839
diff changeset
112 #endif
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1386
diff changeset
113
842
0eec9985767d Load the correct library on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 839
diff changeset
114 if (argv[1]) {
0eec9985767d Load the correct library on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 839
diff changeset
115 gl_library = argv[1];
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 }
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117
842
0eec9985767d Load the correct library on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 839
diff changeset
118 if (SDL_Init(SDL_INIT_VIDEO)<0)
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 {
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 printf("Unable to init SDL : %s\n",SDL_GetError());
1151
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 990
diff changeset
121 return(1);
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 }
990
8e20c48a9c13 Restore everything when a function pointer is NULL
Patrice Mandin <patmandin@gmail.com>
parents: 910
diff changeset
123
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 if (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1)<0)
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 {
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 printf("Unable to set GL attribute : %s\n",SDL_GetError());
1151
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 990
diff changeset
127 quit(1);
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 }
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129
842
0eec9985767d Load the correct library on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 839
diff changeset
130 if (SDL_GL_LoadLibrary(gl_library)<0)
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 {
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 printf("Unable to dynamically open GL lib : %s\n",SDL_GetError());
1151
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 990
diff changeset
133 quit(1);
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 }
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 if (SDL_SetVideoMode(640,480,0,SDL_OPENGL)==NULL)
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 {
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 printf("Unable to open video mode : %s\n",SDL_GetError());
1151
be9c9c8f6d53 Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents: 990
diff changeset
139 quit(1);
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 }
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141
910
4ab6d1fd028f Date: Sat, 26 Jun 2004 14:58:42 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 885
diff changeset
142 /* Set the window manager title bar */
4ab6d1fd028f Date: Sat, 26 Jun 2004 14:58:42 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 885
diff changeset
143 SDL_WM_SetCaption( "SDL Dynamic OpenGL Loading Test", "testdyngl" );
4ab6d1fd028f Date: Sat, 26 Jun 2004 14:58:42 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 885
diff changeset
144
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 init_glfuncs(&f);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 for(i=0;i<NB_PIXELS;i++)
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 {
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 pixels[3*i]=rand()%250-125;
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 pixels[3*i+1]=rand()%250-125;
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 pixels[3*i+2]=rand()%250-125;
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 }
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 f.glViewport(0,0,640,480);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 f.glMatrixMode(GL_PROJECTION);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 f.glLoadIdentity();
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 f.glOrtho(-100,100,-100,100,-500,500);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 f.glMatrixMode(GL_MODELVIEW);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 f.glLoadIdentity();
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 f.glEnable(GL_DEPTH_TEST);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 f.glDisable(GL_TEXTURE_2D);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 f.glEnable(GL_BLEND);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 f.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 f.glClearColor(0.0f,0.0f,0.0f,0.0f);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 f.glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 f.glEnable(GL_POINT_SMOOTH);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 f.glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 f.glPointSize(5.0f);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 f.glEnable(GL_FOG);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 f.glFogf(GL_FOG_START,-500);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 f.glFogf(GL_FOG_END,500);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 f.glFogf(GL_FOG_DENSITY,0.005);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 do
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 {
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 f.glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 f.glRotatef(2.0,1.0,1.0,1.0);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 f.glRotatef(1.0,0.0,1.0,1.0);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 f.glColor4ub(255,255,255,255);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 f.glBegin(GL_POINTS);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 for(i=0;i<NB_PIXELS;i++)
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 {
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 f.glVertex3f(pixels[3*i],pixels[3*i+1],pixels[3*i+2]);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 }
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 f.glEnd();
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 SDL_GL_SwapBuffers();
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 while(SDL_PollEvent(&event))
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 {
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 if(event.type & SDL_KEYDOWN)
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 done=1;
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 }
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 SDL_Delay(20);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 }
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 while(!done);
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 SDL_Quit();
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 return 0;
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 }
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 #else /* HAVE_OPENGL */
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 int main(int argc, char *argv[])
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 {
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 printf("No OpenGL support on this system\n");
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 return 1;
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 }
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 #endif /* HAVE_OPENGL */