annotate test/testdyngl.c @ 1729:0ef52d56e8bb SDL-1.3

Fixed compile problems with new OpenGL API.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 07 Jul 2006 10:39:33 +0000
parents 4da1ee79c9af
children
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
1659
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents: 1440
diff changeset
22 #ifdef __MACOS__
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents: 1440
diff changeset
23 #define HAVE_OPENGL
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents: 1440
diff changeset
24 #endif
14717b52abc0 Merge trunk-1.3-3
Sam Lantinga <slouken@libsdl.org>
parents: 1440
diff changeset
25
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #ifdef HAVE_OPENGL
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #include "SDL_opengl.h"
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29
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
30 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
31 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
32 quit(int rc)
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
33 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
34 SDL_Quit();
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
35 exit(rc);
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
36 }
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
37
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
38 void *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
39 get_funcaddr(const char *p)
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
41 void *f = SDL_GL_GetProcAddress(p);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
42 if (f) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
43 return f;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
44 } else {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
45 printf("Unable to get function pointer for %s\n", p);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
46 quit(1);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
47 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
48 return NULL;
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 }
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 typedef struct
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
53 void (APIENTRY * glBegin) (GLenum);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
54 void (APIENTRY * glEnd) ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
55 void (APIENTRY * glVertex3f) (GLfloat, GLfloat, GLfloat);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
56 void (APIENTRY * glClearColor) (GLfloat, GLfloat, GLfloat, GLfloat);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
57 void (APIENTRY * glClear) (GLbitfield);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
58 void (APIENTRY * glDisable) (GLenum);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
59 void (APIENTRY * glEnable) (GLenum);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
60 void (APIENTRY * glColor4ub) (GLubyte, GLubyte, GLubyte, GLubyte);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
61 void (APIENTRY * glPointSize) (GLfloat);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
62 void (APIENTRY * glHint) (GLenum, GLenum);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
63 void (APIENTRY * glBlendFunc) (GLenum, GLenum);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
64 void (APIENTRY * glMatrixMode) (GLenum);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
65 void (APIENTRY * glLoadIdentity) ();
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
66 void (APIENTRY * glOrtho) (GLdouble, GLdouble, GLdouble, GLdouble,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
67 GLdouble, GLdouble);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
68 void (APIENTRY * glRotatef) (GLfloat, GLfloat, GLfloat, GLfloat);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
69 void (APIENTRY * glViewport) (GLint, GLint, GLsizei, GLsizei);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
70 void (APIENTRY * glFogf) (GLenum, GLfloat);
839
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 glfuncs;
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
74 void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
75 init_glfuncs(glfuncs * f)
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
77 f->glBegin = get_funcaddr("glBegin");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
78 f->glEnd = get_funcaddr("glEnd");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
79 f->glVertex3f = get_funcaddr("glVertex3f");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
80 f->glClearColor = get_funcaddr("glClearColor");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
81 f->glClear = get_funcaddr("glClear");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
82 f->glDisable = get_funcaddr("glDisable");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
83 f->glEnable = get_funcaddr("glEnable");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
84 f->glColor4ub = get_funcaddr("glColor4ub");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
85 f->glPointSize = get_funcaddr("glPointSize");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
86 f->glHint = get_funcaddr("glHint");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
87 f->glBlendFunc = get_funcaddr("glBlendFunc");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
88 f->glMatrixMode = get_funcaddr("glMatrixMode");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
89 f->glLoadIdentity = get_funcaddr("glLoadIdentity");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
90 f->glOrtho = get_funcaddr("glOrtho");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
91 f->glRotatef = get_funcaddr("glRotatef");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
92 f->glViewport = get_funcaddr("glViewport");
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
93 f->glFogf = get_funcaddr("glFogf");
839
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
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 #define NB_PIXELS 1000
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
98 int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
99 main(int argc, char *argv[])
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
101 glfuncs f;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
102 int i;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
103 SDL_Event event;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
104 int done = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
105 GLfloat pixels[NB_PIXELS * 3];
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
106 const char *gl_library = NULL; /* Use the default GL library */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1386
diff changeset
107
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
108 if (argv[1]) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
109 gl_library = argv[1];
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
110 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
111
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
112 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
113 printf("Unable to init SDL : %s\n", SDL_GetError());
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
114 return (1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
115 }
990
8e20c48a9c13 Restore everything when a function pointer is NULL
Patrice Mandin <patmandin@gmail.com>
parents: 910
diff changeset
116
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
117 if (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1) < 0) {
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
118 printf("Unable to set GL attribute : %s\n", SDL_GetError());
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
119 quit(1);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
120 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
121
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
122 if (SDL_GL_LoadLibrary(gl_library) < 0) {
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
123 printf("Unable to dynamically open GL lib : %s\n", SDL_GetError());
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
124 quit(1);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
125 }
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
127 if (SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL) {
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
128 printf("Unable to open video mode : %s\n", SDL_GetError());
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
129 quit(1);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
130 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
131
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
132 /* Set the window manager title bar */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
133 SDL_WM_SetCaption("SDL Dynamic OpenGL Loading Test", "testdyngl");
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
135 init_glfuncs(&f);
910
4ab6d1fd028f Date: Sat, 26 Jun 2004 14:58:42 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 885
diff changeset
136
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
137 for (i = 0; i < NB_PIXELS; i++) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
138 pixels[3 * i] = rand() % 250 - 125;
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
139 pixels[3 * i + 1] = rand() % 250 - 125;
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
140 pixels[3 * i + 2] = rand() % 250 - 125;
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
141 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
142
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
143 f.glViewport(0, 0, 640, 480);
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
145 f.glMatrixMode(GL_PROJECTION);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
146 f.glLoadIdentity();
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
147 f.glOrtho(-100, 100, -100, 100, -500, 500);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
148
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
149 f.glMatrixMode(GL_MODELVIEW);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
150 f.glLoadIdentity();
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
151
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
152 f.glEnable(GL_DEPTH_TEST);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
153 f.glDisable(GL_TEXTURE_2D);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
154 f.glEnable(GL_BLEND);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
155 f.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
156
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
157 f.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
158 f.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
159
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
160 f.glEnable(GL_POINT_SMOOTH);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
161 f.glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
162 f.glPointSize(5.0f);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
163 f.glEnable(GL_FOG);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
164 f.glFogf(GL_FOG_START, -500);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
165 f.glFogf(GL_FOG_END, 500);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
166 f.glFogf(GL_FOG_DENSITY, 0.005);
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
168 do {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
169 f.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
170
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
171 f.glRotatef(2.0, 1.0, 1.0, 1.0);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
172 f.glRotatef(1.0, 0.0, 1.0, 1.0);
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
174 f.glColor4ub(255, 255, 255, 255);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
175 f.glBegin(GL_POINTS);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
176 for (i = 0; i < NB_PIXELS; i++) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
177 f.glVertex3f(pixels[3 * i], pixels[3 * i + 1], pixels[3 * i + 2]);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
178 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
179 f.glEnd();
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
180 SDL_GL_SwapBuffers();
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
181
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
182 while (SDL_PollEvent(&event)) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
183 if (event.type & SDL_KEYDOWN)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
184 done = 1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
185 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
186
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
187 SDL_Delay(20);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
188 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
189 while (!done);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
190
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
191 SDL_Quit();
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
192 return 0;
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 }
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 #else /* HAVE_OPENGL */
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
197 int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
198 main(int argc, char *argv[])
839
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
200 printf("No OpenGL support on this system\n");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1659
diff changeset
201 return 1;
839
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
7b255f0290da Added a test program for dynamically loading OpenGL
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 #endif /* HAVE_OPENGL */