#!/usr/bin/env sim writeln "GLX Demo" $draw_quad: glClearColor 0 0 0 1 glClear GL'COLOR_BUFFER_BIT | GL'DEPTH_BUFFER_BIT glMatrixMode GL'PROJECTION glLoadIdentity glOrtho -1 1 -1 1 1 20 glMatrixMode GL'MODELVIEW glLoadIdentity gluLookAt 0 0 10 0 0 0 0 1 0 quads: glColor3f 1 0 0 glVertex3f -0.75 -0.75 0 glColor3f 0 1 0 glVertex3f 0.75 -0.75 0 glColor3f 0 0 1 glVertex3f 0.75 0.75 0 glColor3f 1 1 0 glVertex3f -0.75 0.75 0 !X11_display XOpenDisplay(NULL) if X11_display->address() == 0: raise "Connection to X-Server failed!" !X11_screen XDefaultScreen() $root XDefaultRootWindow() $attributes int_array(GLX'RGBA GLX'DEPTH_SIZE 24 GLX'DOUBLEBUFFER X'None) $$vi glXChooseVisual(X11_screen attributes) if vi->address() == 0: raise "Connection to X-Server failed!" : write " visual &(vi'visualid) selected $colormap root->create_colormap(vi'visual X'AllocNone) $$set_window_attributes allocate_memory('XSetWindowAttributes) !set_window_attributes'colormap colormap !set_window_attributes'event_mask X'ExposureMask | X'KeyPressMask $win root->create 0 0 600 600 0 vi'depth X'InputOutput vi'visual X'CWColormap|X'CWEventMask set_window_attributes win->store_name "GLX Demo" win->map $glx_context glXCreateContext(vi NULL GL'TRUE) glXMakeCurrent win glx_context glEnable GL'DEPTH_TEST $$event allocate_memory('XEvent) forever: event->next case event'type X'Expose: if event'xexpose'count == 0: $window_attributes allocate_memory('XWindowAttributes) win->get_attributes window_attributes glViewport 0 0 window_attributes'width window_attributes'height draw_quad glXSwapBuffers win X'KeyPress: glXMakeCurrent X'None NULL glXDestroyContext glx_context win->destroy XCloseDisplay terminate