#include <GL/gl.h>
#include <GL/glx.h>
-#include "util.h"
+#include "util-x11.h"
-static void
-set_2d_projection (int width, int height)
-{
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
- glOrtho (0, width, height, 0, 0, 1);
- glMatrixMode (GL_MODELVIEW);
-}
-
-static void
-paint_rgb_using_clear (double r, double g, double b)
-{
- glClearColor(r, g, b, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
-}
-
-static void
-draw (Display *dpy, Window window, int width, int height)
-{
- int i;
- int visual_attr[] = {
- GLX_RGBA,
- GLX_RED_SIZE, 8,
- GLX_GREEN_SIZE, 8,
- GLX_BLUE_SIZE, 8,
- GLX_ALPHA_SIZE, 8,
- GLX_DOUBLEBUFFER,
- GLX_DEPTH_SIZE, 24,
- GLX_STENCIL_SIZE, 8,
- GLX_X_VISUAL_TYPE, GLX_DIRECT_COLOR,
- None
- };
-
- /* Window and context setup. */
- XVisualInfo *visual_info = glXChooseVisual(dpy, 0, visual_attr);
- GLXContext ctx = glXCreateContext(dpy, visual_info, NULL, True);
- glXMakeCurrent(dpy, window, ctx);
-
- glViewport(0, 0, width, height);
-
- set_2d_projection (width, height);
-
-/* Simply count through some colors, frame by frame. */
-#define RGB(frame) (((frame+1)/4) % 2), (((frame+1)/2) % 2), ((frame+1) % 2)
-
- int frame = 0;
- for (i = 0; i < 2; i++) {
- /* Frame: Draw a solid (magenta) frame */
- paint_rgb_using_clear (RGB(frame));
- glXSwapBuffers (dpy, window);
- frame++;
-
- /* Frame: Draw a solid (yellow) frame */
- paint_rgb_using_clear (RGB(frame));
- glXSwapBuffers (dpy, window);
- frame++;
-
- /* Frame: Draw a solid (cyan) frame */
- paint_rgb_using_clear (RGB(frame));
- glXSwapBuffers (dpy, window);
- frame++;
- }
-
- /* Cleanup */
- glXDestroyContext (dpy, ctx);
-}
-
-static void
-handle_events(Display *dpy, Window window)
-{
- XEvent xev;
- int width = 0;
- int height = 0;
-
- XNextEvent (dpy, &xev);
-
- while (1) {
- XNextEvent (dpy, &xev);
- switch (xev.type) {
- case ConfigureNotify:
- width = xev.xconfigure.width;
- height = xev.xconfigure.height;
- break;
- case Expose:
- if (xev.xexpose.count == 0) {
- draw (dpy, window, width, height);
- return;
- }
- break;
- }
- }
-}
+#define COMMON_GL_PREFIX
+#include "common.c"
int
main (void)
{
Display *dpy;
Window window;
+ GLXContext ctx;
+ XVisualInfo *visual_info;
+
+ dpy = util_x11_init_display ();
+
+ common_create_glx_context (dpy, &ctx, &visual_info);
+
+ window = util_x11_init_window (dpy, visual_info);
+
+ common_make_current (dpy, ctx, window);
- util_init_display_window (&dpy, &window);
+ common_handle_events (dpy, dpy, window);
- handle_events (dpy, window);
+ util_x11_fini_window (dpy, window);
- util_fini_display_window (dpy, window);
+ util_x11_fini_display (dpy);
return 0;
}