[Xquartz-changes] [323] AppleSGLX/trunk/tests
source_changes at macosforge.org
source_changes at macosforge.org
Thu Mar 26 00:18:13 PDT 2009
Revision: 323
http://trac.macosforge.org/projects/xquartz/changeset/323
Author: gstaplin at apple.com
Date: 2009-03-26 00:18:13 -0700 (Thu, 26 Mar 2009)
Log Message:
-----------
Add a test that demonstrates the black surface problem some users are experiencing.
Modified Paths:
--------------
AppleSGLX/trunk/tests/tests.mk
AppleSGLX/trunk/tests/triangle_glx/triangle_glx.mk
Added Paths:
-----------
AppleSGLX/trunk/tests/triangle_glx/triangle_glx_destroy_relation.c
Modified: AppleSGLX/trunk/tests/tests.mk
===================================================================
--- AppleSGLX/trunk/tests/tests.mk 2009-03-21 00:36:03 UTC (rev 322)
+++ AppleSGLX/trunk/tests/tests.mk 2009-03-26 07:18:13 UTC (rev 323)
@@ -34,5 +34,6 @@
$(TEST_BUILD_DIR)/glthreads \
$(TEST_BUILD_DIR)/triangle_glx_surface \
$(TEST_BUILD_DIR)/triangle_glx_surface-2 \
- $(TEST_BUILD_DIR)/triangle_glx_withdraw_remap
+ $(TEST_BUILD_DIR)/triangle_glx_withdraw_remap \
+ $(TEST_BUILD_DIR)/triangle_glx_destroy_relation
Modified: AppleSGLX/trunk/tests/triangle_glx/triangle_glx.mk
===================================================================
--- AppleSGLX/trunk/tests/triangle_glx/triangle_glx.mk 2009-03-21 00:36:03 UTC (rev 322)
+++ AppleSGLX/trunk/tests/triangle_glx/triangle_glx.mk 2009-03-26 07:18:13 UTC (rev 323)
@@ -9,3 +9,6 @@
$(TEST_BUILD_DIR)/triangle_glx_withdraw_remap: tests/triangle_glx/triangle_glx_withdraw_remap.c $(LIBGL)
$(CC) tests/triangle_glx/triangle_glx_withdraw_remap.c -Iinclude -o $(TEST_BUILD_DIR)/triangle_glx_withdraw_remap $(LINK_TEST)
+
+$(TEST_BUILD_DIR)/triangle_glx_destroy_relation: tests/triangle_glx/triangle_glx_destroy_relation.c $(LIBGL)
+ $(CC) tests/triangle_glx/triangle_glx_destroy_relation.c -Iinclude -o $(TEST_BUILD_DIR)/triangle_glx_destroy_relation $(LINK_TEST)
Added: AppleSGLX/trunk/tests/triangle_glx/triangle_glx_destroy_relation.c
===================================================================
--- AppleSGLX/trunk/tests/triangle_glx/triangle_glx_destroy_relation.c (rev 0)
+++ AppleSGLX/trunk/tests/triangle_glx/triangle_glx_destroy_relation.c 2009-03-26 07:18:13 UTC (rev 323)
@@ -0,0 +1,130 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include <GL/glx.h>
+
+Window root, win, win2;
+GLXContext ctx;
+
+void draw(Display *dpy, Window w) {
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glLoadIdentity();
+ glColor3f(0.5f, 0.5f, 1.0f);
+ glBegin(GL_TRIANGLES);
+ glVertex3f( 0.0f, 1.0f, 0.0f);
+ glVertex3f(-1.0f,-1.0f, 0.0f);
+ glVertex3f( 1.0f,-1.0f, 0.0f);
+ glEnd();
+ glXSwapBuffers(dpy, w);
+}
+
+void resize(Display *dpy, Window w, int width, int height) {
+ glViewport(0, 0, width, height);
+ draw(dpy, w);
+}
+
+void event_loop(Display *dpy) {
+ XEvent event;
+
+ while(1) {
+ XNextEvent(dpy, &event);
+
+ switch(event.type) {
+ case Expose:
+ glXMakeCurrent(dpy, event.xexpose.window, ctx);
+ draw(dpy, event.xexpose.window);
+ break;
+
+ case KeyPress: {
+ XWindowAttributes wattr;
+
+ glXMakeCurrent(dpy, win2, ctx);
+
+ XGetWindowAttributes(dpy, win2, &wattr);
+
+ resize(dpy, win2, wattr.width, wattr.height);
+ draw(dpy, win2);
+ XFlush(dpy);
+ }
+ break;
+
+ case ConfigureNotify:
+ glXMakeCurrent(dpy, event.xconfigure.window, ctx);
+ resize(dpy, event.xconfigure.window, event.xconfigure.width,
+ event.xconfigure.height);
+ break;
+ }
+ }
+}
+
+int main() {
+ Display *dpy;
+ int attrib[] = { GLX_RGBA,
+ GLX_RED_SIZE, 8,
+ GLX_GREEN_SIZE, 8,
+ GLX_BLUE_SIZE, 8,
+ GLX_DEPTH_SIZE, 24,
+ GLX_DOUBLEBUFFER,
+ None };
+ int eventbase, errorbase;
+ int screen;
+ XVisualInfo *visinfo;
+ XSetWindowAttributes attr;
+
+
+ dpy = XOpenDisplay(NULL);
+
+ if(NULL == dpy) {
+ fprintf(stderr, "error: unable to open display!\n");
+ return EXIT_FAILURE;
+ }
+
+ if(!glXQueryExtension(dpy, &eventbase, &errorbase)) {
+ fprintf(stderr, "GLX is not available!\n");
+ return EXIT_FAILURE;
+ }
+
+ screen = DefaultScreen(dpy);
+ root = RootWindow(dpy, screen);
+
+ visinfo = glXChooseVisual(dpy, screen, attrib);
+
+ if(!visinfo) {
+ fprintf(stderr, "error: couldn't get an RGBA, double-buffered visual!\n");
+ return EXIT_FAILURE;
+ }
+
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
+ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+
+ win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0,
+ /*width*/ 400, /*height*/ 400,
+ 0, visinfo->depth, InputOutput,
+ visinfo->visual,
+ CWBackPixel | CWBorderPixel | CWColormap | CWEventMask,
+ &attr);
+
+ win2 = XCreateWindow(dpy, win, 0, 0,
+ 100, 100,
+ 0, visinfo->depth, InputOutput,
+ visinfo->visual,
+ CWBackPixel | CWBorderPixel | CWColormap | CWEventMask,
+ &attr);
+
+ ctx = glXCreateContext(dpy, visinfo, NULL, True);
+ if(!ctx) {
+ fprintf(stderr, "error: glXCreateContext failed!\n");
+ return EXIT_FAILURE;
+ }
+
+ XMapWindow(dpy, win);
+ XMapWindow(dpy, win2);
+
+ glXMakeCurrent(dpy, win, ctx);
+
+ event_loop(dpy);
+
+ return EXIT_SUCCESS;
+}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/xquartz-changes/attachments/20090326/aabf7658/attachment.html>
More information about the Xquartz-changes
mailing list