get rid of unused span->start field
[mesa.git] / progs / miniglx / miniglxtest.c
1 /* $Id: miniglxtest.c,v 1.3 2004/03/25 14:58:39 brianp Exp $ */
2
3 /*
4 * Test the mini GLX interface.
5 */
6
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <GL/gl.h>
12 #define USE_MINI_GLX 1
13 #if USE_MINI_GLX
14 #include <GL/miniglx.h>
15 #else
16 #include <GL/glx.h>
17 #endif
18
19 #define FRONTBUFFER 1
20 #define NR 6
21 #define DO_SLEEPS 1
22 #define NR_DISPLAYS 2
23
24 GLXContext ctx;
25
26
27 static void _subset_Rectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 )
28 {
29 glBegin( GL_QUADS );
30 glVertex2f( x1, y1 );
31 glVertex2f( x2, y1 );
32 glVertex2f( x2, y2 );
33 glVertex2f( x1, y2 );
34 glEnd();
35 }
36
37
38
39 static void redraw( Display *dpy, Window w, int rot )
40 {
41 printf("Redraw event\n");
42
43 #if FRONTBUFFER
44 glDrawBuffer( GL_FRONT );
45 #else
46 /* glDrawBuffer( GL_BACK ); */
47 #endif
48
49 glClearColor( rand()/(float)RAND_MAX,
50 rand()/(float)RAND_MAX,
51 rand()/(float)RAND_MAX,
52 1);
53
54 glClear( GL_COLOR_BUFFER_BIT );
55
56 #if 1
57 glColor3f( rand()/(float)RAND_MAX,
58 rand()/(float)RAND_MAX,
59 rand()/(float)RAND_MAX );
60 glPushMatrix();
61 glRotatef(rot, 0, 0, 1);
62 glScalef(.5, .5, .5);
63 _subset_Rectf( -1, -1, 1, 1 );
64 glPopMatrix();
65 #endif
66
67 #if FRONTBUFFER
68 glFlush();
69 #else
70 glXSwapBuffers( dpy, w );
71 #endif
72 glFinish();
73 }
74
75
76 static Window make_rgb_db_window( Display *dpy,
77 unsigned int width, unsigned int height )
78 {
79 int attrib[] = { GLX_RGBA,
80 GLX_RED_SIZE, 1,
81 GLX_GREEN_SIZE, 1,
82 GLX_BLUE_SIZE, 1,
83 #if !FRONTBUFFER
84 GLX_DOUBLEBUFFER,
85 #endif
86 None };
87 int scrnum;
88 XSetWindowAttributes attr;
89 unsigned long mask;
90 Window root;
91 Window win;
92 XVisualInfo *visinfo;
93
94 scrnum = 0;
95 root = RootWindow( dpy, scrnum );
96
97 if (!(visinfo = glXChooseVisual( dpy, scrnum, attrib ))) {
98 printf("Error: couldn't get an RGB, Double-buffered visual\n");
99 exit(1);
100 }
101
102 if(!(ctx = glXCreateContext( dpy, visinfo, NULL, True ))) {
103 printf("Error: glXCreateContext failed\n");
104 exit(1);
105 }
106
107 /* window attributes */
108 attr.background_pixel = 0;
109 attr.border_pixel = 0;
110 attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
111 attr.event_mask = StructureNotifyMask | ExposureMask;
112 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
113
114 win = XCreateWindow( dpy, root, 0, 0, width, height,
115 0, visinfo->depth, InputOutput,
116 visinfo->visual, mask, &attr );
117 if (!win) {
118 printf("Error: XCreateWindow failed\n");
119 exit(1);
120 }
121
122 glXMakeCurrent( dpy, win, ctx );
123
124 glViewport(0, 0, width, height);
125
126 return win;
127 }
128
129
130 static void event_loop( Display *dpy, Window win )
131 {
132 int i;
133
134 printf("Hang on... drawing %d frames\n", NR);
135 for (i = 0; i < NR; i++) {
136 redraw( dpy, win, i*10 );
137 if (DO_SLEEPS) {
138 printf("sleep(1)\n");
139 sleep(1);
140 }
141 }
142 }
143
144
145 static int foo( void )
146 {
147 Display *dpy;
148 Window win;
149
150 dpy = XOpenDisplay(NULL);
151 if (!dpy) {
152 printf("Error: XOpenDisplay failed\n");
153 return 1;
154 }
155
156 win = make_rgb_db_window( dpy, 800, 600);
157
158 srand(getpid());
159
160 glShadeModel( GL_FLAT );
161 glClearColor( 0.5, 0.5, 0.5, 1.0 );
162
163 XMapWindow( dpy, win );
164
165 {
166 XEvent e;
167 while (1) {
168 XNextEvent( dpy, &e );
169 if (e.type == MapNotify && e.xmap.window == win) {
170 break;
171 }
172 }
173 }
174
175 event_loop( dpy, win );
176
177 glXDestroyContext( dpy, ctx );
178 XDestroyWindow( dpy, win );
179
180 XCloseDisplay( dpy );
181
182 return 0;
183 }
184
185
186 int main()
187 {
188 int i;
189 for (i = 0 ; i < NR_DISPLAYS ; i++) {
190 if (foo() != 0)
191 break;
192 }
193
194 return 0;
195 }