home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <gl/gl.h>
- #include <gl/glws.h>
-
- GLXconfig conf[] = {
- {GLX_NORMAL, GLX_DOUBLE, False},
- {GLX_NORMAL, GLX_RGB, True},
- {0, 0, 0}
- };
-
- main(argc, argv)
-
- int argc;
- char *argv[];
-
- {
-
- float ptv[2];
- int i;
- int screen;
- int flags;
-
- XVisualInfo *GetGLXVisual();
- void SetGLXWindow();
- unsigned long GetGLXConfigValue();
- Display *dpy;
- Window gr_window;
- XVisualInfo *gv;
- XSetWindowAttributes attributes;
- GLXconfig *result_conf;
- XEvent event;
-
- if (!(dpy = XOpenDisplay("")) ) {
- perror("Cannot open display\n");
- exit(-1);
- }
-
- screen = DefaultScreen(dpy);
- XSynchronize(dpy,True);
-
- if ((result_conf = GLXgetconfig(dpy, screen, conf)) == 0) {
- printf("GLXgetconfig failed \n");
- exit(-1);
- }
-
- /* get the visual for the normal planes */
- gv = GetGLXVisual (dpy, GLX_NORMAL, result_conf);
- printf("Normal buffer id = 0x%x, depth = %d\n", gv->visualid, gv->depth);
-
- /* Set up an GLX window in the normal image planes. */
-
- attributes.border_pixel = 0;
- attributes.background_pixel = 0x0;
- attributes.bit_gravity = ForgetGravity;
- flags = CWBackPixel | CWBorderPixel | CWBitGravity;
- flags |= CWColormap;
- attributes.colormap = GetGLXConfigValue (GLX_NORMAL, GLX_COLORMAP,
- result_conf);
- printf("Normal buffer cmap = 0x%x\n", attributes.colormap);
-
-
- gr_window = XCreateWindow(dpy,
- RootWindow(dpy,screen),
- 100,
- 100,
- 256,
- 256,
- 4,
- gv->depth,
- InputOutput,
- gv->visual,
- flags,
- &attributes);
-
- /* Select input and map the windows. */
- XSelectInput (dpy, gr_window, ExposureMask | StructureNotifyMask |
- ResizeRedirectMask | PointerMotionMask);
-
- XStoreName(dpy,gr_window, "Rubber Banding");
-
- XMapRaised(dpy, gr_window);
- XWindowEvent (dpy, gr_window, ExposureMask, &event);
- while (XCheckWindowEvent(dpy, gr_window, ExposureMask | StructureNotifyMask,
- &event));
-
-
- SetGLXWindow (GLX_NORMAL, gr_window, result_conf);
-
- /* Link the configuration. */
-
- if (GLXlink(dpy, result_conf) < 0) {
- printf("GLXlink failed\n");
- exit(-1);
- }
-
- /* Set up viewing and color information in the normal
- * buffer window.
- */
-
- if (GLXwinset(dpy, gr_window) < 0) {
- printf("GLXwinset failed for graphics init\n");
- exit(-1);
- }
- reshapeviewport();
- ortho2(0,1,0,1);
- clear();
-
- /* Here is the X11 event loop. Each time you get an event,
- * the rectangle in the pop-up planes flips to the other
- * half of the window.
- */
-
- i = 0;
- for (;;) {
-
- XNextEvent(dpy, &event);
-
- /* Draw the normal buffer window. */
-
- if (GLXwinset(dpy, gr_window) < 0) {
- printf("GLXwinset failed for graphics event\n");
- exit(-1);
- }
-
- if (event.type == MotionNotify) {
- RGBcolor(0,0,0);
- clear();
- RGBcolor(0,128,128);
- bgnline();
- ptv[0] = 0.0;
- ptv[1] = 1.0;
- v2f(ptv);
- ptv[0] = event.xmotion.x/256.0;
- ptv[1] = 1.0 - (event.xmotion.y/256.0);
- v2f(ptv);
- endline();
- }
- }
- }
-
-
-
-
-
-
-
-
-
- unsigned long GetGLXConfigValue (buffer, mode, sconf)
- int buffer;
- int mode;
- GLXconfig *sconf;
-
- {
- int i;
-
- for (i = 0; sconf[i].buffer; i++) {
- if (sconf[i].buffer == buffer &&
- sconf[i].mode == mode ) {
- return sconf[i].arg;
- }
- }
-
- return 0;
- }
-
- XVisualInfo * GetGLXVisual (dpy, buffer, sconf)
- Display *dpy;
- int buffer;
- GLXconfig *sconf;
-
- {
- XVisualInfo template;
- int n;
-
- template.visualid = GetGLXConfigValue (buffer, GLX_VISUAL, sconf);
-
- return XGetVisualInfo(dpy, VisualIDMask, &template, &n);
-
- }
-
- void SetGLXWindow (buffer, w, sconf)
- int buffer;
- Window w;
- GLXconfig *sconf;
-
- {
- int i;
-
- for (i = 0; sconf[i].buffer; i++) {
- if ( (sconf[i].buffer == buffer) &&
- (sconf[i].mode == GLX_WINDOW)) {
- sconf[i].arg = w;
- }
- }
-
- }
-