2 #define USE_MINIGLX 1 /* 1 = use Mini GLX, 0 = use Xlib/GLX */
10 #include <GL/miniglx.h>
16 static void _subset_Rectf( GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
28 * Create a simple double-buffered RGBA window.
31 MakeWindow(Display
* dpy
, unsigned int width
, unsigned int height
)
33 int visAttributes
[] = {
41 XSetWindowAttributes attr
;
42 unsigned long attrMask
;
48 root
= RootWindow(dpy
, 0);
50 /* Choose GLX visual / pixel format */
51 visinfo
= glXChooseVisual(dpy
, 0, visAttributes
);
53 printf("Error: couldn't get an RGB, Double-buffered visual\n");
57 /* Create the window */
58 attr
.background_pixel
= 0;
59 attr
.border_pixel
= 0;
60 attr
.colormap
= XCreateColormap(dpy
, root
, visinfo
->visual
, AllocNone
);
61 attrMask
= CWBackPixel
| CWBorderPixel
| CWColormap
;
62 win
= XCreateWindow(dpy
, root
, 0, 0, width
, height
,
63 0, visinfo
->depth
, InputOutput
,
64 visinfo
->visual
, attrMask
, &attr
);
66 printf("Error: XCreateWindow failed\n");
70 /* Display the window */
73 /* Create GLX rendering context */
74 ctx
= glXCreateContext(dpy
, visinfo
, NULL
, True
);
76 printf("Error: glXCreateContext failed\n");
80 /* Bind the rendering context and window */
81 glXMakeCurrent(dpy
, win
, ctx
);
83 glViewport(0, 0, width
, height
);
90 * Draw a few frames of a rotating square.
93 DrawFrames(Display
* dpy
, Window win
)
96 glShadeModel(GL_FLAT
);
97 glClearColor(0.5, 0.5, 0.5, 1.0);
98 for (angle
= 0; angle
< 360; angle
+= 10) {
99 glClear(GL_COLOR_BUFFER_BIT
);
100 glColor3f(1.0, 1.0, 0.0);
102 glRotatef(angle
, 0, 0, 1);
103 _subset_Rectf(-0.8, -0.8, 0.8, 0.8);
105 glXSwapBuffers(dpy
, win
);
112 main(int argc
, char *argv
[])
117 dpy
= XOpenDisplay(NULL
);
119 printf("Error: XOpenDisplay failed\n");
123 win
= MakeWindow(dpy
, 300, 300);
125 DrawFrames(dpy
, win
);