88 lines
2.0 KiB
C
88 lines
2.0 KiB
C
|
|
#include <GL/glx.h>
|
|
#include <GL/gl.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
|
|
static int attributeList[] = {
|
|
GLX_RGBA,
|
|
GLX_DOUBLEBUFFER,
|
|
GLX_DEPTH_SIZE, 24,
|
|
None
|
|
};
|
|
|
|
static Bool WaitForNotify(Display *d, XEvent *e, char *arg)
|
|
{
|
|
return (e->type == MapNotify) && (e->xmap.window == (Window)arg);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
Display *dpy;
|
|
XVisualInfo *vi;
|
|
Colormap cmap;
|
|
XSetWindowAttributes swa;
|
|
Window win;
|
|
GLXContext cx;
|
|
XEvent event;
|
|
|
|
/* get a connection */
|
|
dpy = XOpenDisplay(NULL);
|
|
if (dpy == NULL)
|
|
{
|
|
fprintf(stderr, "XOpenDisplay() returned NULL\n");
|
|
return 2;
|
|
}
|
|
|
|
/* get an appropriate visual */
|
|
vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList);
|
|
if (vi == NULL)
|
|
{
|
|
fprintf(stderr, "glXChooseVisual() returned NULL\n");
|
|
return 2;
|
|
}
|
|
|
|
/* create a GLX context */
|
|
cx = glXCreateContext(dpy, vi, NULL, GL_TRUE);
|
|
if (cx == NULL)
|
|
{
|
|
fprintf(stderr, "glXCreateContext() returned NULL\n");
|
|
return 2;
|
|
}
|
|
|
|
/* create a color map */
|
|
cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen),
|
|
vi->visual, AllocNone);
|
|
|
|
/* create a window */
|
|
swa.colormap = cmap;
|
|
swa.border_pixel = 0;
|
|
swa.event_mask = StructureNotifyMask;
|
|
win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 100, 100,
|
|
0, vi->depth, InputOutput, vi->visual,
|
|
CWBorderPixel | CWColormap | CWEventMask, &swa);
|
|
XMapWindow(dpy, win);
|
|
XIfEvent(dpy, &event, WaitForNotify, (char*)win);
|
|
/* connect the context to the window */
|
|
if (glXMakeCurrent(dpy, win, cx) == GL_FALSE)
|
|
{
|
|
fprintf(stderr, "glXMakeCurrent() returned false\n");
|
|
return 2;
|
|
}
|
|
|
|
/* setup */
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
/* clear the buffer */
|
|
glClearColor(1, 1, 0, 1);
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
glXSwapBuffers(dpy, win);
|
|
|
|
/* wait a while */
|
|
sleep(5);
|
|
|
|
/* teardown */
|
|
XFree(vi);
|
|
XCloseDisplay(dpy);
|
|
}
|