change glx-dbl-bare to be double-buffered
This commit is contained in:
parent
76484f84e4
commit
49f5b2654f
@ -2,8 +2,14 @@
|
|||||||
#include <GL/glx.h>
|
#include <GL/glx.h>
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
static int attributeList[] = { GLX_RGBA, None };
|
static int attributeList[] = {
|
||||||
|
GLX_RGBA,
|
||||||
|
GLX_DOUBLEBUFFER,
|
||||||
|
GLX_DEPTH_SIZE, 24,
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
static Bool WaitForNotify(Display *d, XEvent *e, char *arg)
|
static Bool WaitForNotify(Display *d, XEvent *e, char *arg)
|
||||||
{
|
{
|
||||||
@ -21,11 +27,29 @@ int main(int argc, char **argv)
|
|||||||
XEvent event;
|
XEvent event;
|
||||||
|
|
||||||
/* get a connection */
|
/* get a connection */
|
||||||
dpy = XOpenDisplay(0);
|
dpy = XOpenDisplay(NULL);
|
||||||
|
if (dpy == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "XOpenDisplay() returned NULL\n");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
/* get an appropriate visual */
|
/* get an appropriate visual */
|
||||||
vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList);
|
vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList);
|
||||||
|
if (vi == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "glXChooseVisual() returned NULL\n");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
/* create a GLX context */
|
/* create a GLX context */
|
||||||
cx = glXCreateContext(dpy, vi, 0, GL_FALSE);
|
cx = glXCreateContext(dpy, vi, NULL, GL_TRUE);
|
||||||
|
if (cx == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "glXCreateContext() returned NULL\n");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
/* create a color map */
|
/* create a color map */
|
||||||
cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen),
|
cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen),
|
||||||
vi->visual, AllocNone);
|
vi->visual, AllocNone);
|
||||||
@ -36,15 +60,28 @@ int main(int argc, char **argv)
|
|||||||
swa.event_mask = StructureNotifyMask;
|
swa.event_mask = StructureNotifyMask;
|
||||||
win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 100, 100,
|
win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 100, 100,
|
||||||
0, vi->depth, InputOutput, vi->visual,
|
0, vi->depth, InputOutput, vi->visual,
|
||||||
CWBorderPixel|CWColormap|CWEventMask, &swa);
|
CWBorderPixel | CWColormap | CWEventMask, &swa);
|
||||||
XMapWindow(dpy, win);
|
XMapWindow(dpy, win);
|
||||||
XIfEvent(dpy, &event, WaitForNotify, (char*)win);
|
XIfEvent(dpy, &event, WaitForNotify, (char*)win);
|
||||||
/* connect the context to the window */
|
/* connect the context to the window */
|
||||||
glXMakeCurrent(dpy, win, cx);
|
if (glXMakeCurrent(dpy, win, cx) == GL_FALSE)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "glXMakeCurrent() returned false\n");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* setup */
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
/* clear the buffer */
|
/* clear the buffer */
|
||||||
glClearColor(1,1,0,1);
|
glClearColor(1, 1, 0, 1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glFlush();
|
glXSwapBuffers(dpy, win);
|
||||||
|
|
||||||
/* wait a while */
|
/* wait a while */
|
||||||
sleep(10);
|
sleep(5);
|
||||||
|
|
||||||
|
/* teardown */
|
||||||
|
XFree(vi);
|
||||||
|
XCloseDisplay(dpy);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user