ygl-4.2e/0000755000175000017500000000000010621135163011641 5ustar prabhuprabhuygl-4.2e/misc.c0000444000175000017500000006402510620057071012745 0ustar prabhuprabhu/* * Ygl: Run GL programs with standard X11 and/or OpenGL routines. * (C) Fred Hucht 1993-2007 * EMail: fredthp.Uni-Duisburg.de */ static const char vcid[] = "$Id: misc.c,v 4.14 2007-05-08 13:25:45+02 fred Exp $"; #ifdef OGL # define GLX_GLXEXT_PROTOTYPES /* we want prototypes for glX*VideoSyncSGI() */ #endif #include "header.h" #ifdef _AIX /* # include fails under AIX 3.2 */ #endif #ifdef X11 # ifdef DOUBLEBUF # include # endif # ifdef MULTIBUF # ifndef NO_MULTIBUF_H /* we have both multibuf.h and libXext.a */ # include # else /* we don't have the include file, but the library (HP/UX 8.0) */ # define MultibufferUpdateActionUndefined 0 # define MultibufferUpdateHintFrequent 0 # endif # endif #endif /* X11 */ #define YglClipMask 1L #define YglDashMask 2L #define YglGCMask 4L typedef struct YglGCValues_ { Ulong gcmask; /* The GC mask */ XGCValues values; /* The GC values */ XRectangle rect; /* The clipping rectangle */ char *dashes; /* The dash list */ int ndashes; /* Number of elements in dashes */ } YglGCValues; static void change_gc(Ulong, YglGCValues *); #ifdef X11 static void set_scales(YglWindow *w); #endif static int linestyle_id2idx(Int32 id); #ifdef MULTIBUF static int mbuf_errorhandler(Display *dpy, XErrorEvent *error); #endif static void change_gc(Ulong mask, YglGCValues *yv) { YglWindow *w = W; if(w->rgb || Ygl.GC) { /* RGB windows have only one GC */ if(mask & YglClipMask) XSetClipRectangles(D, w->gc, 0, 0, &yv->rect, 1, Unsorted); if(mask & YglDashMask) XSetDashes (D, w->gc, 0, yv->dashes, yv->ndashes); if(mask & YglGCMask) XChangeGC (D, w->gc, yv->gcmask, &yv->values); } else { int i; for(i = 0; i < CMapSize; i++) { if(mask & YglClipMask) XSetClipRectangles(D, w->gclist[i], 0, 0, &yv->rect, 1, Unsorted); if(mask & YglDashMask) XSetDashes (D, w->gclist[i], 0, yv->dashes, yv->ndashes); if(mask & YglGCMask) XChangeGC (D, w->gclist[i], yv->gcmask, &yv->values); } } if(mask & YglClipMask) XSetClipRectangles(D, w->chargc, 0, 0, &yv->rect, 1, Unsorted); if(mask & YglGCMask) XChangeGC (D, w->chargc, yv->gcmask, &yv->values); /* Added 960130 */ } enum buffers { NoBuf, DBuf, MBuf, OBuf }; static int HasBuf = NoBuf; #ifdef MULTIBUF static int mbuf_errorhandler(Display *dpy, XErrorEvent *error) { char errortext[1024]; XGetErrorText(dpy, error->error_code, errortext, 1024); Yprintf("doublebuffer", "X Error: %s in XmbufCreateBuffers, strange...\n", errortext); return False; } #endif void doublebuffer(void) { const char * MyName = "doublebuffer"; YglWindow *w = W; int junk[2]; I(MyName, ""); #ifdef OGL if(Ygl.UseOGL) { HasBuf = OBuf; /*if(W == NULL) { lmodtest prefsize(1280, 1024); winopen("YglFullscreen"); w = W; }*/ glDrawBuffer(GL_BACK); w->dbuf = True; return; } #endif /* OGL */ #ifdef DOUBLEBUF if(HasBuf == NoBuf) HasBuf = XdbeQueryExtension(D, junk, junk+1) ? DBuf : NoBuf; if(HasBuf == NoBuf) { Yprintf(MyName, "extension 'DOUBLE-BUFFER' not found in X-Server.\n"); } else if(HasBuf == DBuf && !w->dbuf) { /* If not inited */ w->dbufs[0] = w->main; w->dbufs[1] = XdbeAllocateBackBufferName(D, w->main, XdbeUndefined); w->dbuf = True; w->draw = w->dbufs[1]; } #endif /* DOUBLEBUF */ #ifdef MULTIBUF if(HasBuf == NoBuf) HasBuf = XmbufQueryExtension(D, junk, junk+1) ? MBuf : NoBuf; if(HasBuf == NoBuf) { Yprintf(MyName, "extension 'Multi-Buffering' not found in X-Server.\n"); } else if(HasBuf == MBuf && !w->dbuf) { /* If not inited */ int (*old_handler)(Display*, XErrorEvent*); int r; old_handler = XSetErrorHandler(mbuf_errorhandler); r = XmbufCreateBuffers(D, IF_RGBWIN(w->win, w->main), 2, MultibufferUpdateActionUndefined, MultibufferUpdateHintFrequent, w->dbufs); XSync(D, False); XSetErrorHandler(old_handler); if(r != 2) { Yprintf(MyName, "unable to create 2 buffers.\n"); HasBuf = NoBuf; } else { w->dbuf = True; /* Window is in dbuf mode */ w->dispbuf = 0; /* Displayed buffer */ w->draw = w->dbufs[1]; /* draw to backbuffer */ } } #endif /* MULTIBUF */ if(HasBuf == NoBuf) { Yprintf(MyName, "Warning: cannot do doublebuffering.\n"); } #if !(defined(DOUBLEBUF) || defined(MULTIBUF)) Yprintf(MyName, "Warning: Ygl is not compiled for doublebuffering.\n"); #endif } void singlebuffer(void) { const char * MyName = "singlebuffer"; YglWindow *w = W; I(MyName, ""); if(w->dbuf) switch(HasBuf) { #ifdef OGL case OBuf: glDrawBuffer(GL_FRONT); break; #endif #ifdef DOUBLEBUF case DBuf: XdbeDeallocateBackBufferName(D, w->dbufs[1]); W->draw = IF_RGBWIN(W->win, W->main); break; #endif #ifdef MULTIBUF case MBuf: XmbufDestroyBuffers(D, IF_RGBWIN(w->win, w->main)); W->draw = IF_RGBWIN(W->win, W->main); break; #endif case NoBuf: /* Do nothing */ break; } W->dbuf = False; /* Window is not in dbuf mode */ } void swapbuffers(void) { const char * MyName = "swapbuffers"; YglWindow *w = W; I(MyName, ""); if(HasBuf != NoBuf && !w->dbuf) { Yprintf(MyName, "window %d is not in doublebuffer mode.\n", winget()); return; } switch(HasBuf) { #ifdef OGL case OBuf: glXSwapBuffers(D, w->main); break; #endif #ifdef DOUBLEBUF case DBuf: { XdbeSwapInfo xdbesi; xdbesi.swap_window = w->main; xdbesi.swap_action = XdbeUndefined; XdbeSwapBuffers(D, &xdbesi, 1); XFlush(D); /* Need it? */ break; } #endif #ifdef MULTIBUF case MBuf: w->draw = w->dbufs[w->dispbuf]; w->dispbuf = 1 - w->dispbuf; XmbufDisplayBuffers(D, 1, w->dbufs + w->dispbuf, 0, 0); XFlush(D); /* XmbufDisplayBuffers() seems not to flush */ break; #endif case NoBuf: /* Do nothing */ break; } } void frontbuffer(Int32 bool) { const char * MyName = "frontbuffer"; YglWindow *w = W; I(MyName, "%d", bool); if(HasBuf != NoBuf && !w->dbuf) { /* Ignore if not in doublebuffer mode */ /* Yprintf(MyName, "window %d is not in doublebuffer mode.\n", winget()); */ return; } switch(HasBuf) { #ifdef OGL case OBuf: glDrawBuffer(bool ? GL_FRONT : GL_BACK); break; #endif #ifdef DOUBLEBUF case DBuf: w->draw = bool ? w->dbufs[0] : w->dbufs[1]; break; #endif #ifdef MULTIBUF case MBuf: w->draw = bool ? w->dbufs[w->dispbuf] : w->dbufs[1 - w->dispbuf]; break; #endif case NoBuf: /* Do nothing */ break; } } void backbuffer(Int32 bool) { const char * MyName = "backbuffer"; I(MyName, "%d", bool); frontbuffer(!bool); } void gflush(void) { const char * MyName = "gflush"; I(MyName, ""); IFOGL(glFlush(), XFlush(D)); } #ifdef OGL static void gsync_ogl(const char *caller) { unsigned int retraceCount; static int hasExtension = -1; if (hasExtension == -1) { const char * extensionsString, * pos; const char * extension = "GLX_SGI_video_sync"; extensionsString = glXQueryExtensionsString(D, YglScreen); pos = strstr(extensionsString, extension); hasExtension = pos != NULL && (pos == extensionsString || pos[-1] == ' ') && (pos[strlen(extension)] == ' ' || pos[strlen(extension)] == '\0'); if (!hasExtension) { Yprintf(caller, "extension %s not present\n", extension); } } if (hasExtension) { #ifdef GSvs glXGetVideoSyncSGI(&retraceCount); glXWaitVideoSyncSGI(2, (retraceCount+1)%2, &retraceCount); #else Yprintf(caller, "glX*VideoSyncSGI() not enabled in Ygl\n"); #endif } } #endif void gsync(void) { const char * MyName = "gsync"; I(MyName, ""); IFOGL(gsync_ogl(MyName),/**/); } Display *getXdpy(void) { const char * MyName = "getXdpy"; I(MyName, ""); return D; } Window getXwid(void) { /* Return the main window. Usable for move/resize, map/unmap, * event stuff */ const char * MyName = "getXwid"; I(MyName, ""); return W->main; } #ifdef X11 Window getXdid(void) { /* Return the drawable. Usable for drawing. */ const char * MyName = "getXdid"; I(MyName, ""); return W->draw; } GC getXgc(void) { const char * MyName = "getXgc"; I(MyName, ""); return W->gc; } #endif void wintitle(Char8 *Title) { const char * MyName = "wintitle"; I(MyName, "'%s'", Title); XStoreName(D, W->main, Title); } void winset(Int32 wid) { const char * MyName = "winset"; I(MyName, "%d", wid); if(wid > 0 && wid <= Ygl.NextWindow && Ygl.Windows[wid].main != 0) { W = &Ygl.Windows[Ygl.ActiveWindow = wid]; IFOGL(glXMakeCurrent(D, W->main, W->cx), /**/); } else { Yprintf(MyName, "invalid window id: %d\n", wid); } } Int32 winget(void) { const char * MyName = "winget"; I(MyName, ""); return Ygl.ActiveWindow; } Int32 getplanes(void) { const char * MyName = "getplanes"; I(MyName, ""); return W->rgb ? Ygl.RV.depth : Ygl.EmulateCmap ? EMULATE_CMAP_DEPTH : Ygl.CV.depth; } Int32 getvaluator(Device dev) { Window junkwin; int rx, ry, cx, cy; Uint mask; Int32 r = -1; const char * MyName = "getvaluator"; I(MyName, "%d", dev); XQueryPointer(D, W->main, &junkwin, &junkwin, &rx, &ry, &cx, &cy, &mask); #ifdef DEBUG fprintf(stderr, "getvaluator: root = (%d,%d), child = (%d,%d) mask=0x%x\n", rx, ry, cx, cy, mask); #endif switch(dev) { case MOUSEX: r = rx; break; case MOUSEY: r = YglScreenHeight - ry - 1; break; default: Yprintf(MyName, "unknown device: %d.\n", dev); break; } return r; } Int32 getbutton(Device dev) { Window junkwin; int junk; Uint mask, bmask; Int32 r = -1; int i, j, code; char keys[32]; const char * MyName = "getbutton"; I(MyName, "%d", dev); switch(dev) { case 0: break; case LEFTMOUSE: bmask = Button1Mask; goto query; case MIDDLEMOUSE: bmask = Button2Mask; goto query; case RIGHTMOUSE: bmask = Button3Mask; goto query; query: XQueryPointer(D, W->main, &junkwin, &junkwin, &junk, &junk, &junk, &junk, &mask); #ifdef DEBUG fprintf(stderr, "getbutton: mask = 0x%x\n", mask); #endif r = 0 != (mask & bmask); break; default: XQueryKeymap(D, keys); for(i = code = 0; i < 32; i++) for(j = 1; j < 256; j <<= 1, code++) { if(dev == (Ygl.keymap[code] & (KEYMAP_BIT-1))) { /* dev found */ r = 0 != (keys[i] & j); #ifdef DEBUG fprintf(stderr, "getbutton: key %d %s, device = %d\n", code, r ? "pressed" : "released", Ygl.keymap[code] & (KEYMAP_BIT-1)); #endif } } break; } if(r == -1) { Yprintf(MyName, "unknown device: %d.\n", dev); } return r; } static void set_scales(YglWindow *w) { w->xf = (w->vw - 1) / (w->or - w->ol); w->yf = (w->vh - 1) / (w->ot - w->ob); w->xo = w->ol - w->vl / w->xf; w->yo = w->ob - w->vb / w->yf; } void ortho2(Coord left, Coord right, Coord bottom, Coord top) { const char * MyName = "ortho2"; YglWindow *w = W; I(MyName, "%g,%g,%g,%g", left, right, bottom, top); if(left == right || bottom == top) { Yprintf(MyName, "x-range or y-range is empty.\n"); return; } w->ol = left; w->or = right; w->ob = bottom; w->ot = top; set_scales(w); IFOGL(ortho(left, right, bottom, top, -1.0, 1.0), ;/**/); } #ifdef X11 static void viewport_x11(Screencoord left, Screencoord right, Screencoord bottom, Screencoord top, int clip) { YglWindow *w = W; if ( clip ) { YglGCValues yv; /* Clip window */ w->clipped = True; yv.rect.x = MIN(left, right); yv.rect.y = w->ym - 1 - MAX(bottom, top); yv.rect.width = w->vw; yv.rect.height = w->vh; #ifdef DEBUG fprintf(stderr, "viewport: Clipping window with rect=(%d,%d,%d,%d).\n", yv.rect.x, yv.rect.y, yv.rect.width, yv.rect.height); #endif change_gc(YglClipMask, &yv); } else if(w->clipped) { /* Unclip window */ YglGCValues yv; yv.values.clip_mask = None; yv.gcmask = GCClipMask; change_gc(YglGCMask, &yv); w->clipped = False; #ifdef DEBUG fprintf(stderr, "viewport: Unclipping window.\n"); #endif } } #endif void viewport(Screencoord left, Screencoord right, Screencoord bottom, Screencoord top) { const char * MyName = "viewport"; YglWindow *w = W; int clip; I(MyName, "%d,%d,%d,%d", left, right, bottom, top); w->vl = left; w->vr = right; w->vb = bottom; w->vt = top; w->vw = ABS(right - left) + 1; w->vh = ABS(top - bottom) + 1; set_scales(w); clip = (w->vl > 0 || w->vr < w->xm - 1 || w->vb > 0 || w->vt < w->ym - 1); IFOGL( glViewport(w->vl, w->vb, w->vw, w->vh); if (clip) { w->clipped = True; glScissor(w->vl, w->vb, w->vw, w->vh); glEnable(GL_SCISSOR_TEST); } else if (w->clipped) { w->clipped = False; glDisable(GL_SCISSOR_TEST); }, viewport_x11(w->vl, w->vr, w->vb, w->vt, clip) ); } void getviewport(Screencoord*left, Screencoord*right, Screencoord*bottom, Screencoord*top) { YglWindow *w = W; const char * MyName = "getviewport"; I(MyName, "..."); *left = w->vl; *right = w->vr; *bottom = w->vb; *top = w->vt; } void reshapeviewport(void) { YglWindow *w = W; Int32 x, y; const char * MyName = "reshapeviewport"; I(MyName, ""); getsize(&x, &y); w->xm = x; w->ym = y; viewport(0, x - 1, 0, y - 1); #ifdef RGBWIN if(w->rgb) { /* Ignore ExposeEvent */ XSelectInput(D, w->win, NoEventMask); XResizeWindow(D, w->win, x, y); XSelectInput(D, w->win, Ygl.EventMask & ExposureMask); } #endif } void pushviewport(void) { const char * MyName = "pushviewport"; I(MyName, ""); IFOGL(glPushAttrib(GL_VIEWPORT_BIT), NI(MyName)); } void popviewport(void) { const char * MyName = "popviewport"; I(MyName, ""); IFOGL(glPopAttrib(), NI(MyName)); } void winpop(void) { const char * MyName = "winpop"; I(MyName, ""); XRaiseWindow(D, W->main); } void winpush(void) { const char * MyName = "winpush"; I(MyName, ""); XLowerWindow(D, W->main); } Int32 windepth(Int32 wid) { Window root, parent, *children, mainwin; Uint nchildren; Int32 n = 0; const char * MyName = "windepth"; I(MyName, "%d", wid); if(wid <= 0 || wid > Ygl.NextWindow || (mainwin = Ygl.Windows[wid].main) == 0) { Yprintf(MyName, "invalid window id: %d\n", wid); return 0; } if(XQueryTree(D, Ygl.PWID, &root, &parent, &children, &nchildren)) { for(n = 0; n < nchildren && children[n] != mainwin; n++); n++; XFree((char*) children); } return n; } #ifdef X11 static void linewidth_x11(Int16 w) { YglGCValues yv; if(w == W->linewidth) return; /* already set */ yv.gcmask = GCLineWidth; W->linewidth = yv.values.line_width = w; change_gc(YglGCMask, &yv); } #endif void linewidth(Int16 w) { const char * MyName = "linewidth"; I(MyName, "%d", w); IFOGL(glLineWidth(w), linewidth_x11(w)); } Int32 getlwidth(void) { const char * MyName = "getlwidth"; int r; I(MyName, ""); IFOGL({GLint w;glGetIntegerv(GL_LINE_WIDTH, &w);r = w;},r = W->linewidth); return r; } typedef struct YglLineStyle_ { Int32 id; int ndashes; int repeat; char dashes[17]; } YglLineStyle; static YglLineStyle *linestyles = NULL; static int laststyle = -1; static int linestyle_id2idx(Int32 id) { int i = laststyle; while(i >= 0 && linestyles[i].id != id) i--; return i; } static void init_linestyles(void) { YglLineStyle *ls; laststyle = 0; linestyles = (YglLineStyle*)malloc(2 * sizeof(YglLineStyle)); /* setup element 0 */ ls = &linestyles[0]; ls->id = 0; ls->ndashes = 1; ls->repeat = 1; ls->dashes[0] = 1; } void deflinestyle(Int32 id, Linestyle style) { int i, bit, imax = 16; YglLineStyle *ls; const char * MyName = "deflinestyle"; I(MyName, "%d,%d", id, style); if(id == 0) { Yprintf(MyName, "cannot modify linestyle 0.\n"); return; } if(linestyles == NULL) { /* initialize */ init_linestyles(); i = ++laststyle; } else { i = linestyle_id2idx(id); if(i < 0) { /* not found */ i = ++laststyle; linestyles = (YglLineStyle*)realloc(linestyles, (laststyle + 1) * sizeof(YglLineStyle)); } } if(linestyles == NULL) { Yprintf(MyName, "can't allocate memory for linestyle %d'.\n", id); exit(-1); } ls = &linestyles[i]; ls->id = id; ls->ndashes = 0; ls->repeat = 1; ls->dashes[0] = 0; bit = 1; if((style & 0xf) == ((style >> 8) & 0xf)) { /* Periodic pattern 8 bit */ imax /= 2; if((style & 0x7) == ((style >> 4) & 0x7)) { /* 4 bit */ imax /= 2; if((style & 0x3) == ((style >> 2) & 0x3)) { /* 2 bit */ imax /= 2; } } } for(i = 0; i < imax; i++) { if(bit == ((style >> i) & 1)) { ls->dashes[ls->ndashes]++; /* Same value */ } else { ls->dashes[++ls->ndashes] = 1; bit ^= 1; } } ls->ndashes++; if(ls->dashes[0] == 0) { /* Pattern starts with 0s, rotate, it must start with 1s */ int tmp = ls->dashes[1]; ls->ndashes--; for(i = 0; i < ls->ndashes - 1; i++) ls->dashes[i] = ls->dashes[i+2]; ls->dashes[i] = tmp; } #ifdef DEBUG fprintf(stderr, "%s: id = %d, linestyle = 0x%x, dashes = {", MyName, id, style); for(i = 0; i < ls->ndashes; i++) fprintf(stderr, " %d", ls->dashes[i]); fprintf(stderr, "}\n"); #endif } void setlinestyle(Int32 id) { int idx; YglWindow *w = W; YglLineStyle *ls; const char * MyName = "setlinestyle"; I(MyName, "%d", id); if(linestyles == NULL) { /* initialize */ init_linestyles(); } idx = linestyle_id2idx(id); #ifdef DEBUG fprintf(stderr, "%s: id=%d, idx=%d\n", MyName, id, idx); #endif if(idx < 0) { Yprintf(MyName, "invalid linestyle %d.\n", id); return; } if(idx == w->linestyle) return; /* already set */ w->linestyle = idx; if(idx == 0) { YglGCValues yv; yv.gcmask = GCLineStyle; yv.values.line_style = LineSolid; change_gc(YglGCMask, &yv); } else { YglGCValues yv; ls = &linestyles[idx]; yv.gcmask = GCLineStyle; yv.values.line_style = LineOnOffDash; yv.dashes = ls->dashes; yv.ndashes = ls->ndashes; change_gc(YglDashMask | YglGCMask, &yv); } } Int32 getlstyle(void) { const char * MyName = "getlstyle"; I(MyName, ""); return linestyles[W->linestyle].id; } void lsrepeat(Int32 f) { int i; YglLineStyle *ls; YglGCValues yv; const char * MyName = "lsrepeat"; I(MyName, "%d", f); if(f < 1 || f > 255) { Yprintf(MyName, "argument %d must be >= 1 and <= 255.\n", f); return; } if(W->linestyle != 0) { ls = &linestyles[W->linestyle]; for(i = 0; i < ls->ndashes; i++) ls->dashes[i] = f * ls->dashes[i] / ls->repeat; ls->repeat = f; yv.dashes = ls->dashes; yv.ndashes = ls->ndashes; change_gc(YglDashMask, &yv); } #ifdef DEBUG fprintf(stderr, "%s: id = %d, factor = %d, dashes = {", MyName, ls->id, f); for(i = 0; i < ls->ndashes; i++) fprintf(stderr, " %d", ls->dashes[i]); fprintf(stderr, "}\n"); #endif } Int32 getlsrepeat(void) { const char * MyName = "getlsrepeat"; I(MyName, ""); return linestyles[W->linestyle].repeat; } Int32 getdisplaymode(void) { const char * MyName = "getdisplaymode"; I(MyName, ""); if(W->rgb) if(W->dbuf) return DMRGBDOUBLE; else return DMRGB; else if(W->dbuf) return DMDOUBLE; else return DMSINGLE; } void setbell(Char8 t) { XKeyboardControl xkbc; const char * MyName = "setbell"; I(MyName, "%d", t); switch(t) { case 0: xkbc.bell_duration = 0; break; case 1: xkbc.bell_duration = 100; break; case 2: xkbc.bell_duration = 400; break; default: Yprintf(MyName, "invalid value: %d.\n", t); return; break; } XChangeKeyboardControl(D, KBBellDuration, &xkbc); F; } void ringbell(void) { const char * MyName = "ringbell"; I(MyName, ""); XBell(D, 0); F; } Int32 getgdesc(Int32 what) { const char * MyName = "getgdesc"; Int32 r = -1; Display *dpy; if(D == NULL) { if ((dpy = XOpenDisplay(NULL)) == NULL) { Yprintf(MyName, "can\'t open display \"%s\".\n", XDisplayName(NULL)); exit(1); } } else { dpy = D; } switch(what) { case GD_XPMAX: r = DisplayWidth (dpy, DefaultScreen(dpy)); break; case GD_YPMAX: r = DisplayHeight(dpy, DefaultScreen(dpy)); break; default: Yprintf(MyName, "unsupported or unknown argument: %d.\n", what); break; } if(D == NULL) { XCloseDisplay(dpy); } return r; } void foreground(void) { /* Do nothing */ Yprintf("foreground", "ignored.\n"); } #ifdef X11 static void logicop_x11(Int32 op, const char *caller) { int xop; YglGCValues yv; switch(op) { case LO_ZERO: xop = GXclear; break; case LO_AND: xop = GXand; break; case LO_ANDR: xop = GXandReverse; break; case LO_SRC: xop = GXcopy; break; case LO_ANDI: xop = GXandInverted; break; case LO_DST: xop = GXnoop; break; case LO_XOR: xop = GXxor; break; case LO_OR: xop = GXor; break; case LO_NOR: xop = GXnor; break; case LO_XNOR: xop = GXequiv; break; case LO_NDST: xop = GXinvert; break; case LO_ORR: xop = GXorReverse; break; case LO_NSRC: xop = GXcopyInverted; break; case LO_ORI: xop = GXorInverted; break; case LO_NAND: xop = GXnand; break; case LO_ONE: xop = GXset; break; case LO_MIN: case LO_MAX: case LO_AVG: case LO_DMS: case LO_SMD: case LO_SUM: Yprintf(caller, "unsupported argument: %d.\n", op); return; default: Yprintf(caller, "unknown argument: %d.\n", op); return; } yv.gcmask = GCFunction; yv.values.function = xop; change_gc(YglGCMask, &yv); } #endif #ifdef OGL static void logicop_ogl(Int32 op, const char *caller) { GLenum oop; switch(op) { case LO_ZERO: oop = GL_CLEAR; break; case LO_AND: oop = GL_AND; break; case LO_ANDR: oop = GL_AND_REVERSE; break; case LO_SRC: oop = GL_COPY; break; case LO_ANDI: oop = GL_AND_INVERTED; break; case LO_DST: oop = GL_NOOP; break; case LO_XOR: oop = GL_XOR; break; case LO_OR: oop = GL_OR; break; case LO_NOR: oop = GL_NOR; break; case LO_XNOR: oop = GL_EQUIV; break; case LO_NDST: oop = GL_INVERT; break; case LO_ORR: oop = GL_OR_REVERSE; break; case LO_NSRC: oop = GL_COPY_INVERTED; break; case LO_ORI: oop = GL_OR_INVERTED; break; case LO_NAND: oop = GL_NAND; break; case LO_ONE: oop = GL_SET; break; case LO_MIN: case LO_MAX: case LO_AVG: case LO_DMS: case LO_SMD: case LO_SUM: Yprintf(caller, "unsupported argument: %d.\n", op); return; default: Yprintf(caller, "unknown argument: %d.\n", op); return; } glLogicOp(oop); if(oop != GL_COPY) { glEnable(GL_LOGIC_OP); } else { glDisable(GL_LOGIC_OP); } } #endif void logicop(Int32 op) { const char * MyName = "logicop"; I(MyName, "%d", op); IFOGL(logicop_ogl(op, MyName), logicop_x11(op, MyName)); } #ifdef OGL static void getmatrix_ogl(const char *caller, Matrix m) { GLint mode, what; GLfloat glm[16]; short i, j; glGetIntegerv(GL_MATRIX_MODE, &mode); switch(mode) { case GL_MODELVIEW: what = GL_MODELVIEW_MATRIX; break; case GL_PROJECTION: what = GL_PROJECTION_MATRIX; break; default: Yprintf(caller, "strange OpenGL matrix mode %d\n", mode); return; } glGetFloatv(what, glm); /* Under OpenGL matrices are in column order, transpose... */ for(i = 0; i < 4; i++) for(j = 0; j < 4; j++) m[j][i] = glm[4*i + j]; } #endif #ifdef X11 static void getmatrix_x11(Matrix m) { /* We only have orthographic views, so... */ YglWindow *w = W; memset(m, 0, sizeof(Matrix)); m[0][0] = 2.0 / (w->or - w->ol); m[1][1] = 2.0 / (w->ot - w->ob); m[2][2] = -1.0; m[3][0] = -(w->or + w->ol)/(w->or - w->ol); m[3][1] = -(w->ot + w->ob)/(w->ot - w->ob); m[3][3] = 1.0; } #endif void getmatrix(Matrix m) { const char * MyName = "getmatrix"; I(MyName, "Matrix"); IFOGL(getmatrix_ogl(MyName, m), getmatrix_x11(m)); } #ifdef COVERSLEEP #if 0 /* Uncomment next line if you have problems with usleep() in old (prior 1998) versions of Alpha Linux */ /* #define ALPHA_LINUX_USLEEP_BUG */ #ifdef __useconds_t_defined # define USLEEP_RET_TYPE int # define USLEEP_RET_VAL 0 # define USLEEP_ARG_TYPE useconds_t #else /* __useconds_t_defined */ # if defined(__linux) # if defined(__i386) || defined(__alpha) # if defined(ALPHA_LINUX_USLEEP_BUG) /* Under old DEC Alpha Linux, it was "unsigned int usleep(unsigned int)"... * Thanks to Kai Froese */ # define USLEEP_RET_TYPE unsigned int # define USLEEP_RET_VAL 0 # define USLEEP_ARG_TYPE unsigned int # elif defined(__GLIBC__) /* In new GNU libc, usleep is "void usleep(unsigned int)" * Thanks to Juergen Holm */ # define USLEEP_RET_TYPE void # define USLEEP_RET_VAL # define USLEEP_ARG_TYPE unsigned int # else /* In old libc, usleep was "void usleep(unsigned long)" */ # define USLEEP_RET_TYPE void # define USLEEP_RET_VAL # define USLEEP_ARG_TYPE unsigned long # endif # else /* defined(__i386) || defined(__alpha) */ /* Unknown linux derivate */ # error "Unknown Linux derivate, please report to author" # endif # elif defined(__FreeBSD__) /* Under FreeBSD, usleep is "void usleep(unsigned int)" * Thanx to Pedro Giffuni * and Stephen Kennedy */ # define USLEEP_RET_TYPE void # define USLEEP_RET_VAL # define USLEEP_ARG_TYPE unsigned int # else /* defined(__linux) || defined(__FreeBSD__) */ /* On all (?) other platforms, usleep is "int usleep(unsigned int)" */ # define USLEEP_RET_TYPE int # define USLEEP_RET_VAL 0 # define USLEEP_ARG_TYPE unsigned int # endif /* defined (__linux) */ #endif /* __useconds_t_defined */ #endif /* 0 */ #include "usleep.h" #ifndef USLEEP_RET_TYPE # define USLEEP_RET_TYPE int # define USLEEP_RET_VAL 0 #endif #ifndef USLEEP_ARG_TYPE # define USLEEP_ARG_TYPE unsigned int #endif USLEEP_RET_TYPE usleep(USLEEP_ARG_TYPE Useconds) { struct timeval tmout; if(D != NULL) IFOGL(glFlush(), XFlush(D)); tmout.tv_usec = Useconds % 1000000; tmout.tv_sec = Useconds / 1000000; (void) select(0, NULL, NULL, NULL, &tmout); return USLEEP_RET_VAL; } Uint sleep(Uint seconds) { struct timeval tmout; if(D != NULL) IFOGL(glFlush(), XFlush(D)); tmout.tv_usec = 0; tmout.tv_sec = seconds; (void) select(0, NULL, NULL, NULL, &tmout); return 0; } #endif ygl-4.2e/ReadMe.html0000644000175000017500000011656210616075414013705 0ustar prabhuprabhu Ygl Version 4.2 Description

Logo Ygl Version 4.2 Description

©opyright 1993-2007 by Fred Hucht (fred(AT)thp.Uni-Duisburg.DE)

Ygl is distributed in terms of the GNU LIBRARY GENERAL PUBLIC LICENSE. Please see the file LICENSE for further details. You may not distribute this project without this file (ReadMe.html) and the LICENSE file included.

Here you can read the Changes history and the Ygl FAQ.

Description

Ygl emulates SGI's GL routines under X11. It compiles fine under AIX >3.2, HP-UX >7.0, Linux with XFree/Xorg, SunOS, ConvexOS, Mac A/UX, Mac OS/X and many others, but needs an ANSI-C compiler (gcc is ok). It was written for two reasons:
  • On our RS/6000 GT4 hardware, 2D Ygl is up to twenty times faster (circf()) than GL (strange, isn't it?...)
  • 2D (and 3D using OpenGL) graphics runs on non GL hardware and even on remote X-Servers.
Included are most of the two-dimensional graphics routines, the queue device routines, the query routines, doublebuffering, RGB mode with dithering, window attribute routines, FORTRAN bindings and more (see below).

3D stuff was added with version 4.0 using OpenGL calls.

Since Version 2.8, all Ygl functions do have a FORTRAN interface. The FORTRAN versions of all functions have an underscore appended, so the FORTRAN compiler must append a '_' to all function names. f2c does this, xlf (under AIX 3.2) requires the option -qextname. See smile_f77.f for an example program. Set FortranBindings to 0 in Imakefile or change Makefile.std if you don't want these bindings. FORTRAN bindings are not tested because I have no programs.f to test. If you find bugs, feel free to report them to me.

You can always find the latest version of Ygl in the directory ftp.thp.Uni-Duisburg.de/pub/source/X11/.

Note that perl, python and tcl bindings for Ygl are available here thanks to Prabhu Ramachandran.

Details

Environment variables:

Several environment variables are referenced in the library to control the behavior of Ygl:
  • The environment variable YGL_PRIVATECOLORMAP or YGL_PCM can be set to 1 to force Ygl to use a private colormap. While GL always uses a private colormap, Ygl uses the global map by default to avoid technicolor effects on X-Servers not capable of more than one colormap at a time. Note that you can only redefine the color of already drawn objects when you use a private colormap.
  • The environment variable YGL_FLUSHTIME or YGL_FT (default value: 0.1) can be used to adjust the time in seconds between flushes of the graphics pipeline. It can be set to 0 to disable the automatic update via interval timer. Setting YGL_FLUSHTIME to -1 will put the X-Server into synchronous mode (see XSynchronize). This mode seems to be veeeryyy slooow, but is good for debugging...
  • The environment variable YGL_BACKINGSTORE or YGL_BS can be set to 1 to enable BackingStore support for all Ygl windows. With BackingStore, the X-Server remembers the contents of a window when it gets obscured or iconified. You must start your X-Server with the option "-bs" ("+bs" on some systems) to use this feature.
  • The environment variables YGL_CMAPVISUAL or YGL_CV and YGL_RGBVISUAL or YGL_RV control the selection of visuals for cmapmode and RGBmode. Set these variables to the visual id of the desired visual as returned by xdpyinfo (both hex and decimal is ok). Setting one of these variables to -1 forces Ygl to use the default visual of the screen instead of the best visual.
  • The environment variable YGL_SINGLEGC or YGL_GC can be set to 1 to force Ygl to use a single graphics context for colormap windows. Per default Ygl uses one GC for each color, i.e. 256 GCs for a 8 bit colormap window, because this speeds up drawing with many color changes by a factor of 2 or so on many systems. Using a single GC may be faster if you use many mapcolor calls as in colormap animation. Note that if the used colormap visual has more than 256 colors YGL_GC defaults to 1.
  • The environment variable YGL_PARENTWID or YGL_PWID controls the parent window of Ygl. Per default the root window of the default screen of the given display is the parent window of windows opened with winopen(). Set this variable to the window id of the desired window as returned by xwininfo (both hex and decimal is ok).
  • The environment variable YGL_DITHERSIZE or YGL_DSZ controls dithering in RGB mode.With this variable you can specify the size of the dither matrix. The default value is 4, leading to a 4x4 dither matrix. Valid values range from 0 to 6. On a normal 8 bit TrueColor visual ({3,3,2} bits {red,green,blue}) you obtain 113x113x49 = 625681 different "colors" with YGL_DSZ=4, leading to an effective screen depth of approx. 19 bits. The other values and the effective screendepth are:
             |  8 bit (3-3-2)  | 12 bit (4-4-4)  |  16 bit (6-5-5)
      YGL_DSZ| # colors (bits) | # colors (bits) |  # colors (bits)
      -------------------------------------------------------------
        0,1  |      256 ( 8  ) |     4096 (12  ) |     65536 (16  )
         2   |    10933 (13.4) |   226981 (17.8) |   3953125 (21.9)
         3   |   114688 (16.8) |  2515456 (21.3) |  44531200 (25.4)
         4   |   625681 (19.3) | 13997521 (23.7) | 249232081 (27.9)
         5   |  2354176 (21.2) | 53157376 (25.7) | 949029376 (29.8)
         6   |  6976981 (22.7) |158340421 (27.2) |2831006341 (31.4)
    
    Note that dithering costs speed. You may set YGL_DSZ=0 to disable dithering. If you are lucky and have a 24 bit TrueColor visual, YGL_DSZ is automatically set to zero.

Doublebuffering:

Ygl supports doublebuffering via the XServer extensions "DOUBLE-BUFFER" (new in X11R6.1) and "Multi-Buffering". The related routines are doublebuffer(), swapbuffer() and singlebuffer().

Notes:

OpenGL:
You can use the routine gsync() to wait for the next vertical retrace. If you use doublebuffering, it might help to set the environment variable __GL_SYNC_TO_VBLANK to 1 to swap buffers at a vertical retrace.
X11R6.1:
If you have X11R6.1 or later, set DoubleBuffer to 1 in Imakefile.
AIX < 3.2.5:
The extension "Multi-Buffering" is new in X11R5 and is included in the lpp X11dev.src under AIX. To use doublebuffering you have to link the "Multi-Buffering" extension into your X-Server (under AIX, see /usr/lpp/X11/Xamples/README, "Linking the Sample Extensions into the Server").
AIX >= 3.2.5:
You don't need to recompile the X-Server anymore to use doublebuffering under AIX 3.2.5 (AIXWindows 1.2.3). You simply have to add the option "-x mbx" to the X-Servers command line on startup.
AIX >= 4.1:
You need the LPP X11.adt.ext to compile Ygl with doublebuffering enabled.

RGB mode:

Ygl can run in a per window RGB mode, if the X-Server has a TrueColor or DirectColor visual. Ygl will always select the appropiate visual for the desired mode, independent of the default visual, i.e.:
 Colormap mode <-> PseudoColor, StaticColor,
                   GrayScale, StaticGray,
                   TrueColor or DirectColor visual

 RGB mode      <-> TrueColor or DirectColor visual
A RGB mode window is a child of the initially created colormap mode window. Ygl uses the property WM_COLORMAP_WINDOWS to tell the window manager, which colormaps are to be installed. To toggle the colormaps when a RGB window is subwindow of a colormap window, use the window manager function f.colormap in twm or f.next_cmap in mwm. Ygl will automatically dither all output if the X-Server doesn't support 24 bits. See the section environment variables for details.

Multiple Expose events (REDRAW) in qread:

Ygl ignores all Expose events that have e.xexpose.count != 0 (see XExposeEvent(3X11)) AND all Expose events when another Expose event for the same window is in the Event queue. This procedure minimizes unnessesary redraws. Nevertheless, a REDRAW event is generated when a window is moved even when the contents of the window does not have to be redrawn. This is to be compatible with SGI's GL, where no extra event for window moves exist :-(

Automatic flushing of the graphics pipeline:

The process virtual interval timer (see setitimer(3)) is used to flush the graphics pipeline every 0.1 seconds. This interval is adjustable (see above). The system functions sleep() and usleep() are covered by the library to flush the pipeline, too. This had to be done because the GL hardware flushes the pipeline automatically on every vertical retrace and has no command to flush.

Note that sleep() and usleep() always return 0.

You can use "sleep(0)" to flush the graphics pipeline explicitly. If you have problems with sleep() and usleep(), undefine COVERSLEEP in header.h.

Supported routines

Finally a list of supported GL routines is included. For a detailed description of the routines see the GL manuals in the Info-Explorer (under AIX) or click at the command below.

Window related routines:

minsize, maxsize, prefsize, prefposition, stepunit, keepaspect, winopen, winclose, gconfig, gexit, wintitle, winset, winget, getsize, getorigin, getXdpy, getXwid, getbutton, getvaluator, winmove, winposition, ginit, winpop, winpush, windepth, swinopen, winconstraints, noport, noborder, winX.
Note: The routine winX(Display *dpy, Window win) will ignore the first argument dpy. Ygl always uses the XServer specified in the environment variable DISPLAY.

Color related routines:

RGBmode, RGBcolor, cmode, color, mapcolor, getplanes, getmcolor, getmcolors, getcolor, gRGBcolor, c3s, c3i, c3f, cpack.

Device related routines:

tie, noise, isqueued, qdevice, unqdevice, qreset, qtest, qread, qenter,
Notes:
  • Currently supported devices are: REDRAW, KEYBD, INPUTCHANGE, LEFTMOUSE, MIDDLEMOUSE, RIGHTMOUSE (MENUBUTTON), MOUSEX, MOUSEY, WINQUIT, and all individual keys as F1KEY, ESCKEY, UPARROWKEY, and so on.
  • qenter does only support the REDRAW device.

Menu routines:

defpup, newpup, addtopup, dopup, freepup, setpup.
Note: The routines addpup() and defpup() accept an additional modifier '%M'. If you define a submenu anchor with '%M' instead of '%m', Ygl calls the function defined with '%F' with the two arguments menu-return and submenu-return, i.e.:
int callback(Int32 m, Int32 s) {
  sleep(s);
  switch(m) {
  case 1: explode(); break;
  case 2: implode(); break;
  }
  return(m << 8 + s);
}

main() {
  ...
  sub  = defpup("Seconds%t|1|2|3|4|5");
  menu = defpup("Menu%t%F|Explode%M|Implode%M",	callback, sub, sub);
  ...
}
See examples/popup.c for details.

Font routines:

loadXfont, font, getfont, getfontencoding, getheight, getdescender, strwidth, charstr.

Doublebuffer routines:

singlebuffer, doublebuffer, swapbuffers, frontbuffer, backbuffer.

Misc routines:

gflush, gsync, gversion, rectzoom, lrectread, lrectwrite, rectcopy, readsource, rectread, rectwrite, readpixels, writepixels, readRGB, writeRGB, blendfunction, linewidth, getlwidth, deflinestyle, setlinestyle, getlstyle, lsrepeat, getlsrepeat, logicop, getdisplaymode, getgdesc, setbell, ringbell.

Coordinate transformation routines:

ortho2, viewport, getviewport, reshapeviewport, pushviewport, popviewport, getmatrix.

Drawing routines:

clear, pnt2s, pnt2i, pnt2, move2s, move2i, move2, rmv2s, rmv2i, rmv2, draw2s, draw2i, draw2, rdr2s, rdr2i, rdr2, arcs, arci, arc, arcfs, arcfi, arcf, circs, circi, circ, circfs, circfi, circf, rects, recti, rect, rectfs, rectfi, rectf, sboxs, sboxi, sbox, sboxfs, sboxfi, sboxf, concave, pmv2s, pmv2i, pmv2, rpmv2s, rpmv2i, rpmv2, pdr2s, pdr2i, pdr2, rpdr2s, rpdr2i, rpdr2, pclos, poly2s, poly2i, poly2, polf2s, polf2i, polf2, bgnpoint, endpoint, bgnline, endline, bgnclosedline, endclosedline, bgnpolygon, endpolygon, v2s, v2i, v2f, v2d, cmov2s, cmov2i, cmov2, getcpos.
Note: It's not possible to change drawing attributes (color, ...) in the middle of a vertex pipeline in Ygl. This affects the routines {bgn|end}{point|line|closedline|polygon}() and pdr(), rpdr().

3D routines

Drawing:

c4s, c4i, c4f, cmovs, cmovi, cmov, pnts, pnti, pnt, moves, movei, move, draws, drawi, draw, rmvs, rmvi, rmv, rdrs, rdri, rdr, pmvs, pmvi, pmv, rpmvs, rpmvi, rpmv, pdrs, pdri, pdr, rpdrs, rpdri, rpdr, polfs, polfi, polf, v3s, v3i, v3f, v3d, v4s, v4i, v4f, v4d, swaptmesh.

Coordinate Systems:

ortho, lookat, window, perspective, polarview, rot, rotate, scale, translate, loadmatrix, multmatrix, pushmatrix, popmatrix, getmmode, mmode.

Polygon specs:

shademodel, n3f, normal, backface, frontface.

z-Buffer:

zbuffer, zclear, zdraw, zfunction, czclear, depthcue, lRGBrange, lsetdepth, lshaderange.

Display lists:

genobj, isobj, makeobj, getopenobj, closeobj, callobj, delobj.

Misc:

lmbind, lmcolor, lmdef, RGBwritemask, pushattributes, popattributes, scrmask.

Picking/Names:

pick, endpick, picksize, initnames, loadname, pushname, popname.

NOPs:

foreground, drawmode, iconsize, overlay, fullscrn, endfullscrn.

Routines not in SGI's GL:

The following routines are added to standard GL:
  • GC getXgc(void)
    return current graphics context. You can for example use it to draw lines xor'ed with the background:
    #include <X11/X.h>
    ...
    XSetFunction(getXdpy(), getXgc(), GXxor);
    
    Note: Since version 3.1, getXgc() is not supported anymore, as you can use the routine logicop() to set the drawing function.

  • Window getXdid()
    return window id of the current drawable. This id differs from the window id returned by getXwid() when in RGB mode or when using doublebuffering.

  • Int32 crectread(Screencoord x1, Screencoord y1, Screencoord x2, Screencoord y2, Uint8 *data)
    read screen data to unsigned char array data

  • void crectwrite(Screencoord x1, Screencoord y1, Screencoord x2, Screencoord y2, Uint8 *data)
    write unsigned char array data to screen

  • void arcxs(Scoord x,Scoord y,Scoord rx,Scoord ry,Angle s,Angle e)
    void arcxi(Icoord x,Icoord y,Icoord rx,Icoord ry,Angle s,Angle e)
    void arcx(Coord x,Coord y,Coord rx,Coord ry,Angle s,Angle e)

    draw ellipses

  • void arcxfs(Scoord x,Scoord y,Scoord rx,Scoord ry,Angle s,Angle e)
    void arcxfi(Icoord x,Icoord y,Icoord rx,Icoord ry,Angle s,Angle e)
    void arcxf(Coord x,Coord y,Coord rx,Coord ry,Angle s,Angle e)

    draw filled ellipses

  • int gl2ppm(char *filename)
    write out active Ygl window to portable pixmap file 'filename'. When filename[0] == '|', uses popen() instead of fopen(). Note that gl2ppm() can also be used in a GL application. Just add gl2ppm.o to the list of object files.

Acknowledgements

The author would like to thank Michael Staats (michael(AT)thp.Uni-Duisburg.DE) and Ralf Meyer (ralf(AT)thp.Uni-Duisburg.DE) for some hints and tips.

GL is a registered trademark of Silicon Graphics, Inc. ygl-4.2e/color.c0000444000175000017500000005351410620036121013122 0ustar prabhuprabhu/* * Ygl: Run GL programs with standard X11 and/or OpenGL routines. * (C) Fred Hucht 1993-2007 * EMail: fredthp.Uni-Duisburg.de */ static const char vcid[] = "$Id: color.c,v 4.9 2007-05-08 11:01:05+02 fred Exp $"; #include "header.h" static int rect_read_errh(Display *, XErrorEvent *); static Int32 rect_read(const char*, Screencoord, Screencoord, Screencoord, Screencoord, int, void *); static void rect_write(const char*, Screencoord, Screencoord, Screencoord, Screencoord, int, void *); static Ulong emuColorsInv(Ulong x); #ifdef X11 static void create_dither(int r, int g, int b); static void set_color(const char *caller, int r, int g, int b); #endif #define YGL_COLORSINV(x) (Ygl.PCM ? CMapSize-1-(x) : Ygl.EmulateCmap ? emuColorsInv(x) : Ygl.ColorsInv[x]) static Ulong emuColorsInv(Ulong x) { Ulong i; for(i = 0; i < CMapSize && Ygl.Colors[i] != x; i++); return i < CMapSize ? i : 0; } void mapcolor(Colorindex ind, Int16 r, Int16 g, Int16 b) { XColor xc; const char * MyName = "mapcolor"; I(MyName, "%d,%d,%d,%d", ind, r, g, b); if(W->rgb) { Yprintf(MyName, "not in CMap mode.\n"); return; } if(ind >= CMapSize) { Yprintf(MyName, "can't map cell %d (must be between 0 and %d).\n", ind, CMapSize-1); return; } xc.red = r << 8; xc.green = g << 8; xc.blue = b << 8; if(!Ygl.PCM) { /* use default colormap */ if (Ygl.Colors[ind]) XFreeColors(D, Ygl.CCmap, Ygl.Colors + ind, 1, 0); if(XAllocColor(D, Ygl.CCmap, &xc)) { Ygl.Colors[ind] = xc.pixel; if(!Ygl.EmulateCmap) Ygl.ColorsInv[xc.pixel] = ind; } else { Yprintf(MyName, "can't allocate color (%d, %d, %d) for cell %d, colormap full.\n", r, g, b, ind); } } else { /* use private colormap */ xc.pixel = CMapSize - 1 - ind; xc.flags = DoRGB; XStoreColor(D, Ygl.CCmap, &xc); } #ifdef DEBUG fprintf(stderr, "mapcolor: index = %d, xc = %d (%d,%d,%d)\n", ind, xc.pixel, xc.red, xc.green, xc.blue); #endif if(!Ygl.GC) { /* if GC list in CMap windows */ int i; YglWindow *w = &Ygl.Windows[1]; /* first window */ for(i = 1; i < Ygl.NextWindow; i++, w++) { if(w->main != 0 && !w->rgb) { XSetForeground(D, w->gclist[ind], ind); } } } F; } #ifdef X11 static const char *DI[] = { /* index vector for dither matrices */ "\000", /* DI[sz][c] >> 3 : x-coordinate */ "\000", /* DI[sz][c] & 7 : y-coordinate */ /* 2x2 ***+-0--1-*/ "\000\011" /*0| 0 3 */ "\001\010", /*1| 2 1 */ /* 3x3 ***+-0--1--2-*/ "\000\011\012" /*0| 0 5 3 */ "\020\001\010" /*1| 4 1 7 */ "\022\021\002", /*2| 8 2 6 */ /* 4x4 ***+-0--1--2--3-*/ "\000\022\002\020" /*0| 0 8 3 11 */ "\011\033\013\031" /*1|12 4 15 7 */ "\010\032\012\030" /*2| 2 10 1 9 */ "\021\003\023\001", /*3|14 6 13 5 */ /* 5x5 ***+-0--1--2--3--4-*/ "\000\012\024\031\043" /*0| 0 5 10 15 20 */ "\010\022\034\041\003" /*1|13 18 23 3 8 */ "\020\032\044\001\013" /*2|21 1 6 11 16 */ "\030\042\004\011\023" /*3| 9 14 19 24 4 */ "\040\002\014\021\033", /*4|17 22 2 7 12 */ /* 6x6 ***+-0--1--2--3--4--5-*/ "\000\033\002\035\004\031" /*0| 0 18 16 34 9 27 */ "\011\044\013\040\015\042" /*1|33 6 24 5 23 15 */ "\022\055\024\051\020\053" /*2| 2 20 12 30 11 29 */ "\010\043\012\045\014\041" /*3|35 8 26 1 19 17 */ "\021\054\023\050\025\052" /*4| 4 22 14 32 7 25 */ "\032\005\034\001\030\003" /*5|31 10 28 3 21 13 */ }; static void create_dither(int r, int g, int b) { YglWindow *w = W; int i, c; int sz = Ygl.DSZ, szq = sz * sz; int ri, gi, bi, rx, gx, bx, ry, gy, by, red, green, blue; static int init = 0; static int rn, gn, bn; if(init == 0) { /* Initialize static vars */ init = 1; rn = ((256 >> Ygl.rb) - 1) * szq + 1; /* Number of dither patterns red */ gn = ((256 >> Ygl.gb) - 1) * szq + 1; /* Number of dither patterns green */ bn = ((256 >> Ygl.bb) - 1) * szq + 1; /* Number of dither patterns blue */ #ifdef DEBUG fprintf(stderr, "create_dither: sz = %d, {rn, gn, bn} = {%d,%d,%d}\n", sz, rn, gn, bn); #endif } /* Index of dither pat., base color, # elements with color rx + 1 */ ri = (r * rn) >> 8; rx = ri / szq; ry = ri % szq; gi = (g * gn) >> 8; gx = gi / szq; gy = gi % szq; bi = (b * bn) >> 8; bx = bi / szq; by = bi % szq; red = (ri << 8) / rn; green = (gi << 8) / gn; blue = (bi << 8) / bn; if(red != w->red || green != w->green || blue != w->blue) { /*Already set?*/ /* No, we must change pattern/color */ Ulong mask; XGCValues values; w->red = red; w->green = green; w->blue = blue; if(ry + gy + by == 0) { /* We hit pure color, don't dither but set foreground in w->gc */ mask = GCFillStyle | GCForeground; values.fill_style = FillSolid; values.foreground = ((rx << Ygl.rs) & Ygl.RMask) + ((gx << Ygl.gs) & Ygl.GMask) + ((bx << Ygl.bs) & Ygl.BMask); } else { /* Dither. */ mask = GCTile | GCFillStyle; values.fill_style = FillTiled; values.tile = w->pm; for(c = szq; c > 0; c--) { if(c == ry) rx++; /* Go to next color */ if(c == gy) gx++; if(c == by) bx++; i = DI[sz][c-1]; /* Next position in dither matrix */ XPutPixel(w->pmi, i >> 3, i & 7, /* Simplified RGB_TO_RGBVisual */ ((rx << Ygl.rs) & Ygl.RMask) + ((gx << Ygl.gs) & Ygl.GMask) + ((bx << Ygl.bs) & Ygl.BMask)); } XPutImage(D, w->pm, w->pmgc, w->pmi, 0, 0, 0, 0, sz, sz); } XChangeGC(D, w->gc, mask, &values); } } #endif /* X11 */ /* converts 24 bit RGB values ( 0xBBGGRR ) to value appropiate for RGBVisual */ #define RGB24_TO_RGBVisual(rgb24) ( \ ((((rgb24) >> (Ygl.rb + 0)) << Ygl.rs) & Ygl.RMask) \ + ((((rgb24) >> (Ygl.gb + 8)) << Ygl.gs) & Ygl.GMask) \ + ((((rgb24) >> (Ygl.bb + 16)) << Ygl.bs) & Ygl.BMask) ) #define RGBVisual_TO_RGB24(pixel) ( \ ((((pixel) & Ygl.RMask) >> Ygl.rs) << (Ygl.rb + 0)) \ + ((((pixel) & Ygl.GMask) >> Ygl.gs) << (Ygl.gb + 8)) \ + ((((pixel) & Ygl.BMask) >> Ygl.bs) << (Ygl.bb + 16)) ) #define RGB_TO_RGBVisual(r,g,b) ( \ ((((r) >> Ygl.rb) << Ygl.rs) & Ygl.RMask) \ + ((((g) >> Ygl.gb) << Ygl.gs) & Ygl.GMask) \ + ((((b) >> Ygl.bb) << Ygl.bs) & Ygl.BMask) ) #ifdef X11 static void set_color(const char *caller, int r, int g, int b) { if(!W->rgb) { Yprintf(caller, "not in RGB mode.\n"); return; } if(W->pm) { create_dither(r, g, b); } else { XSetForeground(D, W->gc, RGB_TO_RGBVisual(r, g, b)); } } #endif /* X11 */ void RGBcolor(Int16 r, Int16 g, Int16 b) { const char * MyName = "RGBcolor"; I(MyName, "%d,%d,%d", r, g, b); IFOGL(glColor3ub(r, g, b), set_color(MyName, r, g, b) ); } void cpack(Uint32 rgb) { const char * MyName = "cpack"; I(MyName, "%0x%x", rgb); IFOGL(glColor4ubv((GLubyte *)&rgb), set_color(MyName, (rgb >> 0) & 0xFF, (rgb >> 8) & 0xFF, (rgb >> 16) & 0xFF) ); } void c3s(Int16 c[3]) { IFOGL(glColor3usv((GLushort *)c),set_color("c3s", c[0], c[1], c[2])); } void c4s(Int16 c[4]) { IFOGL(glColor4usv((GLushort *)c),set_color("c4s", c[0], c[1], c[2])); } void c3i(Int32 c[3]) { IFOGL(glColor3uiv((GLuint *)c),set_color("c3i", c[0], c[1], c[2])); } void c4i(Int32 c[4]) { IFOGL(glColor4uiv((GLuint *)c),set_color("c4i", c[0], c[1], c[2])); } void c3f(Float32 c[3]) { IFOGL(glColor3fv(c), float f = 255.9999999; set_color("c3f", (int)(f * c[0]), (int)(f * c[1]), (int)(f * c[2]))); } void c4f(Float32 c[4]) { IFOGL(glColor4fv(c), float f = 255.9999999; set_color("c4f", (int)(f * c[0]), (int)(f * c[1]), (int)(f * c[2]))); } #if 0 /* This version is veeeryyy slooowwww !!! */ void RGBcolor (Int16 r, Int16 g, Int16 b) { XColor xc; const char * MyName = "RGBcolor"; I(MyName); if(!W->rgb) { Yprintf(MyName, "not in RGB mode.\n"); return; } xc.red = r << 8; xc.green = g << 8; xc.blue = b << 8; if(XAllocColor(D, Ygl.RCmap, &xc)) XSetForeground(D, W->gc, xc.pixel); else Yprintf(MyName, "can't allocate color (%d, %d, %d), colormap full.\n", r, g, b); } #endif Int32 getcolor(void) { const char * MyName = "getcolor"; I(MyName, ""); if(W->rgb) { Yprintf(MyName, "not in CMap mode.\n"); return 0; } return W->color; } void getmcolor (Colorindex ind, Int16 *r, Int16 *g, Int16 *b) { XColor xc; const char * MyName = "getmcolor"; I(MyName, "%d,*,*,*", ind); if(W->rgb) { Yprintf(MyName, "not in CMap mode.\n"); return; } xc.pixel = YGL_COLORS(ind); XQueryColor(D, Ygl.CCmap, &xc); *r = xc.red >> 8; *g = xc.green >> 8; *b = xc.blue >> 8; } void getmcolors (Colorindex ind1, Colorindex ind2, Int16 *r, Int16 *g, Int16 *b) { XColor *xc; Colorindex i; int n = ind2 - ind1 + 1; const char * MyName = "getmcolors"; I(MyName, "%d,%d,*,*,*", ind1, ind2); if(W->rgb) { Yprintf(MyName, "not in CMap mode.\n"); return; } if(n < 0) { Yprintf(MyName, "2nd argument < 1st argument.\n"); return; } if(NULL == (xc = (XColor*) malloc(n * sizeof(XColor)))) { Yprintf(MyName, "can't allocate memory.\n"); exit(1); } for(i = 0; i < n; i++) xc[i].pixel = YGL_COLORS(i); XQueryColors(D, Ygl.CCmap, xc, n); for(i = 0; i < n; i++) { r[i] = xc[i].red >> 8; g[i] = xc[i].green >> 8; b[i] = xc[i].blue >> 8; } free(xc); } void gRGBcolor(Int16 *r, Int16 *g, Int16 *b) { XGCValues ret; const char * MyName = "gRGBcolor"; I(MyName, "*,*,*"); if(!W->rgb) { Yprintf(MyName, "not in RGB mode.\n"); return; } if(W->pm) { *r = W->red; *g = W->green; *b = W->blue; } else { if(XGetGCValues(D, W->gc, GCForeground, &ret)) { *r = ((ret.foreground & Ygl.RMask) >> Ygl.rs) << Ygl.rb; *g = ((ret.foreground & Ygl.GMask) >> Ygl.gs) << Ygl.gb; *b = ((ret.foreground & Ygl.BMask) >> Ygl.bs) << Ygl.bb; } else { Yprintf(MyName, "cannot get GCValues.\n"); } } #ifdef DEBUG fprintf(stderr, "gRGBcolor: foreground = %d, (r,g,b) = (%d,%d,%d).\n", ret.foreground,*r,*g,*b); #endif } void color(Colorindex ind) { const char * MyName = "color"; I(MyName, "%d", ind); if(W->rgb) { Yprintf(MyName, "not in CMap mode.\n"); } else if(ind >= CMapSize) { Yprintf(MyName, "invalid color %d (must be between 0 and %d).\n", ind, CMapSize-1); } else { Ulong col = YGL_COLORS(ind); W->color = ind; IFOGL( if(Ygl.EmulateCmap) { glColor3ub((col >> 16) & 0xff, (col >> 8) & 0xff, col & 0xff); } else { /*fprintf(stderr, "glIndexi(0x%x)\n", col);*/ glIndexi(col); } , if(Ygl.GC) XSetForeground(D, W->gc, col); /* single GC */ else W->gc = W->gclist[col] ); } } #ifndef YGL_PREFIX void Xcolor(unsigned int ind) { const char * MyName = "Xcolor"; I(MyName, "%d", ind); if(W->rgb) { Yprintf(MyName, "not in CMap mode.\n"); } /*else if(ind >= CMapSize) Yprintf(MyName, "invalid color %d (must be between 0 and %d).\n", ind, CMapSize-1);*/ else { W->color = YGL_COLORSINV(ind); IFOGL(/*fprintf(stderr, "glIndexi(0x%x)\n", ind);*/ if(Ygl.EmulateCmap) { glColor3ub((ind >> 16) & 0xff, (ind >> 8) & 0xff, ind & 0xff); } else { /*fprintf(stderr, "glIndexi(0x%x)\n", ind);*/ glIndexi(ind); } , if(Ygl.GC) XSetForeground(D, W->gc, ind); /* single GC */ else W->gc = W->gclist[ind] ); } } void getmXcolor (Colorindex ind, Int16 *r, Int16 *g, Int16 *b) { XColor xc; const char * MyName = "getmXcolor"; I(MyName, "%d,*,*,*", ind); if(W->rgb) Yprintf(MyName, "not in CMap mode.\n"); else { xc.pixel = ind; XQueryColor(D, Ygl.CCmap, &xc); *r = xc.red >> 8; *g = xc.green >> 8; *b = xc.blue >> 8; } } #endif /* block pixel transfer routines */ static int rect_read_front = True; void readsource(Int32 source) { const char * MyName = "readsource"; I(MyName, "%d", source); switch(source) { case SRC_AUTO: case SRC_BACK: rect_read_front = False; break; case SRC_FRONT: rect_read_front = True; break; default: Yprintf(MyName, "unknown mode %d.\n", source); break; } } static int rect_read_err; static int rect_read_errh(Display *dpy, XErrorEvent *error) { rect_read_err = error->error_code; return 0; } static Float32 Zoom[2] = {1.0, 1.0}; static int DoZoom = False; void rectzoom(Float32 xfactor, Float32 yfactor) { const char * MyName = "readsource"; I(MyName, "%g,%g", xfactor, yfactor); if(xfactor < 0.0 || yfactor < 0.0) { Yprintf(MyName, "xfactor of yfactor negative.\n"); return; } Zoom[0] = xfactor; Zoom[1] = yfactor; DoZoom = xfactor != 1.0 || yfactor != 1.0; } static Int32 rect_read(const char *caller, Screencoord x1, Screencoord y1, Screencoord x2, Screencoord y2, int size, void *data) { XImage *XI; long x, y; Int32 *data32 = (Int32*) data; Int16 *data16 = (Int16*) data; Uint8 *data8 = (Uint8*) data; Screencoord width = x2 - x1 + 1; Screencoord height = y2 - y1 + 1; int (*old_handler)(Display*, XErrorEvent*); rect_read_err = 0; /* reset */ old_handler = XSetErrorHandler(rect_read_errh); XI = XGetImage(D, rect_read_front ? IF_RGBWIN(W->win, W->main) : W->draw, x1, W->ym - 1 - y2, width, height, (1 << YglDepth())-1, ZPixmap); XSync (D, False); XSetErrorHandler(old_handler); /* reset */ #ifdef DEBUG fprintf(stderr, "rect_read: (w, h) = (%d, %d), XI->(w, h) = (%d, %d), err = %d\n", width, height, XI->width, XI->height, rect_read_err); #endif if(rect_read_err == BadMatch) { Yprintf(caller, "window not completely visible.\n"); return 0; } for(y = XI->height-1; y >= 0; y--) { #if DEBUG > 1 fprintf(stderr, "y = %d\n", y); #endif for(x = 0; x < XI->width; x++) { Ulong pixel; long val; pixel = XGetPixel(XI, x, y); if(W->rgb) { val = RGBVisual_TO_RGB24(pixel); } else { val = YGL_COLORSINV(pixel); } switch(size) { case 1: *(data8++) = val; break; case 2: *(data16++) = val; break; case 4: *(data32++) = val; break; } #if DEBUG > 2 fprintf(stderr, "%x,%x ", pixel, val); #endif } #if DEBUG > 2 fputc(13, stderr); #endif } x = XI->width * XI->height; #ifdef DEBUG fprintf(stderr, "loop end."); #endif XDestroyImage(XI); F; return x; } static void rect_write(const char *caller, Screencoord x1, Screencoord y1, Screencoord x2, Screencoord y2, int size, void *data) { XImage *XI; long x, y, ys; Int32 *data32 = (Int32*) data; Int16 *data16 = (Int16*) data; Uint8 *data8 = (Uint8*) data; Screencoord width = x2 - x1 + 1; Screencoord height = y2 - y1 + 1; Ulong xwidth = Zoom[0] * width; Ulong xheight = Zoom[1] * height; float xf = 1.0 / Zoom[0]; float yf = 1.0 / Zoom[1]; XI = XCreateImage(D, YglVisual(), YglDepth(), ZPixmap, /* Format */ 0, /* Offset */ NULL, /* Data */ xwidth, /* Width */ xheight, /* Height */ 8, /* BitmapPad */ 0); /* BytesPerLine */ if(NULL == (XI->data = (char*) malloc(XI->bytes_per_line * xheight))) { Yprintf(caller, "can't allocate memory.\n"); exit(1); } for(ys = 0, y = xheight - 1; y >= 0; ys++, y--) for(x = 0; x < xwidth; x++) { Ulong idx, pixel; long val = -1; switch(size) { #define ZOOMDATA(p, x_, y_) (p)[idx = (long)(xf * (x_)) + width * (long)(yf * (y_))] case 1: val = DoZoom ? ZOOMDATA(data8, x, ys) : *(data8++); break; case 2: val = DoZoom ? ZOOMDATA(data16, x, ys) : *(data16++); break; case 4: val = DoZoom ? ZOOMDATA(data32, x, ys) : *(data32++); break; #undef ZOOMDATA } if(W->rgb) { pixel = RGB24_TO_RGBVisual(val); } else { /* CMap */ if(val < 0 || val >= CMapSize) { Yprintf(caller, "invalid color %d at position (%d,%d) in CMap mode " "(must be between 0 and %d).\n", val, x, y, CMapSize-1); val = 0; } pixel = YGL_COLORS(val); } #if USE_XPUTPIXEL XPutPixel(XI, x, y, pixel); #else { void * addr; addr = XI->data + y * XI->bytes_per_line + XI->bits_per_pixel/8 * x; switch(XI->bits_per_pixel) { case 8: *(Int8 *)addr = pixel; break; case 16: *(Int16*)addr = pixel; break; case 32: *(Int32*)addr = pixel; break; } } #endif } XPutImage(D, W->draw, W->gc, XI, 0, 0, x1, W->ym - (y1 + xheight), xwidth, xheight); /* free(XI->data) done by XDestroyImage() */ XDestroyImage(XI); F; } Int32 lrectread(Screencoord x1, Screencoord y1, Screencoord x2, Screencoord y2, Int32 *data) { const char * MyName = "lrectread"; I(MyName, "%d,%d,%d,%d,*",x1,y1,x2,y2); return rect_read(MyName, x1,y1,x2,y2, 4, data);} Int32 rectread(Screencoord x1, Screencoord y1, Screencoord x2, Screencoord y2, Int16 *data) { const char * MyName = "rectread" ; I(MyName, "%d,%d,%d,%d,*",x1,y1,x2,y2); return rect_read(MyName, x1,y1,x2,y2, 2, data);} Int32 crectread(Screencoord x1, Screencoord y1, Screencoord x2, Screencoord y2, Uint8 *data) { const char * MyName = "crectread"; I(MyName, "%d,%d,%d,%d,*",x1,y1,x2,y2); return rect_read(MyName, x1,y1,x2,y2, 1, data);} void lrectwrite(Screencoord x1, Screencoord y1, Screencoord x2, Screencoord y2, Int32 *data) { const char * MyName = "lrectwrite"; I(MyName, "%d,%d,%d,%d,*",x1,y1,x2,y2); rect_write(MyName, x1,y1,x2,y2, 4, data);} void rectwrite(Screencoord x1, Screencoord y1, Screencoord x2, Screencoord y2, Int16 *data) { const char * MyName = "rectwrite" ; I(MyName, "%d,%d,%d,%d,*",x1,y1,x2,y2); rect_write(MyName, x1,y1,x2,y2, 2, data);} void crectwrite(Screencoord x1, Screencoord y1, Screencoord x2, Screencoord y2, Uint8 *data) { const char * MyName = "crectwrite"; I(MyName, "%d,%d,%d,%d,*",x1,y1,x2,y2); rect_write(MyName, x1,y1,x2,y2, 1, data);} void rectcopy(Screencoord x1, Screencoord y1, Screencoord x2, Screencoord y2, Screencoord xn, Screencoord yn) { const char * MyName = "rectcopy"; I(MyName, "%d,%d,%d,%d,%d,%d", x1, y1, x2, y2, xn, yn); if(DoZoom) { int n = (x2 - x1 + 1) * (y2 - y1 + 1); Int32 *buf; if(NULL == (buf = (Int32*) calloc(n, sizeof (Int32)))) { Yprintf(MyName, "can't allocate memory.\n"); exit(1); } if(rect_read(MyName, x1, y1, x2, y2, 4, buf)) rect_write(MyName, xn, yn, xn+x2-x1, yn+y2-y1, 4, buf); free((char *)buf); } else { XCopyArea(D, W->draw, W->draw, W->gc, x1, W->ym - 1 - y2, x2 - x1 + 1, y2 - y1 + 1, xn, W->ym - 1 - yn - (y2-y1)); } F; } Int32 readpixels(Int16 n, Colorindex data[]) { Screencoord x, y; Int32 r; const char * MyName = "readpixels"; I(MyName, "%d,*", n); if(W->rgb) { Yprintf(MyName, "not in CMap mode.\n"); exit(1); } x = X(W->xc); y = Y(W->yc); r = rect_read(MyName, x, y, x + n, y + 1, 2, data); W->xc += n / W->xf; return r; } void writepixels(Int16 n, Colorindex data[]) { Screencoord x, y; const char * MyName = "writepixels"; I(MyName, "%d,*", n); if(W->rgb) { Yprintf(MyName, "not in CMap mode.\n"); exit(1); } x = X(W->xc); y = Y(W->yc); rect_write(MyName, x, y, x + n, y + 1, 2, data); W->xc += n / W->xf; } Int32 readRGB(Int16 n, RGBvalue r[], RGBvalue g[], RGBvalue b[]) { Screencoord x, y; Int32 ret, *data, i; const char * MyName = "readRGB"; I(MyName, "%d,*,*,*", n); if(!W->rgb) { Yprintf(MyName, "not in RGB mode.\n"); exit(1); } x = X(W->xc); y = Y(W->yc); W->xc += n / W->xf; if(NULL == (data = (Int32*)malloc(n * sizeof(Int32)))) { Yprintf(MyName, "out of memory.\n"); exit(1); } ret = rect_read(MyName, x, y, x + n, y + 1, 4, data); for(i = 0; i < n; i++) { r[i] = (data[i] >> 0) & 0xFF; g[i] = (data[i] >> 8) & 0xFF; b[i] = (data[i] >> 16) & 0xFF; } free(data); return ret; } void writeRGB(Int16 n, RGBvalue r[], RGBvalue g[], RGBvalue b[]) { Screencoord x, y; Int32 *data, i; const char * MyName = "writeRGB"; I(MyName, "%d,*,*,*", n); if(!W->rgb) { Yprintf(MyName, "not in RGB mode.\n"); exit(1); } x = X(W->xc); y = Y(W->yc); W->xc += n / W->xf; if(NULL == (data = (Int32*)malloc(n * sizeof(Int32)))) { Yprintf(MyName, "out of memory.\n"); exit(1); } for(i = 0; i < n; i++) { data[i] = (b[i] << 16) + (g[i] << 8) + r[i]; } rect_write(MyName, x, y, x + n, y + 1, 4, data); free(data); } #ifdef OGL static Int32 blendfunction_translate(const char *caller, Int32 factor) { Int32 r; switch (factor) { case BF_ZERO: r = GL_ZERO; break; case BF_ONE: r = GL_ONE; break; case BF_SC: r = GL_SRC_COLOR; break; case BF_MSC: r = GL_ONE_MINUS_SRC_COLOR; break; case BF_SA: r = GL_SRC_ALPHA; break; case BF_MSA: r = GL_ONE_MINUS_SRC_ALPHA; break; case BF_DA: r = GL_DST_ALPHA; break; case BF_MDA: r = GL_ONE_MINUS_DST_ALPHA; break; case BF_DC: r = GL_DST_COLOR; break; case BF_MDC: r = GL_ONE_MINUS_DST_COLOR; break; case BF_MIN_SA_MDA: r = GL_SRC_ALPHA_SATURATE; break; default: Yprintf(caller, "invalid argument %d\n", factor); r = 0; break; } return r; } #endif void blendfunction(Int32 sfactor, Int32 dfactor) { const char * MyName = "blendfunction"; I(MyName, "%d,%d", sfactor, dfactor); IFOGL(glBlendFunc(blendfunction_translate(MyName, sfactor), blendfunction_translate(MyName, dfactor)); if (sfactor == BF_ONE && dfactor == BF_ZERO) glDisable(GL_BLEND); else glEnable (GL_BLEND), NI(MyName)); } /* $Log: color.c,v $ * Revision 4.9 2007-05-08 11:01:05+02 fred * Version 4.2d * * Revision 4.8 2006-01-10 10:15:20+01 fred * Added blendfunction() * * Revision 4.7 2005-02-15 11:30:39+01 fred * *** empty log message *** * * Revision 4.6 1998-10-27 17:30:33+01 fred * bug in rect_write(), picture written one pixel too high * * Revision 4.5 1997-09-17 14:16:25+02 fred * *** empty log message *** * * Revision 4.4 1997-07-07 11:09:39+02 fred * *** empty log message *** * * Revision 4.3 1996-10-22 19:00:06+02 fred * rectzoom added * */ ygl-4.2e/gl2ppm.c0000444000175000017500000001212710620056737013217 0ustar prabhuprabhu/* * Ygl: Run GL programs with standard X11 routines. * (C) Fred Hucht 1993-2007 * EMail: fred@thp.Uni-Duisburg.de */ static const char vcid[] = "$Id: gl2ppm.c,v 3.9 2007-05-08 13:24:15+02 fred Exp $"; #ifdef YGL_PREFIX # include #endif #include #include #include #if 0 # include # include # include #else # include #endif #if defined(_AIX) || defined(DEBUG) # include #endif #ifndef TRUE # define TRUE (0==0) # define FALSE (!TRUE) #endif #define BYTE(x, n) (((x)>>(n)) & 0xFF) static int broken_pipe; static void pipe_error(int sig_no) { broken_pipe = TRUE; signal(SIGPIPE, pipe_error); } static int check_error(const char *fname, void (*oldsp)(int), int err) { int ret = FALSE; /* No error */ if (broken_pipe) { fprintf(stderr, "gl2ppm: Broken pipe while writing to '%s'.\n", fname+1); ret = TRUE; } if (err) { perror("gl2ppm: "); ret = TRUE; } return ret; } int gl2ppm(const char *fname) { /* * Read the active [Y]gl-window and write a ppm file * If fname[0] == '|', use popen. * return value: * 1 success * 0 not all bytes written or can't open file * * Fred Hucht 1992/95 */ int cells = 0, size, r, ret = 0; Int16 *R = NULL, *G = NULL, *B = NULL; Int32 *buf = NULL, dx, dy, dxdy; register Int32 ix, iy; FILE *tn = NULL; Int32 DisplayMode = getdisplaymode(), CMapMode, DBufMode; void (*oldsigpipe)(int); CMapMode = DisplayMode == DMSINGLE || DisplayMode == DMDOUBLE; /* cmap mode? */ DBufMode = DisplayMode == DMDOUBLE || DisplayMode == DMRGBDOUBLE; getsize(&dx, &dy); /* Get size of GL window */ dxdy = dx*dy; if (NULL == (buf = (Int32*) calloc(dxdy, sizeof(Int32)))) { fprintf(stderr, "gl2ppm: can't allocate memory.\n"); exit(1); } #ifdef DEBUG fprintf(stderr, "gl2ppm: reading %d Pixels.\n", dxdy); #endif if (DBufMode) readsource(SRC_FRONT); size = lrectread(0, 0, dx-1, dy-1, buf); if (DBufMode) readsource(SRC_AUTO); #ifdef DEBUG fprintf(stderr, "gl2ppm: read %d of %d Pixels.\n", size, dxdy); #endif #if defined(DEBUG) || defined(JOKE) if (DBufMode) frontbuffer(TRUE); clear(); sleep(1); lrectwrite (0, 0, dx-1, dy-1, buf); /* Little joke... */ if (DBufMode) frontbuffer(FALSE); #endif if (CMapMode) { /* cmap mode */ cells = 1 << getplanes(); /* Number of colormap cells */ R = (Int16*) malloc(sizeof (Int16) * cells); G = (Int16*) malloc(sizeof (Int16) * cells); B = (Int16*) malloc(sizeof (Int16) * cells); if (R == NULL || G == NULL || B == NULL) { fprintf(stderr, "gl2ppm: Can't allocate memory.\n"); exit(1); } getmcolors(0, cells - 1, R, G, B); /* Load colormap. */ } broken_pipe = FALSE; oldsigpipe = signal(SIGPIPE, pipe_error); tn = (fname[0] != '|') ? fopen(fname, "w") : (FILE*) popen((char*)fname+1, "w"); if (tn == NULL) { perror("gl2ppm: cannot open file"); signal(SIGPIPE, oldsigpipe); goto End; } else { #ifdef _AIX errno = 0; /* Don't ask me. Bug in some versions of AIX3 */ #endif } #ifdef DEBUG if (fname[0] == '|') { fprintf(stderr, "gl2ppm: piping through '%s'. errno = %d\n", fname, errno); } else { fprintf(stderr, "gl2ppm: writing ppm-file '%s'. errno = %d\n", fname, errno); } #endif r = 0 > fprintf(tn,"P6\n%d %d\n255\n", (int)dx, (int)dy); /* Write ppm-Header. */ if (check_error(fname, oldsigpipe, r)) goto End; if (CMapMode) { for (iy = dy-1; iy >= 0; iy--) for (ix = 0; ix < dx; ix++) { Int32 b = buf[iy * dx + ix] & (cells-1); r = EOF == putc(R[b], tn) /* Write RGB bytes */ || EOF == putc(G[b], tn) || EOF == putc(B[b], tn); if (check_error(fname, oldsigpipe, r)) goto End; } } else { /* Do brightness correction */ Int32 white = 0xFFFFFF, maxr, maxg, maxb; if (DBufMode) { frontbuffer(TRUE); readsource(SRC_FRONT); } lrectwrite(0, 0, 0, 0, &white); /* Set white pixel at (0,0) */ lrectread (0, 0, 0, 0, &white); /* Read real colors */ #ifdef DEBUG sleep(1); #endif lrectwrite(0, 0, 0, 0, &buf[0]); /* Restore pixel at (0,0) */ if (DBufMode) { frontbuffer(FALSE); readsource(SRC_AUTO); } maxr = BYTE(white, 0); maxg = BYTE(white, 8); maxb = BYTE(white,16); #ifdef DEBUG fprintf(stderr, "gl2ppm: RGB white = (%d,%d,%d)\n", maxr, maxg, maxb); #endif for (iy = dy-1; iy >= 0; iy--) for (ix = 0; ix < dx; ix++) { Int32 b = buf[iy * dx + ix]; /* Write RGB bytes */ r = EOF == putc(((0xFF * BYTE(b, 0)) / maxr), tn) || EOF == putc(((0xFF * BYTE(b, 8)) / maxg), tn) || EOF == putc(((0xFF * BYTE(b,16)) / maxb), tn); if (check_error(fname, oldsigpipe, r)) goto End; } } ret = size == dxdy; End: /* clean up */ if (tn) { if (fname[0] != '|') fclose(tn); else pclose(tn); } if (buf) free(buf); if(CMapMode) { if (R) free(R); if (G) free(G); if (B) free(B); } #ifdef DEBUG fprintf(stderr, "gl2ppm: ready, ret = %d\n", ret); #endif signal(SIGPIPE, oldsigpipe); return ret; } ygl-4.2e/makeusleep.sed0000644000175000017500000000120707464476401014507 0ustar prabhuprabhu# # Ygl: Run 2d-GL programs with standard X11 routines. # (C) Fred Hucht 1993-2002 # EMail: fred@thp.Uni-Duisburg.DE # # $Id: makeusleep.sed,v 1.2 2002-04-02 15:10:10+02 fred Exp fred $ # /^[^#].*[ _]usleep *(/{ # Remove YGL_PREFIX if used s/ygl_usleep/usleep/ i\ #if 0 p i\ #endif h s/^\(.*\)[ ]usleep.*$/#define USLEEP_RET_TYPE \1/ s/extern// p /void/{ i\ #define USLEEP_RET_VAL } /void/!{ i\ #define USLEEP_RET_VAL 0 } g s/^.*usleep *( *\(unsigned\) \([^ )]*\).*$/#define USLEEP_ARG_TYPE \1 \2/p s/^.*usleep *( *\(signed\) \([^ )]*\).*$/#define USLEEP_ARG_TYPE \1 \2/p s/^.*usleep *( *\([^ )]*\).*$/#define USLEEP_ARG_TYPE \1/p } ygl-4.2e/FAQ.html0000444000175000017500000000566610200400112013127 0ustar prabhuprabhu Ygl Frequently Asked Questions

Ygl Frequently Asked Questions

©opyright 1993-2005 by Fred Hucht <fred(AT)thp.Uni-Duisburg.de>

Q 1:
We have an SGI Indigo on which we run a number of softwares that use GL and which are provided to us as binaries. Since we have an X terminal networked to this station we would be interested in using it to run these softwares. Do you think that Ygl could be used for such a purpose ?
A 1:
I don't think this is possible. Normally you must have the source of the GL application and relink it with libYgl.a instead of libgl.a. This relink will fail if the application uses routines that are not implemented in Ygl, ie. all 3D stuff, object stuff and so on. There is one known case where you don't need the sources:
You have shared libraries and both libgl.a and libYgl.a are shared libs (True under AIX3). Then you can make a directory eg. ~/lib and prepend ~/lib to the libpath. Under AIX3 this is done by setting the environment variable LIBPATH to "~/lib:/usr/lib", under Linux the variable is called LD_LIBRARY_PATH. Then move libYgl.a to ~/lib/libgl.a and try to run your application. If you get errors like "symbol xxx in yyy is undefined" the application requires routines that are not part of Ygl. If you are lucky the program runs.

Q 2:
I have installed Linux + XFree86 on a PC486. If i run programs on remote machines, everything goes all right as long as the program (run on SGI machines) does not use GL. Otherwise, an error message is displayed:
dlg error (protocol): remote machine not DGL capable - machinename:0
dgl error (default init): default dglopen(machinename:0,4) returned -13
Do you think that Ygl can do the trick and make my machine "DGL capable" ?
A 2:
No. You need distributed GL (DGL). DGL is an old extension to GL to make GL networkable. As far as I know, DGL only runs on SGIs (both client and server). There is only a small chance that you can solve your problem with Ygl (see A1).

Q 3:
When using Ygl together with C++ under HP-UX (i.e. with the compiler CC), the float versions of the drawing commands apparently don't do anything and functions like ortho2() keep complaining about zero height/width. What's wrong?
A 3:
Ygl is written (and thus compiled) in ANSI C. For a proper communication between C++ and ANSI C (especially float <-> double) you have to use the option +a1 (contributed by Lothar Brendel <l.brendel@uni-duisburg.de>)
ygl-4.2e/X11/0000755000175000017500000000000010621132320012202 5ustar prabhuprabhuygl-4.2e/X11/Ygl.h0000644000175000017500000006343510620054402013124 0ustar prabhuprabhu/* * Ygl: Run GL programs with standard X11 routines. * (C) Fred Hucht 1993-2006 * EMail: fred@thp.Uni-Duisburg.de * * $Id: Ygl.h,v 4.5 2005-02-08 17:01:45+01 fred Exp fred $ */ #ifndef _YGL_INCLUDED_ #define _YGL_INCLUDED_ #include #ifdef _AUX_SOURCE # include #endif #ifdef __cplusplus extern "C" { #endif #define BLACK 0 #define WHITE 1 #define GREEN 2 #define YELLOW 3 #define BLUE 4 #define MAGENTA 5 #define CYAN 6 #define RED 7 /* for queue */ #define NULLDEV 0 #define BREAKKEY 1 #define SETUPKEY 2 #define LEFTCTRLKEY 3 #define CAPSLOCKKEY 4 #define RIGHTSHIFTKEY 5 #define LEFTSHIFTKEY 6 #define ESCKEY 7 #define ONEKEY 8 #define TABKEY 9 #define QKEY 10 #define AKEY 11 #define SKEY 12 #define NOSCRLKEY 13 #define TWOKEY 14 #define THREEKEY 15 #define WKEY 16 #define EKEY 17 #define DKEY 18 #define FKEY 19 #define ZKEY 20 #define XKEY 21 #define FOURKEY 22 #define FIVEKEY 23 #define RKEY 24 #define TKEY 25 #define GKEY 26 #define HKEY 27 #define CKEY 28 #define VKEY 29 #define SIXKEY 30 #define SEVENKEY 31 #define YKEY 32 #define UKEY 33 #define JKEY 34 #define KKEY 35 #define BKEY 36 #define NKEY 37 #define EIGHTKEY 38 #define NINEKEY 39 #define IKEY 40 #define OKEY 41 #define LKEY 42 #define SEMICOLONKEY 43 #define MKEY 44 #define COMMAKEY 45 #define ZEROKEY 46 #define MINUSKEY 47 #define PKEY 48 #define LEFTBRACKETKEY 49 #define QUOTEKEY 50 #define RETKEY 51 #define PERIODKEY 52 #define VIRGULEKEY 53 #define EQUALKEY 54 #define ACCENTGRAVEKEY 55 #define RIGHTBRACKETKEY 56 #define BACKSLASHKEY 57 #define PAD1 58 #define PAD0 59 #define LINEFEEDKEY 60 #define BACKSPACEKEY 61 #define DELKEY 62 #define PAD4 63 #define PAD2 64 #define PAD3 65 #define PADPERIOD 66 #define PAD7 67 #define PAD8 68 #define PAD5 69 #define PAD6 70 #define PADPF2 71 #define PADPF1 72 #define LEFTARROWKEY 73 #define DOWNARROWKEY 74 #define PAD9 75 #define PADMINUS 76 #define PADCOMMA 77 #define PADPF4 78 #define PADPF3 79 #define RIGHTARROWKEY 80 #define UPARROWKEY 81 #define PADENTER 82 #define SPACEKEY 83 #define LEFTALTKEY 143 #define RIGHTALTKEY 144 #define RIGHTCTRLKEY 145 #define F1KEY 146 #define F2KEY 147 #define F3KEY 148 #define F4KEY 149 #define F5KEY 150 #define F6KEY 151 #define F7KEY 152 #define F8KEY 153 #define F9KEY 154 #define F10KEY 155 #define F11KEY 156 #define F12KEY 157 #define PRINTSCREENKEY 158 #define SCROLLLOCKKEY 159 #define PAUSEKEY 160 #define INSERTKEY 161 #define HOMEKEY 162 #define PAGEUPKEY 163 #define ENDKEY 164 #define PAGEDOWNKEY 165 #define NUMLOCKKEY 166 #define PADVIRGULEKEY 167 #define PADASTERKEY 168 #define PADPLUSKEY 169 #define MOUSE1 101 #define MOUSE2 102 #define MOUSE3 103 #define LEFTMOUSE 103 #define MIDDLEMOUSE 102 #define RIGHTMOUSE 101 #define MENUBUTTON 101 /* Wheel mouse (not in GL) */ #define WHEELUP 200 #define WHEELDOWN 201 #define MOUSEX 266 #define MOUSEY 267 #define ANYKEY 512 #define KEYBD 513 #define TIMER0 515 #define TIMER1 516 #define TIMER2 517 #define TIMER3 518 #define REDRAW 528 #define INPUTCHANGE 534 #define WINCLOSE 537 #define WINFREEZE 539 #define WINTHAW 540 #define WINQUIT 542 #define DEPTHCHANGE 543 #define MAXYGLDEVICE 544 /* for readsource(): */ #define SRC_AUTO 0 #define SRC_FRONT 1 #define SRC_BACK 2 /* for getdisplaymode(): */ #define DMRGB 0L #define DMSINGLE 1L #define DMDOUBLE 2L #define DMRGBDOUBLE 5L /* for getgdesc(): */ #define GD_XPMAX 1L #define GD_YPMAX 2L /* {XY}MAXSCREEN are dynamic */ #define XMAXSCREEN (getgdesc(GD_XPMAX) - 1) #define YMAXSCREEN (getgdesc(GD_YPMAX) - 1) /* for setpup() */ #define PUP_NONE 0 #define PUP_GREY 1 /* for logicop() */ #define LO_ZERO 0x0 #define LO_AND 0x1 #define LO_ANDR 0x2 #define LO_SRC 0x3 #define LO_ANDI 0x4 #define LO_DST 0x5 #define LO_XOR 0x6 #define LO_OR 0x7 #define LO_NOR 0x8 #define LO_XNOR 0x9 #define LO_NDST 0xa #define LO_ORR 0xb #define LO_NSRC 0xc #define LO_ORI 0xd #define LO_NAND 0xe #define LO_ONE 0xf #define LO_MIN 0x10 #define LO_MAX 0x11 #define LO_AVG 0x12 #define LO_DMS 0x13 #define LO_SMD 0x14 #define LO_SUM 0x15 /* for mmode() */ #define MSINGLE 0 #define MPROJECTION 1 #define MVIEWING 2 /* for blendfunction() */ #define BF_ZERO 0 #define BF_ONE 1 #define BF_SC 2 #define BF_MSC 3 #define BF_SA 4 #define BF_MSA 5 #define BF_DA 6 #define BF_MDA 7 #define BF_DC 8 #define BF_MDC 9 #define BF_MIN_SA_MDA 10 /* for zfunction() */ #define ZF_NEVER 0 #define ZF_LESS 1 #define ZF_EQUAL 2 #define ZF_LEQUAL 3 #define ZF_GREATER 4 #define ZF_NOTEQUAL 5 #define ZF_GEQUAL 6 #define ZF_ALWAYS 7 /* for lmdef(): MATERIAL properties */ #define DEFMATERIAL 0 #define EMISSION 1 #define AMBIENT 2 #define DIFFUSE 3 #define SPECULAR 4 #define SHININESS 5 #define COLORINDEXES 6 #define ALPHA 7 /* for lmdef(): LIGHT properties */ #define DEFLIGHT 100 #define LCOLOR 101 #define POSITION 102 #define SPOTDIRECTION 103 #define SPOTLIGHT 104 /* LIGHTINGMODEL properties */ #define DEFLMODEL 200 #define LOCALVIEWER 201 #define ATTENUATION 202 #define ATTENUATION2 203 /* used by SGI */ #define TWOSIDE 204 /* TARGET constants */ #define MATERIAL 1000 #define BACKMATERIAL 1001 #define LIGHT0 1100 #define LIGHT1 1101 #define LIGHT2 1102 #define LIGHT3 1103 #define LIGHT4 1104 #define LIGHT5 1105 #define LIGHT6 1106 #define LIGHT7 1107 #define LMODEL 1200 /* for lmcolor(): modes */ #define LMC_COLOR 0 #define LMC_EMISSION 1 #define LMC_AMBIENT 2 #define LMC_DIFFUSE 3 #define LMC_SPECULAR 4 #define LMC_AD 5 #define LMC_NULL 6 /* for lmdef(): constants */ #define LMNULL 0.0 /* for shademodel() */ #define FLAT 0 #define GOURAUD 1 /* Types */ #include typedef char Char8; typedef char Void; typedef Uint8 Byte; typedef Uint8 RGBvalue; typedef Uint16 Colorindex; typedef Uint16 Device; typedef Uint16 Linestyle; typedef Int16 Angle; typedef Int16 Scoord; typedef Int16 Screencoord; typedef Int32 Icoord; typedef Float32 Coord; typedef Float32 Matrix[4][4]; /********************* draw.c */ extern void clear ( void ); /* Points */ extern void pnt2 ( Coord, Coord ); extern void pnt2i ( Icoord, Icoord ); extern void pnt2s ( Scoord, Scoord ); /* Lines */ extern void move2 ( Coord, Coord ); extern void move2i ( Icoord, Icoord ); extern void move2s ( Scoord, Scoord ); extern void rmv2 ( Coord, Coord ); extern void rmv2i ( Icoord, Icoord ); extern void rmv2s ( Scoord, Scoord ); extern void draw2 ( Coord, Coord ); extern void draw2i ( Icoord, Icoord ); extern void draw2s ( Scoord, Scoord ); extern void rdr2 ( Coord, Coord ); extern void rdr2i ( Icoord, Icoord ); extern void rdr2s ( Scoord, Scoord ); /* Arcs & Circles */ extern void arc ( Coord, Coord, Coord, Angle, Angle ); extern void arci ( Icoord, Icoord, Icoord, Angle, Angle ); extern void arcs ( Scoord, Scoord, Scoord, Angle, Angle ); extern void arcf ( Coord, Coord, Coord, Angle, Angle ); extern void arcfi ( Icoord, Icoord, Icoord, Angle, Angle ); extern void arcfs ( Scoord, Scoord, Scoord, Angle, Angle ); extern void circ ( Coord, Coord, Coord ); extern void circi ( Icoord, Icoord, Icoord ); extern void circs ( Scoord, Scoord, Scoord ); extern void circf ( Coord, Coord, Coord ); extern void circfi ( Icoord, Icoord, Icoord ); extern void circfs ( Scoord, Scoord, Scoord ); /* Rects & Boxes */ extern void rect ( Coord, Coord, Coord, Coord ); extern void recti ( Icoord, Icoord, Icoord, Icoord ); extern void rects ( Scoord, Scoord, Scoord, Scoord ); extern void rectf ( Coord, Coord, Coord, Coord ); extern void rectfi ( Icoord, Icoord, Icoord, Icoord ); extern void rectfs ( Scoord, Scoord, Scoord, Scoord ); extern void sbox ( Coord, Coord, Coord, Coord ); extern void sboxi ( Icoord, Icoord, Icoord, Icoord ); extern void sboxs ( Scoord, Scoord, Scoord, Scoord ); extern void sboxf ( Coord, Coord, Coord, Coord ); extern void sboxfi ( Icoord, Icoord, Icoord, Icoord ); extern void sboxfs ( Scoord, Scoord, Scoord, Scoord ); /* Filled Polygons */ extern void concave ( Int32 ); extern void pmv2 ( Coord, Coord ); extern void pmv2i ( Icoord, Icoord ); extern void pmv2s ( Scoord, Scoord ); extern void rpmv2 ( Coord, Coord ); extern void rpmv2i ( Icoord, Icoord ); extern void rpmv2s ( Scoord, Scoord ); extern void pdr2 ( Coord, Coord ); extern void pdr2i ( Icoord, Icoord ); extern void pdr2s ( Scoord, Scoord ); extern void rpdr2 ( Coord, Coord ); extern void rpdr2i ( Icoord, Icoord ); extern void rpdr2s ( Scoord, Scoord ); extern void pclos ( void ); extern void poly2 ( Int32, Coord[][2] ); extern void poly2i ( Int32, Icoord[][2] ); extern void poly2s ( Int32, Scoord[][2] ); extern void polf2 ( Int32, Coord[][2] ); extern void polf2i ( Int32, Icoord[][2] ); extern void polf2s ( Int32, Scoord[][2] ); /* Vertex graphics */ extern void bgnpoint ( void ); extern void bgnline ( void ); extern void bgnclosedline ( void ); extern void bgnpolygon ( void ); extern void bgntmesh ( void ); extern void endpoint ( void ); extern void endline ( void ); extern void endclosedline ( void ); extern void endpolygon ( void ); extern void endtmesh ( void ); extern void v2s ( Int16[2] ); extern void v2i ( Int32[2] ); extern void v2f ( Float32[2] ); extern void v2d ( Float64[2] ); /* Text */ extern void cmov2 ( Coord, Coord ); extern void cmov2i ( Icoord, Icoord ); extern void cmov2s ( Scoord, Scoord ); extern void getcpos ( Screencoord *, Screencoord * ); /* Extensions: Routines not in gl by MiSt (michael@thp.Uni-Duisburg.de) */ #ifdef X11 extern void arcx ( Coord, Coord, Coord, Coord, Angle, Angle ); extern void arcxi ( Icoord, Icoord, Icoord, Icoord, Angle, Angle ); extern void arcxs ( Scoord, Scoord, Scoord, Scoord, Angle, Angle ); extern void arcxf ( Coord, Coord, Coord, Coord, Angle, Angle ); extern void arcxfi ( Icoord, Icoord, Icoord, Icoord, Angle, Angle ); extern void arcxfs ( Scoord, Scoord, Scoord, Scoord, Angle, Angle ); #endif /********************* queue.c */ extern void tie ( Device, Device, Device ); extern void noise ( Device, Int16 ); extern Int32 isqueued ( Int16 ); extern void qdevice ( Device ); extern void unqdevice ( Device ); extern void qreset ( void ); extern Int32 qtest ( void ); extern Int32 qread ( Int16 * ); extern void qenter ( Int16, Int16 ); extern void pick ( Int16 *, Int32 ); extern Int32 endpick ( Int16[] ); extern void picksize ( Int16, Int16 ); extern void initnames ( void ); extern void loadname ( Int16 ); extern void pushname ( Int16 ); extern void popname ( void ); /********************* misc.c */ extern void singlebuffer ( void ); extern void doublebuffer ( void ); extern void swapbuffers ( void ); extern void frontbuffer ( Int32 ); extern void backbuffer ( Int32 ); extern void gflush ( void ); extern void gsync ( void ); #ifdef _XLIB_H_ /* Declare if is included */ extern Display *getXdpy ( void ); extern Window getXwid ( void ); #ifdef X11 extern Window getXdid ( void ); extern GC getXgc ( void ); #endif #endif /* _XLIB_H_ */ extern void wintitle ( Char8 * ); extern void winset ( Int32 ); extern Int32 winget ( void ); extern Int32 getplanes ( void ); extern Int32 getvaluator ( Device ); extern Int32 getbutton ( Device ); extern Int32 gversion ( Char8[12] ); extern void ortho2 ( Coord, Coord, Coord, Coord ); extern void viewport ( Screencoord, Screencoord, Screencoord, Screencoord ); extern void getviewport ( Screencoord *, Screencoord *, Screencoord *, Screencoord * ); extern void reshapeviewport ( void ); extern void pushviewport ( void ); extern void popviewport ( void ); extern void winpop ( void ); extern void winpush ( void ); extern Int32 windepth ( Int32 ); extern void linewidth ( Int16 ); extern Int32 getlwidth ( void ); extern void deflinestyle ( Int32, Linestyle ); extern void setlinestyle ( Int32 ); extern Int32 getlstyle ( void ); extern void lsrepeat ( Int32 ); extern Int32 getlsrepeat ( void ); extern Int32 getdisplaymode ( void ); extern void setbell ( Char8 ); extern void ringbell ( void ); extern Int32 getgdesc ( Int32 ); extern void foreground ( void ); extern void logicop ( Int32 ); extern void getmatrix ( Matrix ); /********************* font.c */ extern void loadXfont ( Int32 , Char8 * ); extern void font ( Int16 ); extern Int32 getfont ( void ); extern void getfontencoding ( Char8 * ); extern Int32 getheight ( void ); extern Int32 getdescender ( void ); extern Int32 strwidth ( Char8 * ); extern void charstr ( Char8 * ); /********************* color.c */ extern void mapcolor ( Colorindex, Int16, Int16, Int16 ); extern void RGBcolor ( Int16, Int16, Int16 ); extern void cpack ( Uint32 ); extern void c3s ( Int16[3] ); extern void c3i ( Int32[3] ); extern void c3f ( Float32[3] ); extern Int32 getcolor ( void ); extern void getmcolor ( Colorindex, Int16 *, Int16 *, Int16 * ); extern void getmcolors ( Colorindex, Colorindex, Int16 *, Int16 *, Int16 * ); extern void gRGBcolor ( Int16 *, Int16 *, Int16 * ); extern void color ( Colorindex ); extern void readsource ( Int32 ); extern void rectzoom ( Float32, Float32 ); extern Int32 crectread ( Screencoord, Screencoord, Screencoord, Screencoord, Uint8 * ); extern Int32 rectread ( Screencoord, Screencoord, Screencoord, Screencoord, Int16 * ); extern Int32 lrectread ( Screencoord, Screencoord, Screencoord, Screencoord, Int32 * ); extern void crectwrite ( Screencoord, Screencoord, Screencoord, Screencoord, Uint8 * ); extern void rectwrite ( Screencoord, Screencoord, Screencoord, Screencoord, Int16 * ); extern void lrectwrite ( Screencoord, Screencoord, Screencoord, Screencoord, Int32 * ); extern void rectcopy ( Screencoord, Screencoord, Screencoord, Screencoord, Screencoord, Screencoord ); extern Int32 readpixels ( Int16, Colorindex[] ); extern void writepixels ( Int16, Colorindex[] ); extern Int32 readRGB ( Int16, RGBvalue[], RGBvalue[], RGBvalue[] ); extern void writeRGB ( Int16, RGBvalue[], RGBvalue[], RGBvalue[] ); /* for/from Bill Bishop */ extern void blendfunction ( Int32, Int32 ); /********************* menu.c */ extern void addtopup ( Int32, Char8 *, ... ); extern Int32 defpup ( Char8 *, ... ); extern Int32 dopup ( Int32 ); extern void freepup ( Int32 ); extern Int32 newpup ( void ); extern void setpup ( Int32, Int32, Int32 ); /********************* ygl.c */ /* Contraints */ extern void minsize ( Int32, Int32 ); extern void maxsize ( Int32, Int32 ); extern void prefsize ( Int32, Int32 ); extern void prefposition ( Int32, Int32, Int32, Int32 ); extern void stepunit ( Int32, Int32 ); extern void keepaspect ( Int32, Int32 ); extern void noport ( void ); extern void noborder ( void ); extern void ginit ( void ); extern void winconstraints ( void ); extern Int32 winopen ( Char8 * ); extern Int32 swinopen ( Int32 ); extern void winposition ( Int32, Int32, Int32, Int32 ); extern void winmove ( Int32, Int32 ); extern void getsize ( Int32 *, Int32 * ); extern void getorigin ( Int32 *, Int32 * ); extern void RGBmode ( void ); extern void cmode ( void ); extern void gconfig ( void ); extern void winclose ( Int32 ); extern void gexit ( void ); #ifdef _XLIB_H_ /* Declare if is included */ extern Int32 winX ( Display *, Window ); #endif /* _XLIB_H_ */ /* gl2ppm.c */ extern int gl2ppm ( const char * ); /* 3d.c */ extern void cmov ( Coord, Coord, Coord ); extern void cmovi ( Icoord, Icoord, Icoord ); extern void cmovs ( Scoord, Scoord, Scoord ); extern void pnt ( Coord, Coord, Coord ); extern void pnti ( Icoord, Icoord, Icoord ); extern void pnts ( Scoord, Scoord, Scoord ); extern void move ( Coord, Coord, Coord ); extern void movei ( Icoord, Icoord, Icoord ); extern void moves ( Scoord, Scoord, Scoord ); extern void rmv ( Coord, Coord, Coord ); extern void rmvi ( Icoord, Icoord, Icoord ); extern void rmvs ( Scoord, Scoord, Scoord ); extern void draw ( Coord, Coord, Coord ); extern void drawi ( Icoord, Icoord, Icoord ); extern void draws ( Scoord, Scoord, Scoord ); extern void rdr ( Coord, Coord, Coord ); extern void rdri ( Icoord, Icoord, Icoord ); extern void rdrs ( Scoord, Scoord, Scoord ); extern void pmv ( Coord, Coord, Coord ); extern void pmvi ( Icoord, Icoord, Icoord ); extern void pmvs ( Scoord, Scoord, Scoord ); extern void rpmv ( Coord, Coord, Coord ); extern void rpmvi ( Icoord, Icoord, Icoord ); extern void rpmvs ( Scoord, Scoord, Scoord ); extern void pdr ( Coord, Coord, Coord ); extern void pdri ( Icoord, Icoord, Icoord ); extern void pdrs ( Scoord, Scoord, Scoord ); extern void rpdr ( Coord, Coord, Coord ); extern void rpdri ( Icoord, Icoord, Icoord ); extern void rpdrs ( Scoord, Scoord, Scoord ); extern void polf ( Int32, Coord[][3] ); extern void polfi ( Int32, Icoord[][3] ); extern void polfs ( Int32, Scoord[][3] ); extern void v3s ( Int16[3] ); extern void v3i ( Int32[3] ); extern void v3f ( Float32[3] ); extern void v3d ( Float64[3] ); extern void v4s ( Int16[4] ); extern void v4i ( Int32[4] ); extern void v4f ( Float32[4] ); extern void v4d ( Float64[4] ); extern void swaptmesh ( void ); extern void ortho ( Coord, Coord, Coord, Coord, Coord, Coord ); extern void lookat ( Coord, Coord, Coord, Coord, Coord, Coord, Angle ); extern void window ( Coord, Coord, Coord, Coord, Coord, Coord ); extern void perspective ( Angle, Float32, Coord, Coord ); extern void polarview ( Coord, Angle, Angle, Angle ); extern void rot ( Float32, char ); extern void rotate ( Angle, char ); extern void scale ( Float32, Float32, Float32 ); extern void translate ( Coord, Coord, Coord ); extern void loadmatrix ( Matrix ); extern void multmatrix ( Matrix ); extern void pushmatrix ( void ); extern void popmatrix ( void ); extern void shademodel ( Int32 ); extern void c4f ( Float32[4] ); extern void c4i ( Int32[4] ); extern void c4s ( Int16[4] ); extern void n3f ( Float32[3] ); extern void normal ( Coord[3] ); extern void backface ( Int32 ); extern void frontface ( Int32 ); extern Int32 getmmode ( void ); extern void mmode ( Int16 ); extern void zbuffer ( Int32 ); extern void zclear ( void ); extern void zdraw ( Int32 ); extern void zfunction ( Int32 ); extern void czclear ( Int32, Int32 ); extern void depthcue ( Int32 ); extern void lRGBrange ( Int16, Int16, Int16, Int16, Int16, Int16, Int32, Int32 ); extern void lsetdepth ( Int32, Int32 ); extern void lshaderange ( Colorindex, Colorindex, Int32, Int32 ); /* Display lists */ extern Int32 genobj ( void ); extern Int32 isobj ( Int32 ); extern void makeobj ( Int32 ); extern Int32 getopenobj ( void ); extern void closeobj ( void ); extern void callobj ( Int32 ); extern void delobj ( Int32 ); /* Lighting */ extern void lmbind ( Int32, Int32 ); extern void lmcolor ( Int32 ); extern void lmdef ( Int16, Int16, Int16, Float32[] ); extern void RGBwritemask ( Int16, Int16, Int16 ); /* for Pete Riley */ extern void drawmode ( Int32 ); extern void iconsize ( Int32, Int32 ); extern void overlay ( Int32 ); extern void pushattributes ( void ); extern void popattributes ( void ); extern void fullscrn ( void ); extern void endfullscrn ( void ); extern void scrmask ( Screencoord , Screencoord , Screencoord , Screencoord ); /* not implemented (yet) */ #if 0 extern void attachcursor ( Device, Device ); extern void bbox2 ( Screencoord, Screencoord, Coord, Coord, Coord, Coord ); extern void bbox2i ( Screencoord, Screencoord, Icoord, Icoord, Icoord, Icoord ); extern void bbox2s ( Screencoord, Screencoord, Scoord, Scoord, Scoord, Scoord ); extern void bgnsurface ( void ); extern void bgntrim ( void ); extern void blankscreen ( Int32 ); extern void blanktime ( Int32 ); extern void blink ( Int16, Colorindex, Int16, Int16, Int16 ); extern Int32 blkqread ( Int16 *, Int16 ); extern void chunksize ( Int32 ); extern void clkoff ( void ); extern void clkon ( void ); extern void colorf ( Float32 ); extern void compactify ( Int32 ); extern void crv ( Coord[4][3] ); extern void crvn ( Int32, Coord[][3] ); extern void curorigin ( Int16, Int16, Int16 ); extern void cursoff ( void ); extern void curson ( void ); extern void curstype ( Int32 ); extern void curvebasis ( Int16 ); extern void curveit ( Int16 ); extern void curveprecision ( Int16 ); extern void cyclemap ( Int16, Int16, Int16 ); extern void defbasis ( Int32, Matrix ); extern void defcursor ( Int16, Uint16 * ); extern void defpattern ( Int16, Int16, Int16 * ); /*extern void defrasterfont ( Int16, Int16, Int16, Fontchar[], Int16, Int16[] );*/ extern void deltag ( Int32 ); extern void editobj ( Int32 ); extern Int32 endselect ( Int16[] ); extern void endsurface ( void ); extern void endtrim ( void ); extern void finish ( void ); extern void fudge ( Int32, Int32 ); extern void gRGBmask ( Int16 *, Int16 *, Int16 * ); extern void gammaramp ( Int16[256], Int16[256], Int16[256] ); extern void gbegin ( void ); extern Int32 gentag ( void ); extern Int32 getbackface ( void ); extern Int32 getbuffer ( void ); extern Int32 getcmmode ( void ); extern void getcursor ( Int16 *, Colorindex *, Colorindex *, Int32 * ); extern Int32 getdcm ( void ); extern void getdev ( Int32, Device[], short[] ); extern Int32 getdrawmode ( void ); extern void getgpos ( Coord *, Coord *, Coord *, Coord * ); extern Int32 getmap ( void ); extern void getnurbsproperty (Int32, Float32 *); extern Int32 getpattern ( void ); extern void getscrmask ( Screencoord *, Screencoord *, Screencoord *, Screencoord * ); extern Int32 getshade ( void ); extern Int32 getsm ( void ); extern Int32 getwritemask ( void ); extern Int32 getzbuffer ( void ); extern void greset ( void ); extern void gselect ( Int16 *, Int32 ); extern void icontitle ( char * ); extern void imakebackground ( void ); extern Int32 istag ( Int32 ); extern void lampoff ( char ); extern void lampon ( char ); extern void lgetdepth ( Int32 *, Int32 * ); extern void linesmooth ( Int32 ); extern void maketag ( Int32 ); extern void mapcolors ( Colorindex, Colorindex, Int16 *, Int16 *, Int16 *); extern void mapw ( Int32, Screencoord, Screencoord, Coord *, Coord *, Coord *, Coord *, Coord *, Coord * ); extern void mapw2 ( Int32, Screencoord, Screencoord, Coord *, Coord * ); extern void multimap ( void ); /*extern void newtag ( Int32, Int32, Offset );*/ extern void nurbscurve (Int32, Float64 *,Int32, Float64 *, Int32, Int32); extern void nurbssurface (Int32, Float64 *,Int32, Float64 *, Int32, Int32, Float64 *, Int32, Int32, Int32); extern void objdelete ( Int32, Int32 ); extern void objinsert ( Int32 ); extern void objreplace ( Int32 ); extern void onemap ( void ); extern void patch ( Matrix, Matrix, Matrix ); extern void patchbasis ( Int32, Int32 ); extern void patchcurves ( Int32, Int32 ); extern void patchprecision ( Int32, Int32 ); extern void pixmode (Int32,Int32); extern void pntsmooth ( Int32 ); extern void poly ( Int32, Coord[][3] ); extern void polyi ( Int32, Icoord[][3] ); extern void polys ( Int32, Scoord[][3] ); extern void polygonlist ( Int32, Int32, void * ); extern void polylinelist ( Int32, Int32, void * ); extern void pwlcurve (Int32, Float64 *,Int32, Int32); extern void rcrv ( Coord[4][4] ); extern void rcrvn ( Int32, Coord[4][4] ); extern void rpatch ( Matrix, Matrix, Matrix, Matrix ); extern void screenspace ( void ); extern void set_dither ( Int32 ); extern void setcursor ( Int16, Colorindex, Colorindex ); extern void setdblights ( Int32 ); extern void setmap ( Int16 ); extern void setnurbsproperty (Int32, Float32); extern void setpattern ( Int16 ); extern void setvaluator ( Device, Int16, Int16, Int16 ); extern void splf ( Int32, Coord[][3], Colorindex[] ); extern void splf2 ( Int32, Coord[][2], Colorindex[] ); extern void splf2i ( Int32, Icoord[][2], Colorindex[] ); extern void splf2s ( Int32, Scoord[][2], Colorindex[] ); extern void splfi ( Int32, Icoord[][3], Colorindex[] ); extern void splfs ( Int32, Scoord[][3], Colorindex[] ); extern void subpixel ( Int32 ); extern void swapinterval ( Int16 ); extern void textport ( Screencoord, Screencoord, Screencoord, Screencoord ); extern void tpoff ( void ); extern void tpon ( void ); extern void underlay ( Int32 ); extern void wmpack ( Uint32 ); extern void writemask ( Colorindex ); extern void zsource ( Int32 ); extern void zwritemask ( Int32 ); #endif #ifdef __cplusplus } #endif #endif /* _YGL_INCLUDED_ */ ygl-4.2e/X11/Yfgl.h0000644000175000017500000003712710374400744013303 0ustar prabhuprabhuC -*- fortran -*- C C Ygl: Run GL programs with standard X11 and/or OpenGL routines. C (C) Fred Hucht 1993-2006 C EMail: fredthp.Uni-Duisburg.de C C $Id: Yfgl.h,v 4.3 2005-02-08 16:31:04+01 fred Exp fred $ C FORTRAN includes for every routine C #ifndef _YFGL_INCLUDED_ C #define _YFGL_INCLUDED_ C The colors integer*4 BLACK parameter( BLACK = 0 ) integer*4 WHITE parameter( WHITE = 1 ) integer*4 GREEN parameter( GREEN = 2 ) integer*4 YELLOW parameter( YELLOW = 3 ) integer*4 BLUE parameter( BLUE = 4 ) integer*4 MAGENT parameter( MAGENT = 5 ) integer*4 CYAN parameter( CYAN = 6 ) integer*4 RED parameter( RED = 7 ) C The Keys integer*4 BREAKK parameter( BREAKK = 1 ) integer*4 SETUPK parameter( SETUPK = 2 ) integer*4 LEFTCT parameter( LEFTCT = 3 ) integer*4 CAPSLO parameter( CAPSLO = 4 ) integer*4 RIGHTS parameter( RIGHTS = 5 ) integer*4 LEFTSH parameter( LEFTSH = 6 ) integer*4 ESCKEY parameter( ESCKEY = 7 ) integer*4 ONEKEY parameter( ONEKEY = 8 ) integer*4 TABKEY parameter( TABKEY = 9 ) integer*4 QKEY parameter( QKEY = 10 ) integer*4 AKEY parameter( AKEY = 11 ) integer*4 SKEY parameter( SKEY = 12 ) integer*4 NOSCRL parameter( NOSCRL = 13 ) integer*4 TWOKEY parameter( TWOKEY = 14 ) integer*4 THREEK parameter( THREEK = 15 ) integer*4 WKEY parameter( WKEY = 16 ) integer*4 EKEY parameter( EKEY = 17 ) integer*4 DKEY parameter( DKEY = 18 ) integer*4 FKEY parameter( FKEY = 19 ) integer*4 ZKEY parameter( ZKEY = 20 ) integer*4 XKEY parameter( XKEY = 21 ) integer*4 FOURKE parameter( FOURKE = 22 ) integer*4 FIVEKE parameter( FIVEKE = 23 ) integer*4 RKEY parameter( RKEY = 24 ) integer*4 TKEY parameter( TKEY = 25 ) integer*4 GKEY parameter( GKEY = 26 ) integer*4 HKEY parameter( HKEY = 27 ) integer*4 CKEY parameter( CKEY = 28 ) integer*4 VKEY parameter( VKEY = 29 ) integer*4 SIXKEY parameter( SIXKEY = 30 ) integer*4 SEVENK parameter( SEVENK = 31 ) integer*4 YKEY parameter( YKEY = 32 ) integer*4 UKEY parameter( UKEY = 33 ) integer*4 JKEY parameter( JKEY = 34 ) integer*4 KKEY parameter( KKEY = 35 ) integer*4 BKEY parameter( BKEY = 36 ) integer*4 NKEY parameter( NKEY = 37 ) integer*4 EIGHTK parameter( EIGHTK = 38 ) integer*4 NINEKE parameter( NINEKE = 39 ) integer*4 IKEY parameter( IKEY = 40 ) integer*4 OKEY parameter( OKEY = 41 ) integer*4 LKEY parameter( LKEY = 42 ) integer*4 SEMICO parameter( SEMICO = 43 ) integer*4 MKEY parameter( MKEY = 44 ) integer*4 COMMAK parameter( COMMAK = 45 ) integer*4 ZEROKE parameter( ZEROKE = 46 ) integer*4 MINUSK parameter( MINUSK = 47 ) integer*4 PKEY parameter( PKEY = 48 ) integer*4 LEFTBR parameter( LEFTBR = 49 ) integer*4 QUOTEK parameter( QUOTEK = 50 ) integer*4 RETKEY parameter( RETKEY = 51 ) integer*4 PERIOD parameter( PERIOD = 52 ) integer*4 VIRGUL parameter( VIRGUL = 53 ) integer*4 EQUALK parameter( EQUALK = 54 ) integer*4 ACCENT parameter( ACCENT = 55 ) integer*4 RIGHTB parameter( RIGHTB = 56 ) integer*4 BACKSL parameter( BACKSL = 57 ) integer*4 PAD1 parameter( PAD1 = 58 ) integer*4 PAD0 parameter( PAD0 = 59 ) integer*4 LINEFE parameter( LINEFE = 60 ) integer*4 BACKSP parameter( BACKSP = 61 ) integer*4 DELKEY parameter( DELKEY = 62 ) integer*4 PAD4 parameter( PAD4 = 63 ) integer*4 PAD2 parameter( PAD2 = 64 ) integer*4 PAD3 parameter( PAD3 = 65 ) integer*4 PADPER parameter( PADPER = 66 ) integer*4 PAD7 parameter( PAD7 = 67 ) integer*4 PAD8 parameter( PAD8 = 68 ) integer*4 PAD5 parameter( PAD5 = 69 ) integer*4 PAD6 parameter( PAD6 = 70 ) integer*4 PADPF2 parameter( PADPF2 = 71 ) integer*4 PADPF1 parameter( PADPF1 = 72 ) integer*4 LEFTAR parameter( LEFTAR = 73 ) integer*4 DOWNAR parameter( DOWNAR = 74 ) integer*4 PAD9 parameter( PAD9 = 75 ) integer*4 PADMIN parameter( PADMIN = 76 ) integer*4 PADCOM parameter( PADCOM = 77 ) integer*4 PADPF4 parameter( PADPF4 = 78 ) integer*4 PADPF3 parameter( PADPF3 = 79 ) integer*4 RIGHTA parameter( RIGHTA = 80 ) integer*4 UPARRO parameter( UPARRO = 81 ) integer*4 PADENT parameter( PADENT = 82 ) integer*4 SPACEK parameter( SPACEK = 83 ) integer*4 LEFTAL parameter( LEFTAL = 143 ) integer*4 RGHTAL parameter( RGHTAL = 144 ) integer*4 RIGHTC parameter( RIGHTC = 145 ) integer*4 F1KEY parameter( F1KEY = 146 ) integer*4 F2KEY parameter( F2KEY = 147 ) integer*4 F3KEY parameter( F3KEY = 148 ) integer*4 F4KEY parameter( F4KEY = 149 ) integer*4 F5KEY parameter( F5KEY = 150 ) integer*4 F6KEY parameter( F6KEY = 151 ) integer*4 F7KEY parameter( F7KEY = 152 ) integer*4 F8KEY parameter( F8KEY = 153 ) integer*4 F9KEY parameter( F9KEY = 154 ) integer*4 F10KEY parameter( F10KEY = 155 ) integer*4 F11KEY parameter( F11KEY = 156 ) integer*4 F12KEY parameter( F12KEY = 157 ) integer*4 PRINTS parameter( PRINTS = 158 ) integer*4 SCROLL parameter( SCROLL = 159 ) integer*4 PAUSEK parameter( PAUSEK = 160 ) integer*4 INSERT parameter( INSERT = 161 ) integer*4 HOMEKE parameter( HOMEKE = 162 ) integer*4 PAGEUP parameter( PAGEUP = 163 ) integer*4 ENDKEY parameter( ENDKEY = 164 ) integer*4 PAGEDO parameter( PAGEDO = 165 ) integer*4 NUMLOC parameter( NUMLOC = 166 ) integer*4 PADVIR parameter( PADVIR = 167 ) integer*4 PADAST parameter( PADAST = 168 ) integer*4 PADPLU parameter( PADPLU = 169 ) C The Mouse stuff integer*4 MOUSE1 parameter( MOUSE1 = 101 ) integer*4 MOUSE2 parameter( MOUSE2 = 102 ) integer*4 MOUSE3 parameter( MOUSE3 = 103 ) integer*4 LEFTMO parameter( LEFTMO = 103 ) integer*4 MIDDLE parameter( MIDDLE = 102 ) integer*4 RIGHTM parameter( RIGHTM = 101 ) integer*4 MENUBU parameter( MENUBU = 101 ) integer*4 WHEELU parameter( WHEELU = 200 ) integer*4 WHEELD parameter( WHEELD = 201 ) integer*4 MOUSEX parameter( MOUSEX = 266 ) integer*4 MOUSEY parameter( MOUSEY = 267 ) C Other Devices integer*4 KEYBD parameter( KEYBD = 513 ) integer*4 REDRAW parameter( REDRAW = 528 ) integer*4 INPUTC parameter( INPUTC = 534 ) C Device WINCLO conflict with routine winclo() integer*4 WINCLOSE parameter( WINCLOSE = 537 ) integer*4 WINFRE parameter( WINFRE = 539 ) integer*4 WINTHA parameter( WINTHA = 540 ) integer*4 WINQUI parameter( WINQUI = 542 ) integer*4 DEPTHC parameter( DEPTHC = 543 ) integer*4 SRCAUT parameter( SRCAUT = 0 ) integer*4 SRCFRO parameter( SRCFRO = 1 ) integer*4 SRCBAC parameter( SRCBAC = 2 ) integer*4 DMRGB parameter( DMRGB = 0 ) integer*4 DMSING parameter( DMSING = 1 ) integer*4 DMDOUB parameter( DMDOUB = 2 ) integer*4 DMRGBD parameter( DMRGBD = 5 ) integer*4 GDXPMA parameter( GDXPMA = 1 ) integer*4 GDYPMA parameter( GDYPMA = 2 ) integer*4 PUPNON parameter( PUPNON = 0 ) integer*4 PUPGRE parameter( PUPGRE = 1 ) integer*4 XMAXSC parameter( XMAXSC = 1279 ) integer*4 YMAXSC parameter( YMAXSC = 1023 ) C The logicops integer*4 LOZERO parameter( LOZERO = 0 ) integer*4 LOAND parameter( LOAND = 1 ) integer*4 LOANDR parameter( LOANDR = 2 ) integer*4 LOSRC parameter( LOSRC = 3 ) integer*4 LOANDI parameter( LOANDI = 4 ) integer*4 LODST parameter( LODST = 5 ) integer*4 LOXOR parameter( LOXOR = 6 ) integer*4 LOOR parameter( LOOR = 7 ) integer*4 LONOR parameter( LONOR = 8 ) integer*4 LOXNOR parameter( LOXNOR = 9 ) integer*4 LONDST parameter( LONDST = 10 ) integer*4 LOORR parameter( LOORR = 11 ) integer*4 LONSRC parameter( LONSRC = 12 ) integer*4 LOORI parameter( LOORI = 13 ) integer*4 LONAND parameter( LONAND = 14 ) integer*4 LOONE parameter( LOONE = 15 ) integer*4 LOMIN parameter( LOMIN = 16 ) integer*4 LOMAX parameter( LOMAX = 17 ) integer*4 LOAVG parameter( LOAVG = 18 ) integer*4 LODMS parameter( LODMS = 19 ) integer*4 LOSMD parameter( LOSMD = 20 ) integer*4 LOSUM parameter( LOSUM = 21 ) C The matrix modes integer*4 MSINGL parameter ( MSINGL = 0 ) integer*4 MPROJE parameter ( MPROJE = 1 ) integer*4 MVIEWI parameter ( MVIEWI = 2 ) C The blend functions integer*4 BFZERO parameter ( BFZERO = 0 ) integer*4 BFON parameter ( BFONE = 1 ) integer*4 BFDC parameter ( BFDC = 2 ) integer*4 BFSC parameter ( BFSC = 2 ) integer*4 BFMDC parameter ( BFMDC = 3 ) integer*4 BFMSC parameter ( BFMSC = 3 ) integer*4 BFSA parameter ( BFSA = 4 ) integer*4 BFMSA parameter ( BFMSA = 5 ) integer*4 BFDA parameter ( BFDA = 6 ) integer*4 BFMDA parameter ( BFMDA = 7 ) C The z functions integer*4 ZFNEVE parameter ( ZFNEVE = 0 ) integer*4 ZFLESS parameter ( ZFLESS = 1 ) integer*4 ZFEQUA parameter ( ZFEQUA = 2 ) integer*4 ZFLEQU parameter ( ZFLEQU = 3 ) integer*4 ZFGREA parameter ( ZFGREA = 4 ) integer*4 ZFNOTE parameter ( ZFNOTE = 5 ) integer*4 ZFGEQU parameter ( ZFGEQU = 6 ) integer*4 ZFALWA parameter ( ZFALWA = 7 ) C The lighting stuff real*4 LMNULL parameter ( LMNULL = 0.0 ) integer*4 MAXLIG parameter ( MAXLIG = 8 ) integer*4 MAXRES parameter ( MAXRES = 4 ) integer*4 DEFMAT parameter ( DEFMAT = 0 ) integer*4 EMISSI parameter ( EMISSI = 1 ) integer*4 AMBIEN parameter ( AMBIEN = 2 ) integer*4 DIFFUS parameter ( DIFFUS = 3 ) integer*4 SPECUL parameter ( SPECUL = 4 ) integer*4 SHININ parameter ( SHININ = 5 ) integer*4 COLORI parameter ( COLORI = 6 ) integer*4 ALPHA parameter ( ALPHA = 7 ) integer*4 DEFLIG parameter ( DEFLIG = 100 ) integer*4 LCOLOR parameter ( LCOLOR = 101 ) integer*4 POSITI parameter ( POSITI = 102 ) integer*4 SPOTDI parameter ( SPOTDI = 103 ) integer*4 SPOTLI parameter ( SPOTLI = 104 ) integer*4 DEFLMO parameter ( DEFLMO = 200 ) integer*4 LOCALV parameter ( LOCALV = 201 ) integer*4 ATTENU parameter ( ATTENU = 202 ) integer*4 ATTEN2 parameter ( ATTEN2 = 203 ) integer*4 TWOSID parameter ( TWOSID = 204 ) integer*4 MATERI parameter ( MATERI = 1000 ) integer*4 LIGHT0 parameter ( LIGHT0 = 1100 ) integer*4 LIGHT1 parameter ( LIGHT1 = 1101 ) integer*4 LIGHT2 parameter ( LIGHT2 = 1102 ) integer*4 LIGHT3 parameter ( LIGHT3 = 1103 ) integer*4 LIGHT4 parameter ( LIGHT4 = 1104 ) integer*4 LIGHT5 parameter ( LIGHT5 = 1105 ) integer*4 LIGHT6 parameter ( LIGHT6 = 1106 ) integer*4 LIGHT7 parameter ( LIGHT7 = 1107 ) integer*4 LMODEL parameter ( LMODEL = 1200 ) integer*4 LMCCOL parameter ( LMCCOL = 0 ) integer*4 LMCEMI parameter ( LMCEMI = 1 ) integer*4 LMCAMB parameter ( LMCAMB = 2 ) integer*4 LMCDIF parameter ( LMCDIF = 3 ) integer*4 LMCSPE parameter ( LMCSPE = 4 ) integer*4 LMCAD parameter ( LMCAD = 5 ) integer*4 LMCNUL parameter ( LMCNUL = 6 ) C The routines integer*4 isqueu external isqueu integer*4 qtest external qtest integer*4 qread external qread C getXdpy and getXwid are >6 chars long integer*4 getxdpy external getxdpy integer*4 getxwid external getxwid integer*4 getxdid external getxdid integer*4 getxgc external getxgc integer*4 winget external winget integer*4 getpla external getpla integer*4 getval external getval integer*4 getbut external getbut integer*4 gversi external gversi integer*4 windep external windep integer*4 getlwi external getlwi integer*4 getlst external getlst integer*4 getlsr external getlsr integer*4 getdis external getdis integer*4 getgde external getgde integer*4 getfon external getfon integer*4 gethei external gethei integer*4 getdes external getdes integer*4 strwid external strwid integer*4 getcol external getcol integer*4 crectr external crectr integer*4 rectre external rectre integer*4 lrectr external lrectr integer*4 readpi external readpi integer*4 readrg external readrg integer*4 dopup external dopup integer*4 newpup external newpup integer*4 winope external winope integer*4 swinop external swinop integer*4 winx external winx integer*4 gl2ppm external gl2ppm integer*4 getmmo external getmmo integer*4 genobj external genobj integer*4 isobj external isobj integer*4 getope external getope integer*4 endpic external endpic C C Not implemented (yet) C C integer*4 blkqre C external blkqre C integer*4 endsel C external endsel C integer*4 gentag C external gentag C integer*4 getbac C external getbac C integer*4 getbuf C external getbuf C integer*4 getcmm C external getcmm C integer*4 getdcm C external getdcm C integer*4 getdra C external getdra C integer*4 getmap C external getmap C integer*4 getpat C external getpat C integer*4 getsha C external getsha C integer*4 getsm C external getsm C integer*4 getwri C external getwri C integer*4 getzbu C external getzbu C integer*4 istag C external istag C #endif /* _YFGL_INCLUDED_ */ ygl-4.2e/Smile.gif0000644000175000017500000000074306253515704013416 0ustar prabhuprabhuGIF87add¡þþþþ,ddþ„©Ëí£œ´Ú‹³Þ¼û†âH–扦êʶî‹ðlöç6]êþãu€Ä¢Lh1*‰HÉòÉl2 Ô¨ôPÍþ®­×'ýŠu±98;«w¯µÛ厳âtýŽºãOú=©¯÷(2X°Th¨ÐèèX²XôX 2IdÉÙˆé¡ùÓÙùÉ*Z‰ÀYªqªc©° fꊓº`¹µQ›óèPÉzÁkëøûœäã …˜uˬ›Ô¼´ì\Ü=‹±Ymt}苻͌úžÎü| +}®|¬¾þÄ©ún^A9šÝ_N~/})8ÏJ Ygl Version 4.2 Changes History

Logo Ygl Version 4.2 Changes History

©opyright 1993-2007 by Fred Hucht (fred(AT)thp.Uni-Duisburg.de)

Changes from Version 4.2d -> 4.2e:

(V 4.2e released 11. May 2007)
  • Fixed broken irisgl/fdevice.h, updated examples/smile_{f77|xlf}.f
  • Removed obsolete library glwidget. This library can be found here.

Changes from Version 4.2c -> 4.2d:

(V 4.2d released 7. May 2007)
  • Renamed directory gl to irisgl due to incompatibilities with case insensitive filesystems

Changes from Version 4.1f -> 4.2c:

(V 4.2c released 1. May 2007)
  • Added picking & naming stuff
  • Added blendfunction()
  • Many fixes, especially in colormap mode under OpenGL bindings

Changes from Version 4.1e -> 4.1f:

(V 4.1f released 8. Feb 2005)
  • Added gsync() (only works with OpenGL bindings).
  • Added {XY}MAXSCREEN macro
  • Removed poly*() from Ygl.h, as they are not implemented yet.

Changes from Version 4.1b -> 4.1e:

(V 4.1e released 3. Feb 2005)
  • 3D support is on now by default, as OpenGL is assumed to be installed. If not, please set UseOpenGL 0 in Imakefile.
  • Updated the ReadMe file to include the 3D routines.
  • Several minor bug fixes which were reported over the years...

Changes from Version 4.0x -> 4.1b:

(V 4.1b released 2. May 2002)
  • Workaround to let OpenGL bindings work both on X servers with PseudoColor/TrueColor (e.g. AIX) and on X servers with only TrueColor visuals (e.g. XFree).
  • Added method to dynamically determine the declaration of usleep(). Hope this works in all cases...
  • Added missing FORTRAN bindings for new 3D routines.
  • Fixed many bugs...

Changes from Version 3.2 -> 4.0x:

(V 4.0 not released yet)
  • Added 3D using OpenGL. Note that one must compile Ygl with OpenGL support (see Imakefile) and set the environment variable YGL_OGL to 1 to use these bindings.
  • rectf's are now the same size as rect's. rectf's were 1 Pixel larger in both directions, as GL also had this feature on most cards.
  • Fixed bug in viewport() (Thanks to Oliver Bedford <a2270269@athena.rrz.uni-koeln.de>).

Changes from Version 3.1 -> 3.2:

(V 3.2 not released yet)
  • Fixed bug in FORTRAN header Yfgl.h, device WINCLO clashed with routine winclo(). Renamed device WINCLO to WINCLOSE.
  • Fixed two bugs in getbutton(): getbutton(0) failed to return -1, getbutton() of qdevice()ed keys failed.
  • Fixed bug in winconstraints() that also affected startup: Sometimes Ygl freezed in winopen() and one had to move the window to continue. Ygl then waited for a ConfigureNotify event that wasn't generated.
  • Added support for the DoubleBuffer extension. This extension is new in X11R6.1 and replaces the MultiBuffer extension. Set DoubleBuffer to 1 in Imakefile to compile Ygl with this extension.
  • Fixed bug in mkprefix.
  • Added functions deflinestyle(), setlinestyle(), getlstyle(), lsrepeat(), getlsrepeat().
  • Fixed bug in popup menu code that occured when the cmap visual differed from the default visual (as on XServers with a 12 bit PseudoColor visual).
  • Setting the environment variables YGL_CV or YGL_RV to -1 now forces Ygl to use the XServers default visual instead of the best visual for colormap/RGB mode.

Changes from Version 3.0.3 -> 3.1:

(V 3.1 released 6. May 1996)
  • Changed Macros XR() and YR(), added rounding when converting float to int coordinates.
  • Fixed bug in viewport() that could cause the clipping region to be wrong.
  • Added routine logicop().
  • Fixed some bugs in the FORTRAN bindings: Device routines (TIE(), QDEVIC(), UNQDEV(), QENTER()) now require INTEGER*4 parameters as stated in the manpages. READPI(), WRITEP() now accept INTEGER*2 color indices. (Thanks to Luca Formaggia <forma@crs4.it> for the bug report.)
  • Added routine getmatrix().
  • Fixed bug in change_gc() and viewport(): Text was not clipped.
  • Changed frontbuffer() to be ignored when not in doublebuffer mode.
  • Changed qreset() to not remove saved mouse/key events.
  • Didn't fix getcpos() to return position relative to window, not to screen. This is a bug in GL, it is emulated in Ygl :-(((
  • Fixed getorigin() to return coordinates relative to screen.
  • Fixed bug in ygl.c that caused windows not to get a REDRAW event after a window move.
  • Added CMap/RGBmode checks to several color routines.
  • Fixed bug in gl2ppm() that caused gl2ppm() to scramble colors when in doublebuffered RGBmode.
  • Fixed REDRAW events when in RGB mode (Expose events seem not to propagate...). Due to problems with RGB mode windows Ygl returned to the good old way of handling RGB windows, i.e. gconfig() closes the cmap/RGB window and opens a RGB/cmap window at the same position.
  • Fixed bug in popupmenu colors when using private colormap.
  • The changes history is in html format now (as you can see 8-).

Changes from Version 3.0.2 -> 3.0.3:

(V 3.0.3 released 13. Dec 1995)
  • Fixed bug in mapcolor() that may cause segmentation fault.
  • Ygl now ignores MappingNotify Events and doesn't report errors.
  • Ygl windows now have white background (again). The transparent windows were too confusing (I think).
  • Fixed bug in freepup() that may cause segmentation faults. Changed newpup() to recycle menu-IDs after freepup().
  • Changed declaration of usleep() to be compatible with AIX 4.1.
  • Changed Imakefiles to use NullParameter instead of nothing.

Changes from Version 3.0.1 -> 3.0.2:

(V 3.0.2 released 13. Nov 1995)
  • Added noborder() as dummy function.
  • Added support for readsource(SRC_FRONT), needed in doublebuffer-mode to read pixels from the front window. Changed gl2ppm() to read from the front buffer.
  • Fixed bug in newpup() that may cause a segmentation fault in menus without %F callback.
  • getbutton() now can handle keyboard keys, eg. getbutton(AKEY) returns 1 when the key A is pressed at the moment when getbutton() is called. Note that it is better and faster to use the queue (qtest()/qread()) when you want to know if a key was pressed.

Changes from Version 3.0.0 -> 3.0.1:

(V 3.0.1 released 23. Oct 1995)
  • gl2ppm() now corrects the brightness of RGB windows.
  • Added menu.o to Makefile.std.
  • Added viewport() and getviewport().
  • Added vertex drawing routines: bgnpoint(), endpoint(), bgnline(), endline(), bgnclosedline(), endclosedline(), bgnpolygon(), endpolygon(), v2s(), v2i(), v2f(), v2d(). Note that it's not possible to change drawing attributes (color, ...) in the inner of a vertex pipeline in Ygl...
  • Added rpmv2().
  • Added dopup() to FORTRAN bindings (forgot it in 3.0.0...).
  • Added readpixels(), writepixels(), readRGB(), writeRGB().

Changes from Version 2.9.5 -> 3.0.0:

(V 3.0.0 released 23. Aug 1995)
  • Added dithering to RGBmode. Dithering is controlled by the environment variable YGL_DITHERSIZE or shorter YGL_DSZ. With this variable you can specify the size of the dither matrix. The default value is 4, leading to a 4x4 dither matrix. Valid values range from 0 to 6. On a normal 8 bit TrueColor visual ({3,3,2} bits {red,green,blue}) you obtain 113x113x49 = 625681 different "colors" with YGL_DSZ=4, leading to an effective screen depth of approx. 19 bits. The other values and the effective screendepths are:
           |  8 bit (3-3-2)  | 12 bit (4-4-4)  |  16 bit (6-5-5)
    YGL_DSZ| # colors (bits) | # colors (bits) |  # colors (bits)
    -------------------------------------------------------------
      0,1  |      256 ( 8  ) |     4096 (12  ) |     65536 (16  )
       2   |    10933 (13.4) |   226981 (17.8) |   3953125 (21.9)
       3   |   114688 (16.8) |  2515456 (21.3) |  44531200 (25.4)
       4   |   625681 (19.3) | 13997521 (23.7) | 249232081 (27.9)
       5   |  2354176 (21.2) | 53157376 (25.7) | 949029376 (29.8)
       6   |  6976981 (22.7) |158340421 (27.2) |2831006341 (31.4)
    
  • Note that dithering costs speed. You may set YGL_DSZ=0 to disable dithering. If you are lucky and have a 24 bit TrueColor visual, YGL_DSZ is automatically set to zero. Affected routines: RGBcolor(), gRGBcolor(), cpack(), c3s(), c3i(), c3f(). See examples/rgbtest.c for an example.
  • Added menu stuff. New functions: defpup(), newpup(), addtopup(), dopup(), freepup(), setpup(). See examples/popup.c for details.
  • Added C++ support to Ygl.h.
  • Fixed bugs in FORTRAN bindings. Unfortunately some of the FORTRAN names are not truncated to 6 chars due to nameing conflicts, SH*T. FORTRAN bindings must be lowercase...
     double_  -> doublebuffer_
     gRGBcol_ -> grgbcol_
     RGBcol_  -> rgbcol_
     RGBmod_  -> rgbmod_
     loadXf_  -> loadxf_
     getXdpy_ -> getxdpy_
     getXwid_ -> getxwid_
     getXgc_  -> getxgc_
    
  • Fixed bug in gl2ppm() that caused it to fail under newer versions of AIX32.
  • getXwid() returned Window* instead of Window, getXgc() returned GC* instead of GC. Fixed.
  • Added winX() to FORTRAN bindings.
  • Fixed cooperation of FORTRAN bindings and YGL_PREFIX.
  • Changed behaviour of prefposition() and winposition(). The given values now describe the position of the drawing area, not the position of the window incl. window manager decorations.
  • A RGBmode window is now a child of the initially created colormap mode window. This simplified changing to RGBmode. Ygl now uses the property WM_COLORMAP_WINDOWS to tell the window manager which colormaps are to be installed. This also fixed a bug when a subwindow of a cmap window was a RGB window. To toggle the colormaps is this case, use the window manager function f.colormap in twm or f.next_cmap in mwm (see your window manager manual for details).
  • Added the function getXdid(). getXdid() returns the window id of the drawable. This id differs from getXwin() when using RGBmode or doublebuffering.

Changes from Version 2.9.2 -> 2.9.5:

(V 2.9.5 released 4. Jan 1995)
  • Fixed gconfig() to save doublebuffer state when switching cmode and RGBmode.
  • Function added: winX()
  • Note that winX(Display *dpy, Window win) has some limitations:
    • dpy will be ignored. Ygl always uses the environment variable DISPLAY.
    • Changing the visual of a window with cmode() or RGBmode() (RGBmode();gconfig();) will change the X11 WindowID of the window. So after the code
        ...
        xwin = XCreateWindow(...);
        winX(dpy, xwin);
        RGBmode();
        gconfig();
           ...
      
      xwin is not valid anymore. You must get the new windowid with
        xwin = getXwid();
      
  • New environment variable YGL_PARENTWID or YGL_PWID introduced. See the ReadMe file for further details.
  • Ygl was distributed in terms of the GNU GENERAL PUBLIC LICENSE. Since version 2.9.5, Ygl is distributed in terms of the GNU LIBRARY GENERAL PUBLIC LICENSE. See the file LICENSE for further details.
  • Ygl has no private XErrorHandler anymore, as the default error handler gives more information and it's O.K. to exit() when a X error occures.

Changes from Version 2.9 -> 2.9.2:

(V 2.9.2 not released)
  • swapbuffers() didn't explicitely flush the X pipeline, so sometimes a swapbuffers() didn't have an immediate effect.
  • Bug in winopen() fixed that caused Ygl not to work with VisualID=0x0.
  • Some calls to [rcm]alloc() were not checked for out of memory. Fixed.

Changes from Version 2.8.1 -> 2.9:

(V 2.9 not released)
  • Added noop routine foreground().
  • Individual key devices introduced in Version 2.8 now reports both KeyPress and KeyRelease events. See examples/lines.c for an example.
  • Changed qread() to report only one REDRAW event after a window resize and window moves. This is done by interpreting both Expose and ConfigureNotify events as generators for REDRAW events.
  • Moved header Ygl.h, Yfgl.h and Yglprefix.h to X11 directory.

Changes from Version 2.8 -> 2.8.1:

(V 2.8.1 released 8. Oct 1994)
  • Fixed several bugs in FORTRAN bindings.
  • Added header file config.h.
  • Changed gversion() to return -1 if display can't be opened (see example contrib/tools/xmap.c).

Changes from Version 2.7 -> 2.8:

(V 2.8 not released)
  • Function added: getgdesc().
  • Added support for individual key devices, eg. F1KEY, UPARROWKEY and so on. This was done on public request.
  • Replaced XPointer with char*. XPointer isn't defined in X11R4.
  • Added some explicit type converters at calls to [cm]alloc.
  • Changed qdevice() and unqdevice() to return error when called before winopen().
  • Rewrote qtest() and qread(). Now both use one function. Hope not to have introduced too much bugs :-)
  • When routines are called before winopen() or ginit() or after gexit() that don't work at this point, the error message now includes the function name.
  • Fixed winset() and winclose() to handle invalid window ids correctly.
  • Fixed [cl ]rectread() to work when a window is completely visible again after it was not completely visible.
  • Changed gl2ppm() to report broken pipes (invalid shell commands and so on).
  • Included FORTRAN bindings for all Ygl functions. The FORTRAN versions of all functions have an underscore appended, so the FORTRAN compiler must append a _ to all names. f2c does this, xlf (under AIX 3.2) requires the option -qextname. See smile_f77.f for an example program. Set FortranBindings to 0 in Imakefile or change Makefile.std if you don't want these bindings. FORTRAN bindings are not tested because I have no programs.f to test. If you find bugs, feel free to report them to me.
  • Small change to colormap handling to reduce technicolor effects when using a private colormap (YGL_PCM=1) on displays not capable of more than one colormap at a time: Now the default colormap is copied to the private colormap and all entries in the private colormap count from the end of the colormap. So a mapcolor(i,r,g,b) changes colorcell 255-i (in 8 bit deep visuals) instead of cell i to reduce overlapping of private colorcells and cells already in use by other applications.
  • Extended selection of cmapmode visuals. Now cmapmode can also run on TrueColor and DirectColor visuals. This is for XServers that only have True/DirectColor visuals.

Changes from Version 2.6 -> 2.7:

(V 2.7 released 22. Jun 1994)
  • Functions added: getmcolors(), getdisplaymode(), setbell(), ringbell(), gl2ppm(), frontbuffer(), backbuffer()
  • Changed filtering of Expose events. Now even more Expose events for a window are filtered to minimize redraws.
  • XMULIB in Imakefile is also used in ibmLib.tmpl :-(. Changed to THEXMULIB.
  • Simplified code for handling of tie()s.
  • gl2ppm() is a subroutine that will write out the active [Y]gl window to a PPM file or pipe it through a shell command. Usage:
     int gl2ppm(char *filename);
    
    popen() is used instead of fopen() when filename[0] == '|'. For an example, see examples/lines.c.
  • WINCLOSE device changed to WINQUIT due to incompatibility with SGI's GL. Please change WINCLOSE to WINQUIT in your source code.
  • A REDRAW event is sent when a window is moved. This is not nessesary for redrawing but for getting the new origin of the window. Unfortunally SGI's GL has no unique event for window moves (ConfigureNotifyEvent)...

Changes from Version 2.5 -> 2.6:

(V 2.6 released 3. May 1994)
  • getcpos() was wrong when using ortho2(). Fixed.
  • charstr()'s update of character position was wrong when using ortho2. Fixed.
  • loadXfont() crashed when compiled with some non-ansi compilers due to realloc(NULL, ...). Changed.
  • qdevice()/unqdevice() couldn't change device list while a mouse button was pressed due to active pointer grabs. Changed.
  • linewidth() now only changes GCs when linewidth() has changed.
  • Several minor speedups.
  • ortho2() now detects empty [xy]-ranges.
  • Spurious errors "Ygl: X Error: BadColor (invalid Colormap parameter) on 0x2000002" showed up when quitting programs with private colormap (eg. example/colormap). Fixed.

Changes from Version 2.4 -> 2.5:

(V 2.5 released 28. Apr 1994)
  • The following functions are added: tie(), winpop(), winpush(), getlwidth(), swinopen(), getfont(), getfontencoding(), getcpos(), winconstraints(), noport().
  • Minor Changes to qreset(), qread(), and [I]makefiles.
  • Bug fixed that might cause getcolor() to return the wrong color when using multiple windows.
  • Bugs fixed that caused linewidth() and fonts not to be per window.
  • Bug fixed that caused prefposition() to measure from top left corner instead of bottom left corner.
  • getmcolor() returned the X color, not the Ygl color. Fixed.
  • The rect*() and sbox*() routines now draw rects inclusive the edges, i.e. rectf(1,1,2,2) is a 2x2 rect, not a 1x1 rect as before. Old versions of IBMs GL draw 1x1 rects, but this seems to have been fixed...
  • Three new environment variables YGL_SINGLEGC, YGL_CMAPVISUAL and YGL_RGBVISUAL has been added. See the ReadMe file for a description.
  • REDRAW events are now queued by default.
  • Changed example/rgb.c to demonstrate usage of tie() and renamed it to rgbtest.c.
  • Changed example/lines.c to demonstrate usage of swinopen().
  • Header file Ygl.h is now installed automatically when using imake.
  • New define in Imakefile to use (experimental) support for global standard colormaps (see xstdcmap(1)).
  • The ReadMe file is in html format now. Use Mosaic or emacs w3-mode (or other www viewer) to read. The latest version of this ReadMe is available at the World Wide Web:
    http://WWW.thp.Uni-Duisburg.DE/Ygl/ReadMe.html.

Changes from Version 2.3 -> 2.4:

(V 2.4 released 1. Feb 1994)
  • The following functions are added: rectcopy(), cpack(), c3s(), c3i(), c3f(), linewidth(), rect{read|write}(), getXgc(), crect{read|write}().
  • getXgc() is not included in standard GL. It returns a pointer to the graphics context just like getXdpy() returns a pointer to the display. You can for example use it to draw lines etc. XORed with the background:
      #include 
      ...
      XSetFunction(getXdpy(), getXgc(), GXxor);
    
  • crect{read|write}() are also not in standard GL. They work the same as lrect{read|write}(), they only {read|write} the data to a char array instead of Int32 array. This is to speed up Colormap mode operations.
  • Bug in timer handling fixed which caused flushtimes >= 1 second to be ignored.
  • Small bugs in lrect{read|write}() fixed.
  • All rect*() and sbox*() routines now draw rectangles even when x2 < x1 or y2 < y1, i.e. rect(10,10,20,20) is the same as rect(20,20,10,10). circ*() and arc*() routines now interpret negative radii as zero.
  • doublebuffer() and singlebuffer() are now available in the library even when not compiled with -DMULTIBUF.
  • A new example program "smile.f" illustrates how to call Ygl routines from Fortran under AIX.

Changes from Version 2.2 -> 2.3:

(V 2.3 released 12. Jan 1994)
  • The following functions are added: lrectread(), lrectwrite(), readsource().
  • lrectread() returns the same array as the GL version.
  • DirectColor visuals are supported, too, now.

Changes from Version 2.1 -> 2.2:

(V 2.2 released 9. Jan 1994)
  • You don't need to recompile the X-Server anymore to use doublebuffering under AIX 3.2.5 (AIXWindows 1.2.3). You simply have to add the option -x mbx to the X-Servers command line on startup. Additionaly, the multibuffer routines under AIX are in libXext.a now (as they should...).
  • Bug in qread() (Alt/Ctrl keys were reported as normal keys) fixed.
  • Bug in qtest() that eventually caused unknown events to block the queue fixed.
  • The following function is added: ortho2().

Changes from Version 2.0 -> 2.1:

(V 2.1 released 25. Oct 1993)
  • Name of library changed to Ygl due to a nameing conflict with SUNs XGL library.
  • All environment vars now starts with YGL_. The old names remains valid for compatibility reasons.
  • Xgl_Prefix -> Ygl_Prefix and all names are prepended with ygl_. Change file mkprefix to get the old xgl_ prefix.
  • gversion returns Ygl:X11-x.y.z (not Xgl:X11-x.y.z).
  • Example programs and {Im|M}akefiles revisited.
  • Button{Press|Release} events are only received when nessesary now.
  • Bugs in rdr() and arc()/arcf() fixed. They didn't work as expected...
  • Bug in charstr() to RGB windows fixed (core dumped).
  • Bug in winclose() fixed.
  • Support for StaticGray visual added. Ygl now runs on Monochrome servers (again) (eg. XFree under Linux).
  • Colormaps are now only installed when the server has room for them. This avoids the colormap switches on startup.
  • The following function is added: gRGBcolor().

Changes from Version 1.3 -> 2.0:

(V 2.0 released 21. Oct 1993)
  • BackingStore support added. Set XGL_BACKINGSTORE=1.
  • RGBmode and support for other visual types is added. Xgl can run in a per window RGB mode, if the X-Server has a TrueColor visual. Xgl will always select the appropiate visual for the desired mode, independent of the default visual, ie:
     Colormap mode <-> PseudoColor or GrayScale visual
     RGB mode      <-> TrueColor visual
    
  • Short names for environment variables added:
     XGL_FT  for XGL_FLUSHTIME
     XGL_PCM for XGL_PRIVATECOLORMAP
     XGL_BS  for XGL_BACKINGSTORE
    
  • The following functions are added: winmove(), winposition(), ginit(), RGBmode(), RGBcolor(), cmode.
  • Two routines arcx() and arcxf() that are not part of standard GL are contributed by michael@thp.Uni-Duisburg.DE. With this routines you can draw outlined and filled _elliptic_ arcs.
  • All drawing functions are implemented with floating-point arguments, i.e.: pnt2(), move2(), draw2(), rmv2(), rdr2(), arc(), arcf(), circ(), circf(), rect(), rectf(), sbox(), sboxf(), pmv2(), pdr2(), rpdr2(), poly2(), polf2(), cmov2().
  • A bug in prefposition() is fixed that caused prefposition() to not work...
  • All routines that talk to the X-Server now check for correct initialisation. This may slow down Xgl a very little bit. You can undefine CHECKDISPLAY in header.h get the old method (which is also used by GL :-).
  • You can set Xgl_Prefix to 1 in Imakefile and do a
    # xmkmf -a;make clean;make
    
    to compile a library named libXglp.a where all function names are prepended with xgl_. This is to avoid name conflicts if you want to use Xgl in other projects as the Turbo Pascal for Unix emulator by Michael Staats (michael@thp.Uni-Duisburg.DE).

Changes from Version 1.1.1 -> 1.3:

(V 1.3 released 24. Aug 1993)
  • The following functions are added: rmv2s(), rmv2i(), rdr2i(), rdr2s(), winclose(), strwidth(), getheight(), getdescender().
  • The qtest() and qread() routines can now distinguish between LEFTMOUSE, MIDDLEMOUSE and RIGHTMOUSE and support MOUSEX and MOUSEY events.
  • Setting XGL_FLUSHTIME to -1 will put the XServer into synchronous mode (see XSynchonize). This mode seems to be veeeryyy slooow, but is good for debugging...

Changes from Version 1.1 -> 1.1.1:

(V 1.1.1 not released)
  • A bug in qread() is fixed that caused too much Expose events (REDRAW) to be filtered out. XGL filters out all Expose events that are directly followed by another Expose event for the same window. In versions prior to 1.1.1, qread() filtered out ALL Expose events that were followed by another Expose event, even for another window :-(

Changes from Version 1.0.1 -> 1.1:

(V 1.1 released 15 Jul 1993)
  • The function getorigin() returned the position of the upper left corner in X11 coordinates rather than the position of the lower left corner in GL coordinates.
  • The function "gflush()" is no longer supported. Use sleep(0) to flush the graphics pipeline instead.
  • XGL supports doublebuffering via the "Multi-Buffering" server extension. This extension is new in X11R5 and is included in the lpp X11dev.src under AIX 3.2. To use doublebuffering you have to link the "Multi-Buffering" extension into your X-Server (AIXlers, see /usr/lpp/X11/Xamples/README, "Linking the Sample Extensions into the Server"). The related GL routines are doubleduffer, swapbuffer() and singlebuffer().
  • The following functions are added: getmcolor(), getcolor(), gconfig(), singlebuffer(), swapbuffers(), doublebuffer(), getvaluator(), getbutton(), concave(), poly2i(), poly2s(), polf2i(), polf2s().

Changes from Version 1.0 -> 1.0.1:

(V 1.0.1 released 7 Jul 1993)
  • The refresh time and the use of the colormap is now controlled via two environment variables (XGL_PRIVATECOLORMAP and XGL_FLUSHTIME) and no longer through external variables due to problems with shared libraries.
  • libXgl.a is now a shared library under AIX and the linker option -lX11 can be omitted.

Initial Version 1.0:

(V 1.0 released 5 Jul 1993) ygl-4.2e/Ygl.xpm0000644000175000017500000002073106156345572013144 0ustar prabhuprabhu/* XPM */ static char *Smile[] = { /* width height num_colors chars_per_pixel */ " 50 50 4 1", /* colors */ ". c None", "# c #fe0000", "a c #fefefe", "b c #000000", /* pixels */ "..................................................", "..................................................", "..................................................", "..................................................", "..................................................", ".....................#########....................", "..................###############.................", "................###################...............", "..............#######################.............", ".............#########################............", "............###########################...........", "...........#############################..........", "..........###############################.........", ".........#################################........", "........###################################.......", "........#########################aaaaa#####.......", ".......#########################aaaaaaa#####......", ".......########################aaabbaaaa####......", ".......########################aabbbbaaa####......", "......#########################aabbbbbaa#####.....", "......#############a###########aabbbbbaa#####.....", "......#####a######aa###########aaabbbaaa#####.....", "......#####aaaaaaaaa###########aaaaaaaaa#####.....", "......######aaaaaaa#############aaaaaaa######.....", "......#######aaaaa###############aaaaa#######.....", "......#######################################.....", "......#######################################.....", "......#######################################.....", "......#######################################.....", "......#######################################.....", "......########b#####################b########.....", ".......#######b#####################b#######......", ".......########b###################b########......", ".......#########b#################b#########......", "........#########b###############b#########.......", "........##########bb###########bb##########.......", ".........###########bb#######bb###########........", "..........############bbbbbbb############.........", "...........#############################..........", "............###########################...........", ".............#########################............", "..............#######################.............", "................###################...............", "..................###############.................", ".....................#########....................", "..................................................", "..................................................", "..................................................", "..................................................", ".................................................." }; SIMPLE = T BITPIX = 8 NAXIS = 2 NAXIS1 = 50 NAXIS2 = 50 HISTORY Written by XV 3.10 END WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWþþþþþWWWWWWWWWWWWWWWþþþþþWWWWWWWWWWWWWþþþþþþþWWWWWWWWWWWWWþþþþþþþWWWWWWWWWWWþþþþþþþþþWWWWWWWWWWWþþþþþþþþþWWWWWWWWWWþWWWWWWþþWWWWWWWWWWWþþþþþþWWWWWWWWWWWWWWWWWWþWWWWWWWWWWWþþþþWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWþþþþWWWWWWWWWWWWWWWWWWWWWWWWWWWWWþþþþþWWWWWWWWWWWWWWWWWWWWWWWWWWWWþþþþþþþWWWWWWWWWWWWWWWWWWWWWWWWWWWWWþþþþþþþWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWþþþþþWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW ygl-4.2e/irisgl/0000755000175000017500000000000010620320076013130 5ustar prabhuprabhuygl-4.2e/irisgl/fdevice.h0000777000175000017500000000000010712351413016542 2../X11/Yfgl.hustar prabhuprabhuygl-4.2e/irisgl/gl.h0000777000175000017500000000000010712351413015371 2../X11/Ygl.hustar prabhuprabhuygl-4.2e/irisgl/device.h0000777000175000017500000000000010712351413016226 2../X11/Ygl.hustar prabhuprabhuygl-4.2e/irisgl/fgl.h0000777000175000017500000000000010712351413015705 2../X11/Yfgl.hustar prabhuprabhuygl-4.2e/font.c0000444000175000017500000001145310620036162012753 0ustar prabhuprabhu/* * Ygl: Run GL programs with standard X11 and/or OpenGL routines. * (C) Fred Hucht 1993-2007 * EMail: fredthp.Uni-Duisburg.de */ static const char vcid[] = "$Id: font.c,v 4.3 2007-05-08 11:01:38+02 fred Exp $"; #include "header.h" #ifdef OGL static GLuint font_base = 0; #endif void loadXfont(Int32 id, Char8 *name) { int i; XFontStruct *fs; const char * MyName = "loadXfont"; I(MyName, "%d,'%s'", id, name); if(NULL == (fs = XLoadQueryFont(D, name))) { Yprintf(MyName, "can't find font '%s'.\n", name); return; } if(Ygl.Fonts == NULL) { /* initialize */ i = Ygl.LastFont = 0; Ygl.Fonts = (YglFont*)malloc(sizeof(YglFont)); } else { for(i = Ygl.LastFont; i >= 0 && Ygl.Fonts[i].id != id; i--); if(i < 0) { /* not found */ i = ++Ygl.LastFont; Ygl.Fonts = (YglFont*)realloc(Ygl.Fonts, (Ygl.LastFont + 1) * sizeof(YglFont)); } } if(Ygl.Fonts == NULL) { Yprintf(MyName, "can't allocate memory for font '%s'.\n", name); exit(-1); } Ygl.Fonts[i].fs = fs; Ygl.Fonts[i].id = id; #ifdef DEBUG fprintf(stderr, "loadXfont: name = '%s', fs = 0x%x, id = %d.\n", name, fs, id); #endif } #ifdef OGL static void oglSetFont(const char *caller, int i) { int first; int last; if (font_base == 0) { /* initialize */ font_base = glGenLists(256); if (!glIsList(font_base)) { Yprintf(caller, "out of display lists (%d).\n", font_base); exit (1); } } first = Ygl.Fonts[i].fs->min_char_or_byte2; last = Ygl.Fonts[i].fs->max_char_or_byte2; glXUseXFont(Ygl.Fonts[i].fs->fid, first, last-first+1, font_base+first); } #endif void font(Int16 id) { int i = Ygl.LastFont; const char * MyName = "font"; I(MyName, "%d", id); while(i > 0 && Ygl.Fonts[i].id != id) i--; W->font = i; #ifdef DEBUG fprintf(stderr, "font: id = %d, W->font = %d, fid = 0x%x.\n", id, i, Ygl.Fonts[i].fs->fid); #endif IFOGL(oglSetFont(MyName, i), XSetFont(D, W->chargc, Ygl.Fonts[i].fs->fid)); } Int32 getfont(void) { const char * MyName = "getfont"; I(MyName, ""); return Ygl.Fonts[W->font].id; } void getfontencoding(char *r) { XFontStruct *fs; XFontProp *fp; int i; Atom fontatom; char *name, *np = NULL, *rp = r; const char * MyName = "getfontencoding"; I(MyName, "'%s'", r); fs = Ygl.Fonts[W->font].fs; fontatom = XInternAtom(D, "FONT", False); for (i = 0, fp = fs->properties; i < fs->n_properties; i++, fp++) { if (fp->name == fontatom) { np = name = XGetAtomName(D, fp->card32); i = 0; while(i < 13 && *np != 0) if(*np++ == '-') i++; do { if(*np != '-') *rp++ = *np; } while(*np++ != 0); XFree(name); } } if(np == NULL) { Yprintf(MyName, "can't determine fontencoding.\n"); *r = '\0'; } } Int32 getheight(void) { const char * MyName = "getheight"; I(MyName, ""); return(Ygl.Fonts[W->font].fs->ascent + Ygl.Fonts[W->font].fs->descent); } Int32 getdescender(void) { const char * MyName = "getdescender"; I(MyName, ""); return Ygl.Fonts[W->font].fs->descent; } Int32 strwidth(Char8 *string) { const char * MyName = "strwidth"; I(MyName, "'%s'", string); return XTextWidth(Ygl.Fonts[W->font].fs, string, strlen(string)); } void charstr(Char8 *Text) { const char * MyName = "charstr"; I(MyName, "'%s'", Text); IFOGL(/* OpenGL */ glRasterPos3f(W->xc, W->yc, W->zc); glPushAttrib(GL_LIST_BIT); glListBase(font_base); glCallLists(strlen(Text), GL_UNSIGNED_BYTE, (GLubyte *)Text); glPopAttrib(), /* X11 */ if(!(W->rgb || Ygl.GC)) { /* set text color to active color */ XSetForeground(D, W->chargc, YGL_COLORS(W->color)); } XDrawString(D, W->draw, W->chargc, X(W->xc), Y(W->yc), Text, strlen(Text)) ); W->xc += strwidth(Text) / W->xf; F; } void cmov2 (Coord x, Coord y ) { I("cmov2" , "%g,%g", x, y); W->xc = x; W->yc = y; IFOGL(W->zc = 0,/**/); } void cmov2i(Icoord x, Icoord y ) { I("cmov2i", "%d,%d", x, y); W->xc = x; W->yc = y; IFOGL(W->zc = 0,/**/); } void cmov2s(Scoord x, Scoord y ) { I("cmov2s", "%d,%d", x, y); W->xc = x; W->yc = y; IFOGL(W->zc = 0,/**/); } #ifdef OGL void cmov (Coord x, Coord y, Coord z) { I("cmov" , "%g,%g,%g", x, y, z); W->xc = x; W->yc = y; W->zc = z; } void cmovi (Icoord x, Icoord y, Icoord z) { I("cmovi", "%d,%d,%d", x, y, z); W->xc = x; W->yc = y; W->zc = z; } void cmovs (Scoord x, Scoord y, Scoord z) { I("cmovs", "%d,%d,%d", x, y, z); W->xc = x; W->yc = y; W->zc = z; } #endif void getcpos(Screencoord *x, Screencoord *y) { /* Note: Due to a bug in GL getcpos() returns coordinates * relative to the screen, not to the window. We emulate this. :-(( */ const char *MyName = "getcpos"; Int32 xo, yo; I(MyName, "*,*"); getorigin(&xo, &yo); *x = xo + XR(W->xc); *y = yo + YR(W->yc); #ifdef DEBUG fprintf(stderr, "getcpos: *x = %d, *y = %d\n", *x, *y); #endif } ygl-4.2e/ygl.c0000444000175000017500000016766110621132633012616 0ustar prabhuprabhu/* * Ygl: Run GL programs with standard X11 and/or OpenGL routines. * (C) Fred Hucht 1993-2007 * EMail: fredthp.Uni-Duisburg.de */ #define VERSION "4.2e" /* gversion() only allows 12 chars (3 of VERSION) */ static const char vcid[] = "$Id: ygl.c,v 4.17 2007-05-11 20:27:39+02 fred Exp $"; static const char * const WhatString[]= { "@(#)Ygl V" VERSION " by Fred Hucht (C) 1993-2007", "@(#)http://www.thp.Uni-Duisburg.de/Ygl/", "@(#)EMail: fred thp.Uni-Duisburg.de" }; #include "header.h" #include #include #ifdef HASXMU #include #include #endif static XSizeHints YglSizeHints; /* for winconstraints() */ static int YglMapNext = True, /* flag to tell winconstraints() to map window */ YglRGB = False; /* flag to tell gconfig() to switch to RGB mode */ static Cursor YglCursor; /* our special cursor */ static void noinit(const char *caller); static int notimplemented(const char *caller); static int warn(const char *name, const char *format, ...); static int XRscale(double x); static int YRscale(double x); static int Xscale (double x); static int Yscale (double x); static void await_windowevent(Window win, long mask, int type); static const char*devicename(Device dev); static void init_keymap(void); static Int32 x2gl_wid(Window win, int which); static int is_wid(Int32 wid); static int ginit_badWindowHandler(Display *dpy, XErrorEvent *error); static void get_environment(const char *caller); static void create_gc(const char *caller, Int32); static void free_gc(Int32); static void clear_children(Int32); static void set_cmapwins(const char *caller, const YglWindow *cw, int install); static void create_main_window(const char *caller, const char *Title, int x, int y, Uint width, Uint height); #ifdef RGBWIN static void create_RGB_window(const char *caller); static void destroy_RGB_window(const char *caller); #endif #if 0 static int errorHandler(Display *, XErrorEvent *); static int unused_colormaps(void); #endif static void signal_handler(int); static Int32 win_open(const char *caller, const char *Title, Int32 pid, Window xpid); static Ulong parent_height(void); static int setup_visuals(const char *caller); static void setup_colormaps(const char *caller); static void setup_shift_and_mask(void); static YglWindow* find_new_window_id(const char *caller); static int winX_badWindowHandler(Display *, XErrorEvent *); static Window get_real_parent(Window win); static Window get_parent(Window win); static int translate_xy(int xi, int yi, int *xf, int *yf); #ifdef DEBUG static const char *XEventNames[] = { "Unused0", "Unused1", "KeyPress", "KeyRelease", "ButtonPress", "ButtonRelease", "MotionNotify", "EnterNotify", "LeaveNotify", "FocusIn", "FocusOut", "KeymapNotify", "Expose", "GraphicsExpose", "NoExpose", "VisibilityNotify", "CreateNotify", "DestroyNotify", "UnmapNotify", "MapNotify", "MapRequest", "ReparentNotify", "ConfigureNotify", "ConfigureRequest", "GravityNotify", "ResizeRequest", "CirculateNotify", "CirculateRequest", "PropertyNotify", "SelectionClear", "SelectionRequest", "SelectionNotify", "ColormapNotify", "ClientMessage", "MappingNotify" }; #endif static const struct Device_ { const char *name; Device dev; } device[] = { {"NULLDEV", NULLDEV}, {"BREAKKEY", BREAKKEY}, {"SETUPKEY", SETUPKEY}, {"LEFTCTRLKEY", LEFTCTRLKEY}, {"CAPSLOCKKEY", CAPSLOCKKEY}, {"RIGHTSHIFTKEY", RIGHTSHIFTKEY}, {"LEFTSHIFTKEY", LEFTSHIFTKEY}, {"ESCKEY", ESCKEY}, {"ONEKEY", ONEKEY}, {"TABKEY", TABKEY}, {"QKEY", QKEY}, {"AKEY", AKEY}, {"SKEY", SKEY}, {"NOSCRLKEY", NOSCRLKEY}, {"TWOKEY", TWOKEY}, {"THREEKEY", THREEKEY}, {"WKEY", WKEY}, {"EKEY", EKEY}, {"DKEY", DKEY}, {"FKEY", FKEY}, {"ZKEY", ZKEY}, {"XKEY", XKEY}, {"FOURKEY", FOURKEY}, {"FIVEKEY", FIVEKEY}, {"RKEY", RKEY}, {"TKEY", TKEY}, {"GKEY", GKEY}, {"HKEY", HKEY}, {"CKEY", CKEY}, {"VKEY", VKEY}, {"SIXKEY", SIXKEY}, {"SEVENKEY", SEVENKEY}, {"YKEY", YKEY}, {"UKEY", UKEY}, {"JKEY", JKEY}, {"KKEY", KKEY}, {"BKEY", BKEY}, {"NKEY", NKEY}, {"EIGHTKEY", EIGHTKEY}, {"NINEKEY", NINEKEY}, {"IKEY", IKEY}, {"OKEY", OKEY}, {"LKEY", LKEY}, {"SEMICOLONKEY", SEMICOLONKEY}, {"MKEY", MKEY}, {"COMMAKEY", COMMAKEY}, {"ZEROKEY", ZEROKEY}, {"MINUSKEY", MINUSKEY}, {"PKEY", PKEY}, {"LEFTBRACKETKEY", LEFTBRACKETKEY}, {"QUOTEKEY", QUOTEKEY}, {"RETKEY", RETKEY}, {"PERIODKEY", PERIODKEY}, {"VIRGULEKEY", VIRGULEKEY}, {"EQUALKEY", EQUALKEY}, {"ACCENTGRAVEKEY", ACCENTGRAVEKEY}, {"RIGHTBRACKETKEY", RIGHTBRACKETKEY}, {"BACKSLASHKEY", BACKSLASHKEY}, {"PAD1", PAD1}, {"PAD0", PAD0}, {"LINEFEEDKEY", LINEFEEDKEY}, {"BACKSPACEKEY", BACKSPACEKEY}, {"DELKEY", DELKEY}, {"PAD4", PAD4}, {"PAD2", PAD2}, {"PAD3", PAD3}, {"PADPERIOD", PADPERIOD}, {"PAD7", PAD7}, {"PAD8", PAD8}, {"PAD5", PAD5}, {"PAD6", PAD6}, {"PADPF2", PADPF2}, {"PADPF1", PADPF1}, {"LEFTARROWKEY", LEFTARROWKEY}, {"DOWNARROWKEY", DOWNARROWKEY}, {"PAD9", PAD9}, {"PADMINUS", PADMINUS}, {"PADCOMMA", PADCOMMA}, {"PADPF4", PADPF4}, {"PADPF3", PADPF3}, {"RIGHTARROWKEY", RIGHTARROWKEY}, {"UPARROWKEY", UPARROWKEY}, {"PADENTER", PADENTER}, {"SPACEKEY", SPACEKEY}, {"LEFTALTKEY", LEFTALTKEY}, {"RIGHTALTKEY", RIGHTALTKEY}, {"RIGHTCTRLKEY", RIGHTCTRLKEY}, {"F1KEY", F1KEY}, {"F2KEY", F2KEY}, {"F3KEY", F3KEY}, {"F4KEY", F4KEY}, {"F5KEY", F5KEY}, {"F6KEY", F6KEY}, {"F7KEY", F7KEY}, {"F8KEY", F8KEY}, {"F9KEY", F9KEY}, {"F10KEY", F10KEY}, {"F11KEY", F11KEY}, {"F12KEY", F12KEY}, {"PRINTSCREENKEY", PRINTSCREENKEY}, {"SCROLLLOCKKEY", SCROLLLOCKKEY}, {"PAUSEKEY", PAUSEKEY}, {"INSERTKEY", INSERTKEY}, {"HOMEKEY", HOMEKEY}, {"PAGEUPKEY", PAGEUPKEY}, {"ENDKEY", ENDKEY}, {"PAGEDOWNKEY", PAGEDOWNKEY}, {"NUMLOCKKEY", NUMLOCKKEY}, {"PADVIRGULEKEY", PADVIRGULEKEY}, {"PADASTERKEY", PADASTERKEY}, {"PADPLUSKEY", PADPLUSKEY}, {"MOUSEX", MOUSEX}, {"MOUSEY", MOUSEY}, {"ANYKEY", ANYKEY}, {"KEYBD", KEYBD}, {"TIMER0", TIMER0}, {"TIMER1", TIMER1}, {"TIMER2", TIMER2}, {"TIMER3", TIMER3}, {"REDRAW", REDRAW}, {"INPUTCHANGE", INPUTCHANGE}, {"WINCLOSE", WINCLOSE}, {"WINFREEZE", WINFREEZE}, {"WINTHAW", WINTHAW}, {"WINQUIT", WINQUIT}, {"DEPTHCHANGE", DEPTHCHANGE}, {"Unknown", MAXYGLDEVICE} }; YglControl Ygl = { NULL, /* display */ NULL, NULL, /* Windows, active */ 0, 1, /* ActiveWindow, NextWindow */ /*---------------------- Bitfields: */ #ifdef AUTOFLUSH False, /* flush */ #endif False, /* wm_dw_flag */ False, /* stat */ False, /* PCM */ /* use private colormap? */ False, /* BS */ /* YGL_BS (backing store ) set */ False, /* GC */ /* Use single GC in CMap windows (slower) */ False, /* cmapmode uses TrueColor or DirectColor visual */ #ifdef OGL False, /* Use OpenGL routines */ False, /* in GL_SELECT mode */ #endif /*---------------------- End of Bitfields */ NULL, /* Fonts */ 0, /* LastFont */ 0, /* Eventmask */ 0, /* Atom wm_dw */ 100, /* FT */ /* autoflush time in msec */ {-2,-2}, /* V */ /* User requested visuals */ 0, /* PWID */ /* Parent window ID of winopen wins */ 4, /* DSZ */ /* Size of RGBmode dither matrix */ 0, 0, /* CCmap, RCmap */ NULL, /* Colors */ NULL, /* ColorsInv */ 0, 0, 0, /* rs, gs, bs */ 0, 0, 0, /* rb, gb, bb */ #ifdef DEBUG XEventNames, /* For debugging */ #else NULL, #endif noinit, notimplemented, warn, x2gl_wid, XRscale, YRscale, Xscale, Yscale, await_windowevent, devicename }; /* Static functions */ static const char* devicename(Device dev) { int i; for(i = 0; device[i].dev != dev && device[i].dev != MAXYGLDEVICE; i++); return device[i].name; } static void init_keymap(void) { static int inited = False; if(!inited) { int code; unsigned char wieoft[MAXYGLDEVICE]; inited = True; memset(wieoft, 0, sizeof(wieoft)); for(code = 0; code < KEYMAP_LEN; code++) { KeySym ks = XKeycodeToKeysym(D, code, 0); switch(ks) { /* main keys */ case XK_a: Ygl.keymap[code] = AKEY; break; case XK_b: Ygl.keymap[code] = BKEY; break; case XK_c: Ygl.keymap[code] = CKEY; break; case XK_d: Ygl.keymap[code] = DKEY; break; case XK_e: Ygl.keymap[code] = EKEY; break; case XK_f: Ygl.keymap[code] = FKEY; break; case XK_g: Ygl.keymap[code] = GKEY; break; case XK_h: Ygl.keymap[code] = HKEY; break; case XK_i: Ygl.keymap[code] = IKEY; break; case XK_j: Ygl.keymap[code] = JKEY; break; case XK_k: Ygl.keymap[code] = KKEY; break; case XK_l: Ygl.keymap[code] = LKEY; break; case XK_m: Ygl.keymap[code] = MKEY; break; case XK_n: Ygl.keymap[code] = NKEY; break; case XK_o: Ygl.keymap[code] = OKEY; break; case XK_p: Ygl.keymap[code] = PKEY; break; case XK_q: Ygl.keymap[code] = QKEY; break; case XK_r: Ygl.keymap[code] = RKEY; break; case XK_s: Ygl.keymap[code] = SKEY; break; case XK_t: Ygl.keymap[code] = TKEY; break; case XK_u: Ygl.keymap[code] = UKEY; break; case XK_v: Ygl.keymap[code] = VKEY; break; case XK_w: Ygl.keymap[code] = WKEY; break; case XK_x: Ygl.keymap[code] = XKEY; break; case XK_y: Ygl.keymap[code] = YKEY; break; case XK_z: Ygl.keymap[code] = ZKEY; break; case XK_0: Ygl.keymap[code] = ZEROKEY; break; case XK_1: Ygl.keymap[code] = ONEKEY; break; case XK_2: Ygl.keymap[code] = TWOKEY; break; case XK_3: Ygl.keymap[code] = THREEKEY; break; case XK_4: Ygl.keymap[code] = FOURKEY; break; case XK_5: Ygl.keymap[code] = FIVEKEY; break; case XK_6: Ygl.keymap[code] = SIXKEY; break; case XK_7: Ygl.keymap[code] = SEVENKEY; break; case XK_8: Ygl.keymap[code] = EIGHTKEY; break; case XK_9: Ygl.keymap[code] = NINEKEY; break; case XK_apostrophe: Ygl.keymap[code] = QUOTEKEY; break; case XK_backslash: Ygl.keymap[code] = BACKSLASHKEY; break; case XK_bracketleft: Ygl.keymap[code] = LEFTBRACKETKEY; break; case XK_bracketright: Ygl.keymap[code] = RIGHTBRACKETKEY; break; case XK_comma: Ygl.keymap[code] = COMMAKEY; break; case XK_equal: Ygl.keymap[code] = EQUALKEY; break; case XK_grave: Ygl.keymap[code] = ACCENTGRAVEKEY; break; case XK_minus: Ygl.keymap[code] = MINUSKEY; break; case XK_period: Ygl.keymap[code] = PERIODKEY; break; case XK_semicolon: Ygl.keymap[code] = SEMICOLONKEY; break; case XK_slash: Ygl.keymap[code] = VIRGULEKEY; break; case XK_space: Ygl.keymap[code] = SPACEKEY; break; case XK_BackSpace: Ygl.keymap[code] = BACKSPACEKEY; break; case XK_Escape: Ygl.keymap[code] = ESCKEY; break; case XK_Return: Ygl.keymap[code] = RETKEY; break; case XK_Tab: Ygl.keymap[code] = TABKEY; break; /* modifiers */ case XK_Shift_L: Ygl.keymap[code] = LEFTSHIFTKEY; break; case XK_Shift_R: Ygl.keymap[code] = RIGHTSHIFTKEY; break; case XK_Alt_L: case XK_Meta_L: Ygl.keymap[code] = LEFTALTKEY; break; case XK_Alt_R: case XK_Meta_R: case XK_ISO_Level3_Shift: case XK_Mode_switch: Ygl.keymap[code] = RIGHTALTKEY; break; case XK_Control_L: Ygl.keymap[code] = LEFTCTRLKEY; break; case XK_Control_R: case XK_Multi_key: case XK_Execute: Ygl.keymap[code] = RIGHTCTRLKEY; break; case XK_Num_Lock: Ygl.keymap[code] = NUMLOCKKEY; break; case XK_Caps_Lock: case XK_Shift_Lock: Ygl.keymap[code] = CAPSLOCKKEY; break; /* cursor control */ case XK_Delete: Ygl.keymap[code] = DELKEY; break; case XK_Down: Ygl.keymap[code] = DOWNARROWKEY; break; case XK_End: Ygl.keymap[code] = ENDKEY; break; case XK_Home: Ygl.keymap[code] = HOMEKEY; break; case XK_Insert: Ygl.keymap[code] = INSERTKEY; break; case XK_Left: Ygl.keymap[code] = LEFTARROWKEY; break; case XK_Next: Ygl.keymap[code] = PAGEDOWNKEY; break; case XK_Prior: Ygl.keymap[code] = PAGEUPKEY; break; case XK_Right: Ygl.keymap[code] = RIGHTARROWKEY; break; case XK_Up: Ygl.keymap[code] = UPARROWKEY; break; /* keypad */ case XK_KP_0: case XK_KP_Insert: Ygl.keymap[code] = PAD0; break; case XK_KP_1: case XK_KP_End: Ygl.keymap[code] = PAD1; break; case XK_KP_2: case XK_KP_Down: Ygl.keymap[code] = PAD2; break; case XK_KP_3: case XK_KP_Next: Ygl.keymap[code] = PAD3; break; case XK_KP_4: case XK_KP_Left: Ygl.keymap[code] = PAD4; break; case XK_KP_5: case XK_KP_Begin: Ygl.keymap[code] = PAD5; break; case XK_KP_6: case XK_KP_Right: Ygl.keymap[code] = PAD6; break; case XK_KP_7: case XK_KP_Home: Ygl.keymap[code] = PAD7; break; case XK_KP_8: case XK_KP_Up: Ygl.keymap[code] = PAD8; break; case XK_KP_9: case XK_KP_Prior: Ygl.keymap[code] = PAD9; break; case XK_KP_F1: Ygl.keymap[code] = PADPF1; break; case XK_KP_F2: Ygl.keymap[code] = PADPF2; break; case XK_KP_F3: Ygl.keymap[code] = PADPF3; break; case XK_KP_F4: Ygl.keymap[code] = PADPF4; break; case XK_KP_Add: Ygl.keymap[code] = PADPLUSKEY; break; case XK_KP_Decimal: case XK_KP_Delete: Ygl.keymap[code] = PADPERIOD; break; case XK_KP_Enter: Ygl.keymap[code] = PADENTER; break; case XK_KP_Divide: Ygl.keymap[code] = PADVIRGULEKEY; break; case XK_KP_Multiply: Ygl.keymap[code] = PADASTERKEY; break; case XK_KP_Separator: Ygl.keymap[code] = PADCOMMA; break; case XK_KP_Subtract: Ygl.keymap[code] = PADMINUS; break; /* function keys */ case XK_F1: Ygl.keymap[code] = F1KEY; break; case XK_F2: Ygl.keymap[code] = F2KEY; break; case XK_F3: Ygl.keymap[code] = F3KEY; break; case XK_F4: Ygl.keymap[code] = F4KEY; break; case XK_F5: Ygl.keymap[code] = F5KEY; break; case XK_F6: Ygl.keymap[code] = F6KEY; break; case XK_F7: Ygl.keymap[code] = F7KEY; break; case XK_F8: Ygl.keymap[code] = F8KEY; break; case XK_F9: Ygl.keymap[code] = F9KEY; break; case XK_F10: Ygl.keymap[code] = F10KEY; break; case XK_F11: Ygl.keymap[code] = F11KEY; break; case XK_F12: Ygl.keymap[code] = F12KEY; break; case XK_F13: case XK_Print: Ygl.keymap[code] = PRINTSCREENKEY; break; case XK_F14: case XK_Scroll_Lock: case XK_Cancel: Ygl.keymap[code] = SCROLLLOCKKEY; break; case XK_F15: case XK_Pause: Ygl.keymap[code] = PAUSEKEY; break; default: Ygl.keymap[code] = 0; break; } wieoft[Ygl.keymap[code]]++; #if DEBUG > 2 if(ks != 0 || Ygl.keymap[code] != 0) fprintf(stderr, "code = %d, XK = 0x%x, dev = %d (%s)\n", code, ks, Ygl.keymap[code], Ygl.devicename(Ygl.keymap[code])); #endif } #ifdef DEBUG for(code = 1; code < sizeof(wieoft)/sizeof(wieoft[0]); code++) if(wieoft[code] > 1) { fprintf(stderr, "device %d (%s) is %d times defined\n", code, Ygl.devicename(code), wieoft[code]); } #endif /* Try to fix PAD keys, as Linux, Solaris and maybe others define them as * simple numeric keysyms (XK_0 instead of XK_KP_0) * Here we assume that the keypad keycodes are > than the normal codes */ { Device FixUs[][2] = { {ZEROKEY, PAD0}, {ONEKEY, PAD1}, {TWOKEY, PAD2}, {THREEKEY, PAD3}, {FOURKEY, PAD4}, {FIVEKEY, PAD5}, {SIXKEY, PAD6}, {SEVENKEY, PAD7}, {EIGHTKEY, PAD8}, {NINEKEY, PAD9}, {MINUSKEY, PADMINUS}, {RETKEY, PADENTER}, {PERIODKEY, PADCOMMA} }; int i; for(i = 0; i < sizeof(FixUs)/sizeof(FixUs[0]); i++) if(wieoft[FixUs[i][0]] == 2) { for(code = KEYMAP_LEN; code > 0 && Ygl.keymap[code] != FixUs[i][0]; code--); if(code > 0) { #ifdef DEBUG fprintf(stderr, "fixing keymap[%d] from %d (%s) -> %d (%s)\n", code, Ygl.keymap[code], Ygl.devicename(Ygl.keymap[code]), FixUs[i][1], Ygl.devicename(FixUs[i][1])); #endif Ygl.keymap[code] = FixUs[i][1]; } } } } } static void noinit(const char *caller) { Yprintf(caller, "Ygl not initialized, call winopen or ginit first.\n"); exit(1); } static int notimplemented(const char *caller) { char * mode; IFOGL(mode = "OpenGL", mode = "X11"); return Yprintf(caller, "not implemented in %s mode.\n", mode); } static int warn(const char *name, const char *format, ...) { int r; va_list Argp; va_start(Argp, format); r = fprintf(stderr, "Ygl: %s: ", name); r += vfprintf(stderr, format, Argp); va_end(Argp); return r; } static Int32 x2gl_wid(Window win, int which) { /* Computes Ygl wid from X wid */ Int32 i = Ygl.NextWindow - 1; switch(which) { case X2GL_MAIN: while(i > 0 && win != Ygl.Windows[i].main) i--; break; #ifdef RGBWIN case X2GL_TOP: while(i > 0 && win != Ygl.Windows[i].top ) i--; break; case X2GL_WIN: while(i > 0 && win != Ygl.Windows[i].win ) i--; break; case X2GL_DRAW: while(i > 0 && win != Ygl.Windows[i].draw) i--; break; #endif default: abort(); } return i; /* 0 if not found */ } /* Routines to scale Ygl coords to X11 coords. */ #define IFLOOR(x) (((int)(x)) - ((x) < 0 && (x) != ((double)(int)(x)) ? 1 : 0)) static int XRscale(double x) { x = x * W->xf + 0.5; return IFLOOR(x) ; } static int YRscale(double y) { y = y * W->yf + 0.5; return IFLOOR(y) ; } static int Xscale (double x) { x = (x - W->xo) * W->xf + 0.5; return IFLOOR(x) ; } static int Yscale (double y) { y = (W->yo - y) * W->yf + 0.5; return IFLOOR(y) + W->ym - 1; } static void await_windowevent(Window win, long mask, int type) { XEvent ev; #ifdef DEBUG fprintf(stderr, "await_windowevent: window 0x%x, waiting for %d(%s) with mask 0x%x\n", win, type, Ygl.XEventNames[type], mask); #endif do { XWindowEvent(D, win, mask, &ev); #ifdef DEBUG fprintf(stderr, "await_windowevent: received %d(%s)\n", ev.type, Ygl.XEventNames[ev.type]); #endif } while(ev.type != type); } static int is_wid(Int32 wid) { return wid > 0 && wid < Ygl.NextWindow && Ygl.Windows[wid].main != 0; } #if 0 static int errorHandler(Display *dpy, XErrorEvent *error) { char errortext[1024]; XGetErrorText(dpy, error->error_code, errortext, 1024); fprintf(stderr, "Ygl: X Error: %s on 0x%x.\n", errortext, error->resourceid); return False; } #endif #if 0 static int unused_colormaps(void) { /* returns number of unused colormaps */ int num; Colormap *cmaps = XListInstalledColormaps(D, Ygl.PWID, &num); #ifdef DEBUG fprintf(stderr,"unused_colormaps: %d of %d installed Colormaps\n", num, MaxCmapsOfScreen(DefaultScreenOfDisplay(D))); #endif XFree((char*) cmaps); return MaxCmapsOfScreen(DefaultScreenOfDisplay(D)) - num; } #endif /* 0 */ #ifdef AUTOFLUSH static void signal_handler(int sig_no) { #ifdef DEBUG fprintf(stderr, "In signal_handler, sig_no = %d\n", sig_no); #endif Ygl.flush = True; /* XFlush() at next possibility. Don't try to XFlush() * here, as it will totally screw up XLibs * internal buffers */ } #endif /* AUTOFLUSH */ static int ginit_badWindowHandler(Display *dpy, XErrorEvent *error) { Yprintf("ginit", "invalid window id 0x%x in YGL_PARENTWID.\n", error->resourceid); exit (1); } #define NUMVARS 9 static void get_environment(const char *caller) { /* Parse environment */ char *env; int v, i; int useogl = False; const char *names[NUMVARS][2] = { /* valid names of environment vars */ { "YGL_FLUSHTIME", "YGL_FT" }, { "YGL_PRIVATECOLORMAP", "YGL_PCM" }, { "YGL_BACKINGSTORE", "YGL_BS" }, { "YGL_SINGLEGC", "YGL_GC" }, { "YGL_CMAPVISUAL", "YGL_CV" }, { "YGL_RGBVISUAL", "YGL_RV" }, { "YGL_PARENTWID", "YGL_PWID"}, { "YGL_DITHERSIZE", "YGL_DSZ" }, { "YGL_USEOGL", "YGL_OGL" } }; Ygl.PWID = RootWindow(D, YglScreen); for(v = 0; v < NUMVARS; v++) { /* loop over vars */ for(i = 0; i < 2; i++) { /* loop over names */ if((env = getenv(names[v][i])) != NULL && env[0] != '\0') { i = 4711; /* Found, end of i loop */ switch(v) { case 0: Ygl.FT = 1000 * atof(env); break; case 1: Ygl.PCM = (strcmp(env,"1") == 0); break; /* Use private colormap */ case 2: Ygl.BS = (strcmp(env,"1") == 0); break; /* Use backing store */ case 3: Ygl.GC = (strcmp(env,"1") == 0); break; /* Use single graphics context */ case 4: Ygl.V[0] = (int) strtol(env, NULL, 0); break; /* Colormap Visual */ case 5: Ygl.V[1] = (int) strtol(env, NULL, 0); break; /* RGBmode Visual */ case 6: Ygl.PWID = (Window) strtol(env, NULL, 0); break;/* Parent window ID */ case 7: Ygl.DSZ = (int) strtol(env, NULL, 0); break; /* Size of dither matrix */ case 8: useogl = (int) strtol(env, NULL, 0); break; /* Use OpenGL routines */ } } } } #ifdef DEBUG fprintf(stderr, "get_environment: FT = %d, PCM = %d, BS = %d, GC = %d,\n" " V = {0x%x,0x%x}, PWID = 0x%x, DSZ = %d, UseOGL = %d\n", Ygl.FT, Ygl.PCM, Ygl.BS, Ygl.GC, Ygl.V[0], Ygl.V[1], Ygl.PWID, Ygl.DSZ, useogl); #endif { /* Check if PWID is valid window */ XWindowAttributes wa; int (*old_handler)(Display*, XErrorEvent*); old_handler = XSetErrorHandler(ginit_badWindowHandler); XGetWindowAttributes(D, Ygl.PWID, &wa); XSync(D, False); XSetErrorHandler(old_handler); } if(Ygl.DSZ < 0 || Ygl.DSZ > 6) { Yprintf(caller, "Invalid value of YGL_DSZ. Must be >= 0 and <= 6.\n"); exit(1); } Ygl.V[0] = (Ygl.V[0] == -1) ? DefaultVisual(D, YglScreen)->visualid : -1; Ygl.V[1] = (Ygl.V[1] == -1) ? DefaultVisual(D, YglScreen)->visualid : -1; #ifdef OGL Ygl.UseOGL = useogl; #else if(useogl == 1) { Yprintf(caller, "Ygl not compiled for OpenGL support, ignoring YGL_OGL.\n"); } #endif #ifndef X11 if(Ygl.UseOGL == 0) { Yprintf(caller, "Ygl not compiled for X11 support, ignoring YGL_OGL.\n"); Ygl.UseOGL = 1; } #endif } static void create_gc(const char *caller, Int32 id) { int i; Ulong mask = GCGraphicsExposures | GCLineWidth | GCForeground; XGCValues values; YglWindow *w = &Ygl.Windows[id]; values.graphics_exposures = False; /* so rectcopy won't generate * {Graphics|No}Expose events */ values.line_width = 0; /* default line width */ values.foreground = 0; /* fg color */ w->linewidth = 0; w->linestyle = 0; w->color = 0; if(w->rgb || Ygl.GC) { /* RGB windows have only one GC */ w->gc = XCreateGC(D, w->draw, mask, &values); w->chargc = w->gc; } else { w->chargc = XCreateGC(D, w->draw, mask, &values); if(NULL == (w->gclist = (GC*) calloc(CMapSize, sizeof(GC)))) { Yprintf(caller, "can't allocate memory.\n"); exit(1); } for(i = 0; i < CMapSize; i++) { values.foreground = i; w->gclist[i] = XCreateGC(D, w->draw, mask, &values); } w->gc = w->gclist[0]; } if(w->rgb && Ygl.DSZ > 1) { /* Initialize dithering */ Ulong mask = 0; XGCValues values; w->pm = XCreatePixmap(D, w->draw, Ygl.DSZ, Ygl.DSZ, YglDepth()); w->pmgc = XCreateGC(D, w->draw, mask, &values); w->pmi = XCreateImage(D, YglVisual(), YglDepth(), ZPixmap, 0, NULL, Ygl.DSZ, Ygl.DSZ, 8, 0); w->pmi->data = (char*) malloc(w->pmi->bytes_per_line * Ygl.DSZ); if(w->pmi->data == NULL) { Yprintf(caller, "can't allocate memory.\n"); exit(1); } w->red = w->green = w->blue = -1; } else { w->pm = 0; /* Used as flag for dithering */ } #ifdef DEBUG XSync(D, False); fprintf(stderr, "%s: create_gc: id=%d rgb=%d main=0x%x draw=0x%x gc=0x%x\n", caller, id, w->rgb, w->main, w->draw, w->gc); #endif } static void free_gc(Int32 id) { int i; YglWindow *w = &Ygl.Windows[id]; if(w->rgb || Ygl.GC) { XFreeGC(D, w->gc); w->gc = NULL; } else { for(i = 0; i < CMapSize; i++) { XFreeGC(D, w->gclist[i]); } XFreeGC(D, w->chargc); free(w->gclist); w->gclist = NULL; w->gc = NULL; w->chargc = NULL; } if(w->rgb && w->pm) { XFreeGC(D, w->pmgc); XFreePixmap(D, w->pm); free(w->pmi->data); XDestroyImage(w->pmi); w->pm = 0; } } static void clear_children(Int32 id) { Window root, parent, *children; Uint nchildren, n; Status r; #ifdef DEBUG fprintf(stderr, "clear_children: id = %d\n", id); #endif r = XQueryTree(D, Ygl.Windows[id].main, &root, &parent, &children, &nchildren); for(n = 0; n < nchildren; n++) { Int32 cid = x2gl_wid(children[n], X2GL_MAIN); if(cid) { clear_children(cid); Ygl.Windows[cid].main = 0; } } if(r) XFree((char*) children); } static Ulong parent_height(void) { XWindowAttributes pa; if(W->xpid == RootWindow(D, YglScreen)) { pa.height = DisplayHeight(D, YglScreen); } else { XGetWindowAttributes(D, W->xpid, &pa); } return pa.height; } static int translate_xy(int xi, int yi, int *xf, int *yf) { int r; Window junkwin; XTranslateCoordinates(D, W->xpid, W->main, xi, yi, xf, yf, &junkwin); r = (*xf != 0 || *yf != 0) ? 1 : 0; #ifdef DEBUG fprintf(stderr, "translate_xy: active=%d, xi=%d, yi=%d, xf=%d, yf=%d, r=%d\n", Ygl.ActiveWindow, xi, yi, *xf, *yf, r); #endif *xf += xi; *yf += yi; #ifdef DEBUG fprintf(stderr, " xf=%d, yf=%d\n", *xf, *yf); #endif return r; } static void set_cmapwins(const char *caller, const YglWindow *cw, int install) { Window *wins = (Window*)malloc((Ygl.NextWindow+2) * sizeof(Window)); Int32 id, num = 0; #ifdef RGBWIN if(cw->top == cw->main) { /* cw is top-level window, install RGB map first */ wins[num++] = cw->win; wins[num++] = cw->top; } else { /* We are subwindow, install RGB map last */ wins[num++] = cw->top; wins[num++] = cw->win; } #ifdef DEBUG fprintf(stderr, "%s: CMAP_WINS(0x%x): 0x%x 0x%x", caller, cw->top, wins[0], wins[1]); #endif #else /* RGBWIN */ wins[num++] = cw->top; #ifdef DEBUG fprintf(stderr, "%s: CMAP_WINS(0x%x): 0x%x", caller, cw->top, wins[0]); #endif #endif /* RGBWIN */ /* If any window is subwindow of me and has different color mode, * add to window list. One window is enough, as we only use two * colormaps (cmap mode, RGB mode) */ for(id = 1; id < Ygl.NextWindow; id++) { YglWindow *w = &Ygl.Windows[id]; if(w->top == cw->top /* is subwindow */ && wins[0] != IF_RGBWIN(w->win, w->main) /* not already in list */ ) { wins[num++] = IF_RGBWIN(w->win, w->main); #ifdef DEBUG fprintf(stderr, " 0x%x", wins[num-1]); #endif } } if((!install) || (num == 1 && cw->top == wins[0])) { /* Don't install redundant window info */ /* Changed last arg from True to False due to problems with XServer * in RedHat 6.0. Thx to * Frederick W. Koehler IV & * Kristina L. Klinkner */ Atom WM_C_W = XInternAtom(D, "WM_COLORMAP_WINDOWS", False); #ifdef DEBUG fprintf(stderr, " clearing\n"); #endif XDeleteProperty(D, cw->top, WM_C_W); } else { #ifdef DEBUG fprintf(stderr, " installing\n"); #endif if(XSetWMColormapWindows(D, cw->top, wins, num) == 0) { Yprintf(caller, "cannot change WM_COLORMAP_WINDOWS property.\n"); } } free(wins); } #ifdef OGL static void create_main_window_ogl(const char *caller, YglWindow *w) { GLXContext oldcx = w->cx; /* If saved from gconfig() */ if(NULL == (w->cx = glXCreateContext(D, w->rgb ? &Ygl.RV : &Ygl.CV, NULL, True))) { Yprintf(caller, "cannot create context.\n"); exit(1); } if(oldcx) { if (Ygl.CV.visualid != Ygl.RV.visualid) { /* copy state from window with other mode */ glXCopyContext(D, oldcx, w->cx, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | /* GL_LIGHTING_BIT lighting fails when copied | */ GL_LINE_BIT | GL_POINT_BIT | GL_POLYGON_BIT | GL_POLYGON_STIPPLE_BIT | GL_TRANSFORM_BIT | GL_VIEWPORT_BIT); glXDestroyContext(D, oldcx); } else { glXDestroyContext(D, w->cx); w->cx = oldcx; } } glXMakeCurrent(D, w->main, w->cx); /* Before anything else */ /* Initialize */ glDrawBuffer(w->dbuf ? GL_BACK : GL_FRONT); if(!oldcx) { #if 0 w->circ = gluNewQuadric(); /* circ() */ gluQuadricDrawStyle(w->circ, GLU_SILHOUETTE); w->circf = gluNewQuadric(); /* circf() */ gluQuadricDrawStyle(w->circf, GLU_FILL); #endif ortho2 (0.0, w->xm - 1.0, 0.0, w->ym - 1.0); /* set X11 default scale */ viewport(0 , w->xm - 1 , 0 , w->ym - 1 ); /* set X11 default viewport */ } if(glXIsDirect(D, w->cx)) Yprintf(caller, "direct rendering enabled.\n"); /* * Some optimization settings * Moved to here as glColorMask() fails in setup_visuals under MacOSX */ /* glEnable(GL_NORMALIZE); GL sets this */ /* glEnable(GL_ALPHA_TEST); */ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); /* from OpenGL README */ /* Yprintf(caller, "alpha writes disabled.\n"); */ } #endif static void create_main_window(const char *caller, const char *Title, int x, int y, Uint width, Uint height) { XSetWindowAttributes swa; Ulong swa_mask = 0; YglWindow *w = W; int we_are_top; XWMHints xwmh; XClassHint xch; #ifdef DEBUG fprintf(stderr, "create_main_window: '%s': (x,y) = (%d,%d), (w,h) = (%d,%d)\n", Title, x, y, width, height); #endif we_are_top = w->pid == 0 && Ygl.PWID == RootWindow(D, YglScreen); swa.background_pixel = WhitePixel(D,YglScreen); swa.border_pixel = WhitePixel(D,YglScreen); swa.colormap = YglColormap(); swa.cursor = YglCursor; swa_mask = CWBackPixel | CWBorderPixel | CWColormap | CWCursor; if(!we_are_top) { /* Used with subwindows and with YGL_PWID, * as window positions count from leftlower corner in Ygl. * Don't do this with normal WM-controlled windows. */ swa.win_gravity = SouthWestGravity; swa_mask |= CWWinGravity; } if(Ygl.BS) { swa.backing_store = Always; swa_mask |= CWBackingStore; } w->main = XCreateWindow(D, w->xpid, x, y, width, height, 0, /* BorderWidth */ YglDepth(), /* Depth */ InputOutput, /* Class */ YglVisual(), swa_mask, &swa); w->draw = IF_RGBWIN(w->win = w->main, w->main); if(we_are_top) { /* We are top-level window created by winopen() */ w->top = w->main; } else if(w->pid == 0) { /* Created by winopen() and YGL_PWID was set */ w->top = Ygl.PWID; } else { /* Copy from parent */ w->top = Ygl.Windows[w->pid].top; } set_cmapwins(caller, w, 1); create_gc(caller, Ygl.ActiveWindow); XStoreName(D, w->main, Title); xwmh.flags = StateHint | InputHint; xwmh.input = True; xwmh.initial_state = NormalState; XSetWMHints(D, w->main, &xwmh); xch.res_name = (char*)Title; xch.res_class = "Ygl"; XSetClassHint(D, w->main, &xch); IFOGL(create_main_window_ogl(caller, w), ortho2 (0.0, w->xm - 1.0, 0.0, w->ym - 1.0); /* set X11 default scale */ viewport(0 , w->xm - 1 , 0 , w->ym - 1 ) /* set X11 default viewport */ ); winconstraints(); font(0); /* Set default font to "fixed" */ #if 1 if(MaxCmapsOfScreen(DefaultScreenOfDisplay(D)) > 1) { /* if(1 || unused_colormaps() > 0) { */ XInstallColormap(D, YglColormap()); #ifdef DEBUG fprintf(stderr,"create_main_window: Installing Colormap\n"); #endif } #endif } static YglWindow *find_new_window_id(const char *caller) { Ygl.ActiveWindow = 1; while(is_wid(Ygl.ActiveWindow)) Ygl.ActiveWindow++; if(Ygl.ActiveWindow == Ygl.NextWindow) { Ygl.NextWindow++; if(NULL == (Ygl.Windows = (YglWindow*) realloc(Ygl.Windows, Ygl.NextWindow * sizeof(YglWindow)))) { Yprintf(caller, "can't allocate memory.\n", caller); exit(1); } } return W = &Ygl.Windows[Ygl.ActiveWindow]; } static Int32 win_open(const char *caller, const char *Title, Int32 pid, Window xpid) { YglWindow *w; w = find_new_window_id(caller); /* Get new W */ /* Setup window structure */ w->pid = pid; w->xpid = xpid; if(YglSizeHints.flags & PMinSize) { w->xm = YglSizeHints.min_width; w->ym = YglSizeHints.min_height; } else { w->xm = 100; w->ym = 100; } /* flip-fix y relative to parent window */ YglSizeHints.y = parent_height() - w->ym - YglSizeHints.y; w->xp = w->yp = w->xc = w->yc = 0; YglRGB = w->rgb = False; /* New windows are always in cmode */ w->mapped = False; /* window is not mapped yet */ w->dbuf = False; /* New windows are always in singlebuffer mode */ w->clipped = False; /* No clipping activated */ w->vmode = VertexNone; w->pm = 0; /* Used in draw.c:pnt2() */ w->vw = w->xm; /* else set_scales() crashes the first time */ w->vh = w->ym; #ifdef OGL w->zp = w->zc = 0; w->cx = NULL; #endif create_main_window(caller, Title, YglSizeHints.x, YglSizeHints.y, w->xm, w->ym); return Ygl.ActiveWindow; } static Window get_parent(Window win) { Window root, parent, *children; Uint nchildren; if(XQueryTree(D, win, &root, &parent, &children, &nchildren)) XFree((char*) children); return parent; } static Window get_real_parent(Window win) { Window root, parent, *children; Uint nchildren; Status r; int (*old_handler)(Display*, XErrorEvent*); Atom WM_STATE = XInternAtom(D, "WM_STATE", True); Atom type = None; old_handler = XSetErrorHandler(winX_badWindowHandler); r = XQueryTree(D, win, &root, &parent, &children, &nchildren); XSync (D, False); XSetErrorHandler(old_handler); if(r) XFree((char*) children); while(1) { int format; unsigned long nitems, after; unsigned char *data; if(parent == root) break; /* win is maindow, no WM */ /* Find a window with WM_STATE as per ICCCM */ if(XGetWindowProperty(D, parent, WM_STATE, 0, 0, False, AnyPropertyType, &type, &format, &nitems, &after, &data)) XFree(data); if(type) break; win = parent; if(XQueryTree(D, win, &root, &parent, &children, &nchildren)) XFree((char*) children); #ifdef DEBUG fprintf(stderr, "get_real_parent: root=0x%x, win=0x%x, parent=0x%x\n", /**/ root , win , parent); #endif } return parent; } /* Initialization (constraints) */ void minsize(Int32 x, Int32 y) { YglSizeHints.min_width = x; YglSizeHints.min_height = y; YglSizeHints.flags |= PMinSize; } void maxsize(Int32 x, Int32 y) { YglSizeHints.max_width = x; YglSizeHints.max_height = y; YglSizeHints.flags |= PMaxSize; } void prefsize(Int32 x, Int32 y) { YglSizeHints.width = x; YglSizeHints.height = y; YglSizeHints.flags |= PSize; YglSizeHints.flags |= USSize; minsize(x, y); maxsize(x, y); } void prefposition(Int32 x1, Int32 x2, Int32 y1, Int32 y2) { YglSizeHints.x = x1; YglSizeHints.y = y1; YglSizeHints.flags |= PPosition; YglSizeHints.flags |= USPosition; prefsize(x2 - x1 + 1, y2 - y1 + 1); } void stepunit(Int32 x, Int32 y) { YglSizeHints.width_inc = x; YglSizeHints.height_inc = y; YglSizeHints.flags |= PResizeInc; } void keepaspect(Int32 x, Int32 y) { YglSizeHints.min_aspect.x = YglSizeHints.max_aspect.x = x; YglSizeHints.min_aspect.y = YglSizeHints.max_aspect.y = y; YglSizeHints.flags |= PAspect; } void noport(void) { YglMapNext = False; } void noborder(void) { /* Do nothing... */ } static void setup_shift_and_mask(void) { /* Determine shift value */ Ygl.rs = 0; while (!((1 << Ygl.rs) & Ygl.RMask)) Ygl.rs++; Ygl.gs = 0; while (!((1 << Ygl.gs) & Ygl.GMask)) Ygl.gs++; Ygl.bs = 0; while (!((1 << Ygl.bs) & Ygl.BMask)) Ygl.bs++; /* Determine mask widths */ Ygl.rb = 0; while ( (1 << (Ygl.rs + Ygl.rb)) & Ygl.RMask) Ygl.rb++; Ygl.gb = 0; while ( (1 << (Ygl.gs + Ygl.gb)) & Ygl.GMask) Ygl.gb++; Ygl.bb = 0; while ( (1 << (Ygl.bs + Ygl.bb)) & Ygl.BMask) Ygl.bb++; #ifdef DEBUG fprintf(stderr,"setup_visuals: Shift = (%d,%d,%d), width = (%d,%d,%d)\n", Ygl.rs, Ygl.gs, Ygl.bs, Ygl.rb, Ygl.gb, Ygl.bb); #endif /* We need it in this form in RGBcolor ... */ Ygl.rb = 8-Ygl.rb; Ygl.gb = 8-Ygl.gb; Ygl.bb = 8-Ygl.bb; } #define BETTER_VISUAL(oldi,newi) ( ((oldi) == -1 || xv[oldi].depth < xv[newi].depth) ? (newi) : (oldi) ) #ifdef OGL static int setup_visuals_ogl(const char *caller) { /* find Visuals */ int junk[2]; int rgblist[] = {GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DEPTH_SIZE, 16, None}; int cmaplist[] = {GLX_DOUBLEBUFFER, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, None}; XVisualInfo *xv; if(!glXQueryExtension(D, junk, junk + 1)) { Yprintf(caller, "X server has no OpenGL GLX extension.\n"); return False; } if((xv = glXChooseVisual(D, YglScreen, rgblist))) { memcpy(&Ygl.RV, xv, sizeof(XVisualInfo)); XFree((char*)xv); setup_shift_and_mask(); } else { Yprintf(caller, "no OpenGL RGB visual found.\n"); return False; } if((xv = glXChooseVisual(D, YglScreen, cmaplist))) { memcpy(&Ygl.CV, xv, sizeof(XVisualInfo)); XFree((char*)xv); } else { Yprintf(caller, "no OpenGL colormap visual found, emulating using visual 0x%x.\n", Ygl.RV.visualid); memcpy(&Ygl.CV, &Ygl.RV, sizeof(XVisualInfo)); Ygl.EmulateCmap = True; CMapSize = 1 << EMULATE_CMAP_DEPTH; /*return False;*/ } /*Ygl.RCmap = XCreateColormap(D, Ygl.PWID, Ygl.RV.visual, AllocNone);*/ /*Ygl.CCmap = XCreateColormap(D, Ygl.PWID, Ygl.CV.visual, AllocAll);*/ #ifdef DEBUG fprintf(stderr, "setup_visuals: CMap VisualID = 0x%x, Depth = %d, CMEntries = %d, Ygl.stat = %d\n" " RGB VisualID = 0x%x, Depth = %d, CMEntries = %d\n", Ygl.CV.visualid, Ygl.CV.depth, Ygl.CV.colormap_size, Ygl.stat, Ygl.RV.visualid, Ygl.RV.depth, Ygl.RV.colormap_size); #endif return True; } #endif /* OGL */ #ifdef X11 static int setup_visuals_x11(const char *caller) { /* find best X11 Visuals */ XVisualInfo xvproto, *xv; /* Note: Some implementations have VisualID == 0 */ int Pseudoi = -1, Grayi = -1, Truei = -1, Directi = -1, SColori = -1, SGrayi = -1, Useri0 = -1, Useri1 = -1; int xvn, i = 0; xvproto.screen = YglScreen; xv = XGetVisualInfo(D, VisualScreenMask, &xvproto, &xvn); /* Find best visual of each class */ for(i = 0; i < xvn; i++) switch(xv[i].class) { case StaticGray: SGrayi = BETTER_VISUAL(SGrayi , i); break; case GrayScale: Grayi = BETTER_VISUAL(Grayi , i); break; case StaticColor: SColori = BETTER_VISUAL(SColori, i); break; case PseudoColor: Pseudoi = BETTER_VISUAL(Pseudoi, i); break; case TrueColor: Truei = BETTER_VISUAL(Truei , i); break; case DirectColor: Directi = BETTER_VISUAL(Directi, i); break; default: Yprintf(caller, "unknown visual class: %d.\n", xv[i].class); break; } /* Find best colormap mode visual */ if(Ygl.V[0] != -1) { for(i = 0; i < xvn; i++) if(Ygl.V[0] == xv[i].visualid) Useri0 = i; if(Useri0 == -1) Yprintf(caller, "VisualID 0x%x not found, using default.\n", Ygl.V[0]); else { switch(xv[Useri0].class) { case DirectColor: /* Consider as static */ case TrueColor: Ygl.GC = True; Ygl.EmulateCmap = True; case StaticGray: case StaticColor: Ygl.stat = True; break; case GrayScale: case PseudoColor: break; default: Yprintf(caller, "VisualID 0x%x invalid for colormap mode, using default.\n", Ygl.V[0]); Useri0 = -1; break; } } } /* Find best RGBmode visual */ if(Ygl.V[1] != -1) { for(i = 0; i < xvn; i++) if(Ygl.V[1] == xv[i].visualid) Useri1 = i; if(Useri1 == -1) Yprintf(caller, "VisualID 0x%x not found, using default.\n", Ygl.V[1]); else { switch(xv[Useri1].class) { case TrueColor: case DirectColor: break; default: Yprintf(caller, "VisualID 0x%x invalid for RGBmode, using default.\n", Ygl.V[1]); Useri1 = -1; break; } } } if (Useri0 >= 0) i = Useri0; else if (Pseudoi >= 0) i = Pseudoi; else if (SColori >= 0){i = SColori; Ygl.stat = True; } else if (Grayi >= 0) i = Grayi; else if (SGrayi >= 0){i = SGrayi; Ygl.stat = True; } else if (Truei >= 0){i = Truei; Ygl.GC = Ygl.stat = Ygl.EmulateCmap = True; } else if (Directi >= 0){i = Directi; Ygl.GC = Ygl.stat = Ygl.EmulateCmap = True; } else { Yprintf(caller, "no appropiate visual found.\n"); return False; } if(i >= 0) { memcpy(&Ygl.CV, xv+i, sizeof(XVisualInfo)); if(Ygl.EmulateCmap) { CMapSize = 1 << EMULATE_CMAP_DEPTH; } if(Ygl.GC == False && CMapSize > MAX_MULTIGC_CMAPSIZE) { Ygl.GC = True; #ifdef DEBUG fprintf(stderr, "setup_visuals: CMapSize > %d, using single GC.\n", MAX_MULTIGC_CMAPSIZE); #endif } } if (Useri1 >= 0) i = Useri1; else if (Truei >= 0) i = Truei; else if (Directi >= 0) i = Directi; else i = -1; if(i >= 0) { memcpy(&Ygl.RV, xv+i, sizeof(XVisualInfo)); setup_shift_and_mask(); } XFree((char*) xv); #ifdef DEBUG fprintf(stderr, "setup_visuals: CMap VisualID = 0x%x, Depth = %d, CMEntries = %d, Ygl.stat = %d\n" " RGB VisualID = 0x%x, Depth = %d, CMEntries = %d\n", Ygl.CV.visualid, Ygl.CV.depth, Ygl.CV.colormap_size, Ygl.stat, Ygl.RV.visualid, Ygl.RV.depth, Ygl.RV.colormap_size); #endif return True; } #endif /* X11 */ static int setup_visuals(const char *caller) { /* find Visuals */ #ifdef OGL if(Ygl.UseOGL) Ygl.UseOGL = setup_visuals_ogl(caller); if(Ygl.UseOGL) return True; /* OK, use OpenGL */ #endif #ifdef X11 return setup_visuals_x11(caller); #else return False; #endif } Int32 gversion(Char8 *v) { const char * MyName = "gversion"; const char * version_x11 = "Ygl:X11-" VERSION; const char * version_ogl = "Ygl:OGL-" VERSION; const char * version; int r, useogl; if(D == NULL) { YglControl tmp; memcpy(&tmp, &Ygl, sizeof(Ygl)); /* Save a copy of fresh struct */ D = XOpenDisplay(NULL); if(D == NULL) { r = False; } else { get_environment(MyName); r = setup_visuals(MyName); XCloseDisplay(D); } #ifdef OGL useogl = Ygl.UseOGL; #endif memcpy(&Ygl, &tmp, sizeof(Ygl)); /* Restore */ #ifdef OGL Ygl.UseOGL = useogl; #endif } else { r = True; } IFOGL(version = version_ogl, version = version_x11); strncpy(v, version, 12); v[11] = '\0'; return r ? 0 : -1; } #ifdef HASXMU static void find_colormap_xmu(void) { XStandardColormap *stdcmap; int num, r, i, found = False; Atom map; switch(Ygl.CV.class) { case StaticGray: map = XA_RGB_GRAY_MAP; break; case StaticColor: map = XA_RGB_BEST_MAP; break; case GrayScale: map = XA_RGB_GRAY_MAP; break; case PseudoColor: map = XA_RGB_DEFAULT_MAP; break; } r = XmuLookupStandardColormap(D, YglScreen, Ygl.CV.visualid, Ygl.CV.depth, map, False, True); #ifdef DEBUG fprintf(stderr, "ginit: XmuLookupStandardColormap = %d\n", r); #endif r = XGetRGBColormaps(D, Ygl.PWID, &stdcmap, &num, map); for(i = 0; i < num; i++) if(stdcmap[i].visualid == Ygl.CV.visualid) { Ygl.CCmap = stdcmap[i].colormap; found = True; } if(!found) { Yprintf(caller, "no appropiate standard colormap installed.\n"); exit(1); } } #endif /* HASXMU */ static void setup_colormaps(const char *caller) { struct colors_ { Ushort red, green, blue; const char *name; } colors[] = { { 0, 0, 0, "black" }, {65535, 65535, 65535, "white" }, { 0, 65535, 0, "green" }, {65535, 65535, 0, "yellow" }, { 0, 0, 65535, "blue" }, {65535, 0, 65535, "magenta"}, { 0, 65535, 65535, "cyan" }, {65535, 0, 0, "red" } }; int i; if(!Ygl.PCM) { /* use global colormap */ #ifdef HASXMU find_colormap_xmu(void); #else /* HASXMU */ if(Ygl.CV.visual == DefaultVisual(D, YglScreen)) { Ygl.CCmap = DefaultColormap(D, YglScreen); } else { Ygl.CCmap = XCreateColormap(D, Ygl.PWID, Ygl.CV.visual, AllocNone); } #endif /* HASXMU */ if(NULL == (Ygl.Colors = (Ulong*) calloc(CMapSize, sizeof(Ulong)))) { Yprintf(caller, "can't allocate memory.\n"); exit(1); } if(!Ygl.EmulateCmap) { if(NULL == (Ygl.ColorsInv = (Ulong*) calloc(CMapSize, sizeof(Ulong)))) { Yprintf(caller, "can't allocate memory.\n"); exit(1); } } for(i = 0; i < MIN(8,CMapSize); i++) { /* define only allocated colors, * others may change */ XColor xc; xc.red = colors[i].red; xc.green = colors[i].green; xc.blue = colors[i].blue; xc.flags = DoRGB; if(XAllocColor(D, Ygl.CCmap, &xc)) { Ygl.Colors[i] = xc.pixel; if(!Ygl.EmulateCmap) Ygl.ColorsInv[xc.pixel] = i; #ifdef DEBUG fprintf(stderr, "alloc color '%s', i = %d, pixel = 0x%x (%d,%d,%d)\n", colors[i].name, i, xc.pixel, xc.red, xc.green, xc.blue); #endif } else { Yprintf(caller, "can't allocate color %s = {%d,%d,%d}\n", colors[i].name, colors[i].red, colors[i].green, colors[i].blue); } } } else { /* PCM */ XColor *xcs; if(Ygl.stat) { Yprintf(caller, "can't use private colormap on static visuals.\n"); exit(1); } Ygl.CCmap = XCreateColormap(D, Ygl.PWID, Ygl.CV.visual, AllocAll); /* copy default colormap to reduce technicolor effects */ if(NULL == (xcs = (XColor*) calloc(CMapSize, sizeof(XColor)))) { Yprintf(caller, "can't allocate memory.\n"); exit(1); } for(i = 0; i < CMapSize; i++) xcs[i].pixel = i; XQueryColors(D, DefaultColormap(D, YglScreen), xcs, CMapSize); for(i = 0; i < MIN(8,CMapSize); i++) { xcs[CMapSize - 1 - i].red = colors[i].red; xcs[CMapSize - 1 - i].green = colors[i].green; xcs[CMapSize - 1 - i].blue = colors[i].blue; } XStoreColors(D, Ygl.CCmap, xcs, CMapSize); free(xcs); } /* PCM */ if(Ygl.RV.visual) { Ygl.RCmap = XCreateColormap(D, Ygl.PWID, Ygl.RV.visual, AllocNone); } } #if DEBUG > 10 static int syncfn(Display *dpy) { fprintf(stderr, "Sync\n"); return XSync(dpy, False); } #endif void ginit(void) { const char * MyName = "ginit"; if ((D = XOpenDisplay(NULL)) == NULL) { Yprintf(MyName, "can\'t open display \"%s\".\n", XDisplayName(NULL)); exit(1); } /* allocate one window structure. The first window(0) is never used...*/ if(NULL == (Ygl.Windows = (YglWindow*) calloc(1, sizeof(YglWindow)))) { Yprintf(MyName, "can't allocate memory.\n"); exit(1); } Ygl.ActiveWindow = 0; Ygl.NextWindow = 1; /* GL seems to set these... (see header.h) */ Ygl.EventMask = EnterLeaveMask | RedrawMask; get_environment(MyName); #ifndef DEBUG /* XSetErrorHandler(errorHandler); */ #endif if(setup_visuals(MyName) == False) exit(1); setup_colormaps(MyName); if(Ygl.FT == -1000) { Yprintf(MyName, "switching to synchronous mode.\n"); XSynchronize(D, True); } else if(Ygl.FT > 0) { #ifdef AUTOFLUSH struct itimerval itimer, otimer; struct sigaction action, oaction; itimer.it_interval.tv_sec = Ygl.FT / 1000; itimer.it_value.tv_sec = Ygl.FT / 1000; itimer.it_interval.tv_usec = (Ygl.FT % 1000) * 1000; itimer.it_value.tv_usec = (Ygl.FT % 1000) * 1000; Ygl.flush = False; action.sa_handler = signal_handler; sigfillset(&action.sa_mask); action.sa_flags = 0; if(sigaction(SIGVTALRM, &action, &oaction)) { perror(MyName); exit(1); } if(oaction.sa_handler) Yprintf(MyName, "warning: SIGVTALRM already used.\n"); setitimer(ITIMER_VIRTUAL, &itimer, &otimer); #endif /* AUTOFLUSH */ } #if DEBUG > 10 fprintf(stderr, "DEBUG: setting XSetAfterFunction(D, syncfn)\n"); XSetAfterFunction(D, syncfn); #elif DEBUG > 1 fprintf(stderr, "DEBUG: setting XSynchronize(D, True)\n"); XSynchronize(D, True); #endif loadXfont(0, "fixed"); Ygl.wm_dw = XInternAtom(D, "WM_DELETE_WINDOW", False); YglCursor = XCreateFontCursor(D, XC_left_ptr); { XColor fg, bg; bg.red = 0 ; bg.green = 0 ; bg.blue = 0xffff; fg.red = 0xffff; fg.green = 0xffff; fg.blue = 0 ; XRecolorCursor(D, YglCursor, &fg, &bg); } if(Ygl.RV.depth >= 24) { #ifdef DEBUG fprintf(stderr, "Won't dither, depth >= 24\n"); #endif Ygl.DSZ = 0; /* Don't need to dither if we have 24 bits */ } init_keymap(); } void winconstraints(void) { const char * MyName = "winconstraints"; YglWindow *w = W; I(MyName, ""); XSetWMNormalHints(D, w->main, &YglSizeHints); if(YglMapNext && !w->mapped) { /* Map window? */ #ifdef DEBUG fprintf(stderr, "winconstraints: Mapping window %d\n", Ygl.ActiveWindow); #endif XSelectInput(D, w->main, StructureNotifyMask | ExposureMask); /* So we get the MapNotify and the first Exposure(REDRAW) event */ w->mapped = True; XMapWindow(D, w->main); #ifdef RGBWIN if(w->rgb) XMapWindow(D, w->win); #endif Ygl.await_windowevent(w->main, StructureNotifyMask, MapNotify); if(YglSizeHints.flags & PPosition && get_parent(w->main) != w->xpid) { /* Fix window position gobbled by window manager */ int xf, yf; #ifdef DEBUG fprintf(stderr, "winconstraints: Moving to (%d,%d)\n", YglSizeHints.x, YglSizeHints.y); #endif XMoveWindow(D, w->main, YglSizeHints.x, YglSizeHints.y); Ygl.await_windowevent(w->main, StructureNotifyMask, ConfigureNotify); if(translate_xy(YglSizeHints.x, YglSizeHints.y, &xf, &yf)) { #ifdef DEBUG fprintf(stderr, "winconstraints: Moving to (%d,%d)\n", xf, yf); #endif XMoveWindow(D, w->main, xf, yf); Ygl.await_windowevent(w->main, StructureNotifyMask, ConfigureNotify); } } XSetWMProtocols(D, w->main, &Ygl.wm_dw, Ygl.wm_dw_flag ? 1 : 0); XSelectInput(D, w->main, Ygl.EventMask); #ifdef RGBWIN if(w->rgb) /* Expose events don't propagate */ XSelectInput(D, w->win, Ygl.EventMask & ExposureMask); #endif qenter(REDRAW, Ygl.ActiveWindow); } else if(w->mapped && !YglMapNext) { /* unmap window */ #ifdef DEBUG fprintf(stderr, "winconstraints: Unmapping window %d\n", Ygl.ActiveWindow); #endif XUnmapWindow(D, w->main); w->mapped = False; } /* Reinit constraints */ memset(&YglSizeHints, 0, sizeof(XSizeHints)); /* clear YglSizeHints */ YglMapNext = True; /* YglSizeHints.flags |= PSize; YglSizeHints.width = 100; YglSizeHints.height = 100; */ } Int32 winopen(char *Title) { const char * MyName = "winopen"; if(D == NULL) ginit(); /* first window */ #if 0 if(0 == (YglSizeHints.flags & PMinSize)) minsize(40,30); if(0 == (YglSizeHints.flags & PMaxSize)) maxsize(YglScreenWidth, YglScreenHeight); #endif return win_open(MyName, Title, 0, Ygl.PWID); } Int32 swinopen(Int32 pid) { const char * MyName = "swinopen"; I(MyName, "%d", pid); if(is_wid(pid)) { return win_open(MyName, NULL, pid, Ygl.Windows[pid].main); } else { Yprintf(MyName, "parent does not exist: %d.\n", pid); return 0; } } void winposition(Int32 x1, Int32 x2, Int32 y1, Int32 y2) { const char * MyName = "winposition"; YglWindow *w = W; int x, y; I(MyName, "%d,%d,%d,%d", x1, x2, y1, y2 ); x = x1; y = parent_height() - 1 - y2; if(get_parent(w->main) != w->xpid) { /* Fix window position gobbled by window manager */ int xf, yf; XSelectInput(D, w->main, StructureNotifyMask); XMoveResizeWindow(D, w->main, x, y, x2 - x1 + 1, y2 - y1 + 1); #ifdef DEBUG XSync(D, False); #else Ygl.await_windowevent(w->main, StructureNotifyMask, ConfigureNotify); #endif XSelectInput(D, w->main, Ygl.EventMask); if(translate_xy(x, y, &xf, &yf)) XMoveWindow(D, w->main, xf, yf); } else { XMoveResizeWindow(D, w->main, x, y, x2 - x1 + 1, y2 - y1 + 1); } } void winmove(Int32 x, Int32 y) { const char * MyName = "winmove"; Int32 xs, ys; I(MyName, "%d,%d", x, y); getsize(&xs, &ys); XMoveWindow(D, W->main, x, parent_height() - y - ys); } void getsize(Int32 *x, Int32 *y) { const char * MyName = "getsize"; XWindowAttributes wa; I(MyName, "*,*"); XGetWindowAttributes(D, W->main, &wa); *x = wa.width; *y = wa.height; } void getorigin(Int32 *x, Int32 *y) { /* Return the position of * the lower left corner of the drawing area relative to * the lower left corner of the parent window * WRONG! relative to Ygl.PWID (normally root) */ const char * MyName = "getorigin"; XWindowAttributes wa, pa; Window junkwin; int rx, ry; I(MyName, "*,*"); XGetWindowAttributes(D, W->main, &wa); XTranslateCoordinates(D, W->main, Ygl.PWID, -wa.border_width, -wa.border_width, &rx, &ry, &junkwin); if(Ygl.PWID == RootWindow(D, YglScreen)) { pa.height = DisplayHeight(D, YglScreen); } else { XGetWindowAttributes(D, Ygl.PWID, &pa); } *x = rx; *y = pa.height - (wa.height + ry); #ifdef DEBUG fprintf(stderr, "getorigin: %d %d, returning %d %d\n", rx, ry, *x, *y); #endif } void RGBmode(void) { /* switch the window active on next gconfig() to RGB mode */ YglRGB = True; } void cmode(void) { /* switch the window active on next gconfig() to colormap mode */ YglRGB = False; } #ifdef RGBWIN static void create_RGB_window(const char *caller) { XSetWindowAttributes swa; Ulong swa_mask = 0; YglWindow *w = W; #ifdef DEBUG fprintf(stderr, "create_RGB_window: (w,h) = (%d,%d)\n", w->xm, w->ym); #endif /*swa.background_pixel = WhitePixel(D,YglScreen);*/ swa.colormap = Ygl.RCmap; swa.cursor = YglCursor; swa_mask = /*CWBackPixel|*/CWColormap | CWCursor; if(Ygl.BS) { swa.backing_store = Always; swa_mask |= CWBackingStore; } w->draw = w->win = XCreateWindow(D, w->main, 0, 0, w->xm, w->ym, 0, /* BorderWidth */ Ygl.RV.depth, /* Depth */ InputOutput, /* Class */ Ygl.RV.visual, swa_mask, &swa); XStoreName(D, w->win, "RGB"); XSelectInput(D, w->win, StructureNotifyMask); XMapWindow(D, w->win); Ygl.await_windowevent(w->win, StructureNotifyMask, MapNotify); XSelectInput(D, w->win, Ygl.EventMask & ExposureMask); XLowerWindow(D, w->win); /* So it does not obscure any subwindows */ } static void destroy_RGB_window(const char *caller) { YglWindow *w = W; XEvent ev; XDestroyWindow(D, w->win); XSync(D, False); while(XCheckWindowEvent(D, w->win, Ygl.EventMask, &ev)) { #ifdef DEBUG fprintf(stderr, "destroy_RGB_window: dropped %d(%s) for window 0x%x\n", ev.type, Ygl.XEventNames[ev.type], w->win); #endif } w->draw = w->win = w->main; } #endif /* RGBWIN */ #ifdef OGL static int destroycontext = True; #endif void gconfig(void) { const char * MyName = "gconfig"; YglWindow *w = W; short dbuf; #ifndef RGBWIN XWindowAttributes wa; Window junkwin; int x, y; char *Title; #endif I(MyName, ""); if(YglRGB == w->rgb) return; /* no mode change */ if(Ygl.RV.visual == NULL) { Yprintf(MyName, "RGBmode requires a TrueColor or DirectColor visual.\n"); exit(1); } dbuf = w->dbuf; #ifdef RGBWIN singlebuffer(); free_gc(Ygl.ActiveWindow); #else /* RGBWIN */ /* Save state of active window */ XGetWindowAttributes(D, w->main, &wa); XTranslateCoordinates(D, w->main, w->xpid, -wa.border_width/*-wa.x*/, -wa.border_width/*-wa.y*/, &x, &y, &junkwin); XFetchName(D, w->main, &Title); XGetNormalHints(D, w->main, &YglSizeHints); /* ??? */ #ifdef DEBUG fprintf(stderr,"gconfig: Title = '%s', x = %d, y = %d, xt = %d, yt = %d\n", Title, wa.x, wa.y, x, y); #endif /* And close it */ #ifdef OGL destroycontext = False; #endif winclose(Ygl.ActiveWindow); #endif /* RGBWIN */ w->rgb = YglRGB; /* Switch to new mode */ #ifdef RGBWIN if(YglRGB) { /* switch to RGB */ create_RGB_window(MyName); } else { /* switch to cmap */ destroy_RGB_window(MyName); } create_gc(MyName, Ygl.ActiveWindow); font(0); /* Set default font to "fixed" */ #else /* RGBWIN */ /* And open a new one with other visual at same place */ YglSizeHints.x = x; YglSizeHints.y = y; YglSizeHints.flags |= PPosition | USPosition; YglMapNext = w->mapped; /* map if window was mapped */ w->mapped = False; /* window is not mapped yet */ create_main_window(MyName, Title, x, y, wa.width, wa.height); XFree(Title); #endif /* RGBWIN */ /*set_cmapwins(MyName, w, 1);*/ if(dbuf) doublebuffer(); } void winclose(Int32 id) { const char * MyName = "winclose"; XEvent ev; I(MyName, "%d", id); if(is_wid(id)) { Int32 active = winget(); YglWindow *w = &Ygl.Windows[id]; set_cmapwins(MyName, w, 0); /* Remove from list */ free_gc(id); clear_children(id); /* marks all children as closed */ winset(id); singlebuffer(); if (Ygl.Windows[active].main != 0) winset(active); else winset(1); #ifdef RGBWIN if(w->rgb) destroy_RGB_window(MyName); #endif #ifdef OGL if(Ygl.UseOGL) { glXMakeCurrent(D, None, NULL); #if 0 gluDeleteQuadric(w->circ); gluDeleteQuadric(w->circf); #endif if(destroycontext) glXDestroyContext(D, w->cx); destroycontext = True; /* Reinit */ } #endif XDestroyWindow(D, w->main); XSync(D, False); while(XCheckWindowEvent(D, w->main, Ygl.EventMask, &ev)) { #ifdef DEBUG fprintf(stderr, "winclose: dropped %d(%s) for window 0x%x\n", ev.type, Ygl.XEventNames[ev.type], w->main); #endif } w->main = 0; } else { Yprintf(MyName, "invalid window id: %d\n", id); } } void gexit(void) { const char * MyName = "gexit"; int i; I(MyName, ""); for(i = 1; i < Ygl.NextWindow; i++) if(is_wid(i)) winclose(i); #ifdef HASXMU if(Ygl.PCM) { XFreeColormap(D, Ygl.CCmap); } #else if(Ygl.PCM || Ygl.CCmap != DefaultColormap(D, YglScreen)) { XFreeColormap(D, Ygl.CCmap); } #endif if(!Ygl.PCM) { free(Ygl.Colors); if(!Ygl.EmulateCmap) free(Ygl.ColorsInv); } if(Ygl.RCmap != 0) XFreeColormap(D, Ygl.RCmap); free(Ygl.Windows); XFreeCursor(D, YglCursor); XCloseDisplay(D); D = NULL; } static int winX_badWindowHandler(Display *dpy, XErrorEvent *error) { Yprintf("winX", "no window with id 0x%x found.\n", error->resourceid); exit (1); } Int32 winX(Display *dpy, Window win) { const char * MyName = "winX"; XWindowAttributes wa; XSetWindowAttributes swa; Ulong swa_mask = 0; YglWindow *w; if(D == NULL) ginit(); /* first window. Here we assume that dpy is taken from envvar DISPLAY... */ if(win == RootWindow(D, YglScreen)) { Yprintf(MyName, "Cannot convert root window.\n"); exit (1); } w = find_new_window_id(MyName); w->xpid = get_real_parent(win); /* Also checks if win is valid */ XGetWindowAttributes(D, win, &wa); /* Setup window structure */ w->top = win; w->main = win; #ifdef RGBWIN w->win = win; #endif w->draw = win; w->xm = wa.width; w->ym = wa.height; w->vw = w->xm; /* else set_scales() crashes the firat time */ w->vh = w->ym; w->xp = w->yp = w->xc = w->yc = 0; if(wa.visual->visualid == Ygl.CV.visualid) { w->rgb = False; } else if(wa.visual->visualid == Ygl.RV.visualid) { w->rgb = True; } else { Yprintf(MyName, "unsupported visual type, must be 0x%x (cmap) or 0x%x (RGB).\n", Ygl.CV.visualid, Ygl.RV.visualid); exit(1); } w->mapped = wa.map_state != IsUnmapped; w->pid = -1; w->dbuf = False; /* New windows are always in singlebuffer mode */ w->clipped = False; /* No clipping activated */ w->vmode = VertexNone; /* Set up window attributes */ swa.background_pixel = WhitePixel(D,YglScreen); swa.border_pixel = WhitePixel(D,YglScreen); swa.colormap = YglColormap(); swa.cursor = YglCursor; swa_mask = CWBackPixel | CWBorderPixel | CWColormap | CWCursor; if(Ygl.BS) { swa.backing_store = Always; swa_mask |= CWBackingStore; } XChangeWindowAttributes(D, w->main, swa_mask, &swa); create_gc(MyName, Ygl.ActiveWindow); font(0); /* Set default font to "fixed" */ ortho2 (0.0, w->xm - 1.0, 0.0, w->ym - 1.0); /* set default scale */ viewport(0 , w->xm - 1 , 0 , w->ym - 1 ); /* set default viewport */ #ifdef DEBUG fprintf(stderr, "winX: id = %d, done.\n", Ygl.ActiveWindow); #endif qenter(REDRAW, Ygl.ActiveWindow); return Ygl.ActiveWindow; } ygl-4.2e/config.h0000444000175000017500000000101706360131143013253 0ustar prabhuprabhu/* * Ygl: Run GL programs with standard X11 routines. * (C) Fred Hucht 1993-96 * EMail: fred@thp.Uni-Duisburg.DE * * $Id: config.h,v 3.5 1997-07-07 11:09:39+02 fred Exp $ */ #define AUTOFLUSH /* define to generate code for flushing the server via timer */ #define COVERSLEEP /* define to cover the system commands sleep and usleep with own versions that flushes Xlibs output buffer */ /*#define RGBWIN*/ #ifdef RGBWIN # define IF_RGBWIN(x, y) x #else # define IF_RGBWIN(x, y) y #endif ygl-4.2e/contrib/0000755000175000017500000000000010621134723013302 5ustar prabhuprabhuygl-4.2e/contrib/ycpu.c0000644000175000017500000000345706000436352014436 0ustar prabhuprabhu/* * ycpu.c: display a graph of CPU usage obtained from vmstat * in a [Y]gl window. This program may not run on non-AIX. * * (C) Fred Hucht 1994,1995, EMail: fred@hal6000.Uni-Duisburg.DE * * Feel free to copy and redistribute in terms of the * GNU public license. */ #include #include #include #include int goon() { int r = 1; if(qtest()) { Int32 dev; Int16 val; dev = qread(&val); switch(dev) { case WINQUIT: r = 0; break; case KEYBD: switch(val) { case '\033': case 'q': r = 0; break; } break; } } return(r); } int main(int argc, char *argv[]) { FILE *p; char hostname[256], cmd[128]; int X = 200, Y = 200, sec = 1; putenv("YGL_BS=1"); if(argc > 1) X = atoi(argv[1]); if(argc > 2) sec = atoi(argv[2]); prefsize(X+1, Y+1); gethostname(hostname, sizeof(hostname)); winopen(hostname); qdevice(KEYBD); qdevice(WINQUIT); color(BLACK); clear(); sprintf(cmd, "vmstat %d", sec); if(NULL == (p = (FILE*) popen(cmd, "r"))) { perror("pipe error"); exit(-1); } while(goon()) { short us, sy, id, wa; short i; char line[160]; if(NULL == fgets(line, 160, p)) { perror("fgets error"); exit(-2); } if(4 == sscanf(line, "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %hd %hd %hd %hd", &us, &sy, &id, &wa)) { /*printf("%d %d %d %d\n", us, sy, id, wa);*/ rectcopy(1, 0, X, Y, 0, 0); move2(X, 0); color(GREEN); rdr2(0, Y/100.0 * us); color(YELLOW); rdr2(0, Y/100.0 * sy); color(BLUE); rdr2(0, Y/100.0 * id); color(RED); rdr2(0, Y/100.0 * wa); for(i=0; i<=10; i++) pnt2(X, Y/100.0 * 10 * i); sleep(0); } } gexit(); pclose(p); exit(0); } ygl-4.2e/contrib/gl2ppm.c0000777000175000017500000000000010712351413016422 2../gl2ppm.custar prabhuprabhuygl-4.2e/contrib/xmap.c0000644000175000017500000000604006117314472014421 0ustar prabhuprabhu/* * xmap.c: display the active colormap in a [Y]gl window. * * (C) Fred Hucht 1994, EMail: fred@hal6000.Uni-Duisburg.DE * * Feel free to copy and redistribute in terms of the * GNU public license. */ #include #include #include #define SZ 160 #define SI (SZ/m) #ifdef XCOLOR #define COLOR Xcolor #define GETMCOLOR getmXcolor #else #define COLOR color #define GETMCOLOR getmcolor #endif void set_header(char *text) { color(BLACK); rectfi( 0, SZ, SZ, SZ+20); color(WHITE); cmov2i(10, SZ + 5); charstr(text); } int main(int argc, char *argv[]) { Device dev; short val; int i, j, m, p, left = 0; Int16 x,y; Int32 win, index; Int32 xo, yo, xs, ys; char version[20], header[80], buf[80], *name = argv[0], *title, *titles[]={"X11 ColorMap ( quit)", "YGL ColorMap ( quit)", "GL ColorMap ( quit)"}; if(-1 == gversion(version)) { fprintf(stderr, "%s: won't run on this display.\n", version); exit(1); } minsize (SZ, SZ + 20); /* stepunit (SZ, SZ + 20); */ keepaspect(SZ, SZ + 20); if(name[0] == 'g') title = titles[2]; /* glmap */ else if(name[1] == 'g') title = titles[1]; /* yglmap */ else title = titles[0]; /* xmap */ win = winopen(title);winconstraints(); qdevice(WINQUIT); qdevice(KEYBD); qdevice(REDRAW); qdevice(INPUTCHANGE); qenter(REDRAW, win); qdevice(MOUSEX); qdevice(MOUSEY); qdevice(LEFTMOUSE); p = getplanes(); m = 1 << (p/2); sprintf(header, "%s, %d bpp", version, p); while (1) { dev = qread(&val); #ifdef DEBUG printf("%d %d\n", dev, val); #endif switch(dev) { case INPUTCHANGE: if(val==0) set_header(header); break; case MOUSEX: x = val; goto mouse; case MOUSEY: y = val; goto mouse; mouse: { Int32 xw, yw, q; Int16 r,g,b; q = qtest(); if(q == MOUSEX || q == MOUSEY) break; xw = x - xo; yw = y - yo; index = m * (yw*m/xs) + (xw*m/xs); if(index >= 0 && index < (1<= 0 && index < (1< #include #define FACT 2 #define X 600 #define Y 200 main(int argc, char *argv[]) { FILE *p; char cmd[80]; sprintf(cmd, "rup %s", argc == 1 ? "localhost" : argv[1]); putenv("YGL_BS=1"); prefsize(X+1, Y+1); winopen(cmd); color(BLACK); clear(); while(1) { double a1,a2,a3; short i; char x[80]; p = (FILE*) popen(cmd, "r"); fscanf(p, "%51c %lg%*c%lg%*c%lg", x, &a1, &a2, &a3); pclose(p); /* printf("%s-%g %g %g\n", x, a1,a2,a3); */ rectcopy(1, 0, X, Y, 0, 0); color(BLACK); move2(X, 0);draw2(X, Y); color(YELLOW); for(i=0; i<=10; i++) pnt2(X, 10*i*FACT); color(BLUE); pnt2(X, a3*FACT); color(GREEN); pnt2(X, a2*FACT); color(RED); pnt2(X, a1*FACT); sleep(5); } } ygl-4.2e/contrib/Makefile0000644000175000017500000000060106007136171014741 0ustar prabhuprabhu .SUFFIXES: .gl TARGETS = ycpu yup xmap yglmap all: $(TARGETS) .c.gl: $(CC) $(CFLAGS) -o $@ $< -lgl .c: $(CC) $(CFLAGS) -o $@ $< -lYgl -lXext -lX11 glmap: xmap.c $(CC) $(CFLAGS) -o $@ $? -lgl yglmap: xmap.c $(CC) $(CFLAGS) -o $@ $? -lYgl -lXext -lX11 xmap: xmap.c $(CC) -DXCOLOR $(CFLAGS) -o $@ $? -lYgl -lXext -lX11 clean: /bin/rm -f *.o *~ $(TARGETS) ygl-4.2e/header.h0000444000175000017500000002210210620057016013234 0ustar prabhuprabhu/* * Ygl: Run GL programs with standard X11 and/or OpenGL routines. * (C) Fred Hucht 1993-2007 * EMail: fredthp.Uni-Duisburg.de * * $Id: header.h,v 4.9 2007-05-08 13:25:02+02 fred Exp $ */ #ifdef _AIX #define _POSIX_SOURCE /* else sigaction isn't defined under AIX 3.2 */ #endif #include "config.h" #ifdef YGL_PREFIX /* If all routines should get the prefix ygl_ * to avoid naming conflicts */ # include "X11/Yglprefix.h" /* must be included first (don't ask why...) */ #endif #ifdef X11 # include # include # include #else # undef DOUBLEBUF # undef MULTIBUF #endif #ifdef OGL # include # include # include #endif #include /* fprintf */ #include /* malloc */ #include /* defpup(...), warn() */ #include #include #include #ifdef _AIX /*extern int setitimer(int, const struct itimerval *, struct itimerval *);*/ #endif #ifdef AUTOFLUSH # include #endif #include "X11/Ygl.h" #define Ygl _Ygl_Control_ /* Alias for readability. _Ygl_Control_ is the only visible external of libYgl.a */ #define D Ygl.display #define W Ygl.active #define YglScreen DefaultScreen(D) #define YglScreenHeight DisplayHeight(D, YglScreen) #define YglScreenWidth DisplayWidth(D, YglScreen) #define KEYMAP_LEN 256 /* For init_keymap() etc. */ #define KEYMAP_BIT 0x1000 /* Is key qdevice()d? */ typedef unsigned long Ulong; typedef unsigned int Uint; typedef unsigned short Ushort; #ifdef OGL # ifdef X11 /* Use both */ # define IFOGL(o, x) do if(Ygl.UseOGL) {o;} else {x;} while(0) # else /* Only use OGL */ # define IFOGL(o, x) o # endif #else # ifdef X11 /* Only use X11 */ # define IFOGL(o, x) x #else /* Should not happen */ # error "Define at least one of OGL, X11" # endif #endif typedef struct YglWindow_ { Window top; /* top-level window of window, used for colormap installation */ Window main; /* main window */ #ifdef RGBWIN Window win; /* == main when in cmap mode, sub of main when in RGBmode */ #endif Window draw; /* drawable, only differ from win when doublebuffering */ GC gc, *gclist, chargc; int font; /* window's font id */ int linewidth; /* active linewidth */ int linestyle; /* active linestyle (index into misc.c:linestyles) */ Colorindex color; /* active color in CMap mode */ double xf, yf; /* scaling factor for macros XR(), YR()*/ double xo, yo; /* offset to coords for macros X(), Y()*/ int xm, ym; /* width, height of window */ double xp, yp; /* graphics cursor position */ double xc, yc; /* text cursor position */ int vl, vr, vb, vt; /* viewport left, right, bottom, top */ int vw, vh; /* viewport width, height */ double ol, or, ob, ot; /* ortho2 left, right, bottom, top */ #ifdef OGL double zp; /* graphics cursor z-position */ double zc; /* text cursor z-position */ double on, of; /* ortho near, far */ #endif Window xpid; /* real X Parent window ID (excl. WM) */ Int32 pid; /* parent id (swinopen), * 0 if window opened with winopen, * -1 if window converted with winX */ #if defined(DOUBLEBUF) || defined(MULTIBUF) Window dbufs[2]; /* the two doublebuffers */ #endif #ifdef MULTIBUF int dispbuf; /* dbufs[dispbuf] is displayed */ #endif Pixmap pm; /* Pixmap for dithering in RGBmode */ GC pmgc; /* GC for it */ XImage *pmi; /* XImage for dithering */ unsigned char red,green,blue; /* Dithered RGBcolors for gRGBcolor */ unsigned char vmode; /* vertex mode of window */ #ifdef OGL GLXContext cx; /* OpenGL context */ #if 0 GLUquadricObj *circ, *circf; /* OpenGL object for circ etc. */ #endif #endif /*------------------------------ Bitfields: */ Uint rgb:1; /* True if window in RGBmode */ Uint mapped:1; /* True if window is mapped */ Uint dbuf:1; /* True if window in doublebuffer mode */ Uint clipped:1; /* True if clipping is activated (viewport) */ } YglWindow; typedef struct YglFont_ { XFontStruct *fs; Int32 id; } YglFont; /* Global symbols */ typedef struct YglControl_ { Display *display; YglWindow *Windows, *active; int ActiveWindow, NextWindow; /*------------------------------ Bitfields: */ #ifdef AUTOFLUSH Uint flush:1; #endif Uint wm_dw_flag:1; Uint stat:1; /* CMap visual static? */ Uint PCM:1; /* use private colormap? */ Uint BS:1; /* YGL_BS (backing store ) set */ Uint GC:1; /* Use single GC in CMap windows (slower) */ Uint EmulateCmap:1; /* cmapmode uses TrueColor or DirectColor visual */ #ifdef OGL Uint UseOGL:1; /* Use OpenGL routines */ Uint SelectMode:1; /* in GL_SELECT mode */ #endif /*------------------------------ End of Bitfields */ YglFont *Fonts; int LastFont; Ulong EventMask; Atom wm_dw; int FT; /* autoflush time in msec */ int V[2]; /* User requested visuals */ Window PWID; /* Parent window ID */ int DSZ; /* size of RGBmode dither matrix */ Colormap CCmap, RCmap; Ulong *Colors; Ulong *ColorsInv; /* for lrectread */ int rs, gs, bs; /* bits to shift */ int rb, gb, bb; /* width of mask */ const char **XEventNames; /* For debugging */ void (*noinit)(const char *); int (*notimplemented)(const char *); int (*warn)(const char *, const char *, ...); Int32 (*x2gl_wid)(Window, int); int (*XRscale)(double); int (*YRscale)(double); int (*Xscale )(double); int (*Yscale )(double); void (*await_windowevent)(Window, long, int); const char* (*devicename)(Device); /*------------------------------ End of initialized values (see ygl.c) */ long keymap[KEYMAP_LEN]; /* For getbutton() and queueing of keys */ XEvent lastreadevent; /* not inited, For dopup() */ XVisualInfo CV, RV; /* not inited, must be last */ } YglControl; extern YglControl Ygl; #define EMULATE_CMAP_DEPTH 8 /* no comment */ #define MAX_MULTIGC_CMAPSIZE 256 /* Above that we use single GC in cmap mode */ #define CMapSize Ygl.CV.colormap_size #define RMask RV.visual->red_mask #define GMask RV.visual->green_mask #define BMask RV.visual->blue_mask #define EnterLeaveMask (EnterWindowMask|LeaveWindowMask) #define RedrawMask (ExposureMask|StructureNotifyMask) #define DoRGB (DoRed|DoGreen|DoBlue) #define VertexNone 0 /* Vertex modes */ #define VertexPoint 1 #define VertexLine 2 #define VertexCLine 3 #define VertexPoly 4 #define VertexTMesh 5 #define YglVisual() (W->rgb ? Ygl.RV.visual : Ygl.CV.visual) #define YglDepth() (W->rgb ? Ygl.RV.depth : Ygl.CV.depth ) #define YglColormap() (W->rgb ? Ygl.RCmap : Ygl.CCmap ) #define YGL_COLORS(x) (Ygl.PCM ? CMapSize-1-(x) : Ygl.Colors[x]) #define Yprintf Ygl.warn #if DEBUG > 1 /* # define I(name) if(fprintf(stderr, "Entering %s\n", name) && D == NULL) Ygl.noinit(name) */ static void I(const char *name, const char *format, ...) { va_list Argp; va_start(Argp, format); fprintf(stderr, "Entering %s(", name); vfprintf(stderr, format, Argp); fprintf(stderr, ")\n"); va_end(Argp); if ( D == NULL ) Ygl.noinit(name); } #else static void I(const char *name, const char *format, ...) { if ( D == NULL ) Ygl.noinit(name); } /*# define I(name, ...) if(D == NULL) Ygl.noinit(name)*/ #endif #ifdef AUTOFLUSH # ifdef DEBUG # define F if(Ygl.flush) { Ygl.flush = False; fprintf(stderr, "Autoflushing.\n"); IFOGL(glFlush(), XFlush(D)); } # else # define F if(Ygl.flush) { Ygl.flush = False; IFOGL(glFlush(), XFlush(D)); } # endif #else /*AUTOFLUSH*/ # define F #endif /*AUTOFLUSH*/ #define XR(x) Ygl.XRscale(x) /* rescaled x, rounded to next int */ #define YR(y) Ygl.YRscale(y) /* rescaled y, dito */ #define X(x) Ygl.Xscale(x) /* rescaled and shifted x */ #define Y(y) Ygl.Yscale(y) /* rescaled and shifted and mirrored y */ #define XS(x) X(W->xp = (x)) /* return X(x) and set cursor position */ #define YS(y) Y(W->yp = (y)) /* return Y(y) and set cursor position */ /* Set cursor positions. Ex.: SCP(=x,=y,=0), SCP(+=x,+=y,=0); */ #ifdef OGL # define SCP(gx,gy,gz) {W->xp gx;W->yp gy;W->zp gz;} #else # define SCP(gx,gy,gz) {W->xp gx;W->yp gy;} #endif #define MIN(x,y) ((x)<(y) ? (x) :(y)) #define MAX(x,y) ((x)>(y) ? (x) :(y)) #define ABS(x) ((x)< 0 ? (-(x)):(x)) /* #if defined(DEBUG) && !defined(malloc) */ #ifdef DEBUG # undef malloc # undef calloc # undef realloc static char *debug_malloc_p; # define malloc(x) (debug_malloc_p = malloc(x ), fprintf(stderr, "malloc: x=%d r=0x%x\n", x, debug_malloc_p), debug_malloc_p) # define calloc(x, y) (debug_malloc_p = calloc(x, y), fprintf(stderr, "calloc: x=%d y=%d r=0x%x\n", x, y, debug_malloc_p), debug_malloc_p) # define realloc(p, x) (debug_malloc_p = realloc(p, x), fprintf(stderr, "realloc: p=0x%x x=%d r=0x%x\n", p, x, debug_malloc_p), debug_malloc_p) # define free(p) (fprintf(stderr, "free: p=0x%x\n", p), free(p)) #endif #define X2GL_TOP 0 #define X2GL_MAIN 1 #define X2GL_WIN 2 #define X2GL_DRAW 3 #define NI(name) do {static int i = 1; if(i) Ygl.notimplemented(name); i = 0; return; } while(0) #define NIR(name,ret) do {static int i = 1; if(i) Ygl.notimplemented(name); i = 0; return ret;} while(0) ygl-4.2e/draw.c0000444000175000017500000005021110620036144012735 0ustar prabhuprabhu/* * Ygl: Run GL programs with standard X11 and/or OpenGL routines. * (C) Fred Hucht 1993-2007 * EMail: fredthp.Uni-Duisburg.de */ static const char vcid[] = "$Id: draw.c,v 4.8 2007-05-08 11:01:24+02 fred Exp $"; #include "header.h" #ifdef DEBUG /* see arc_ogl() */ # include #endif #ifdef X11 #define DWGC D,W->draw,W->gc #endif #define Coo Coord #define Ico Icoord #define Sco Scoord /* Drawing */ void clear(void) { I("clear", ""); IFOGL( if (W->rgb || Ygl.EmulateCmap) { GLfloat color[4]; /* Ask OpenGL for the current color */ glGetFloatv(GL_CURRENT_COLOR, color); glClearColor(color[0], color[1], color[2], color[3]); } else { GLfloat color; glGetFloatv(GL_CURRENT_INDEX, &color); glClearIndex(color); } glClear(GL_COLOR_BUFFER_BIT); , XFillRectangle(DWGC, 0, 0, W->xm, W->ym) ); F; } #define PNT2_FN(t, x, y) IFOGL(\ glBegin(GL_POINTS); glVertex2##t(W->xp = (x), W->yp = (y)); glEnd(),\ if(W->pm) XFillRectangle(DWGC, XS(x), YS(y), 1, 1);else XDrawPoint(DWGC, XS(x), YS(y))) #define PNT_FN(t, x, y, z) IFOGL(\ glBegin(GL_POINTS); glVertex3##t(W->xp = (x), W->yp = (y), W->zp = (z)); glEnd(),\ if(W->pm) XFillRectangle(DWGC, XS(x), YS(y), 1, 1);else XDrawPoint(DWGC, XS(x), YS(y))) #define DRAW2_FN(t, x, y) IFOGL(\ glBegin(GL_LINES); glVertex2##t(W->xp, W->yp); glVertex2##t(x, y); glEnd(),\ XDrawLine(DWGC, X(W->xp), Y(W->yp), X(x), Y(y))) #define DRAW_FN(t, x, y, z) IFOGL(\ glBegin(GL_LINES); glVertex3##t(W->xp, W->yp, W->zp); glVertex3##t(x, y, z); glEnd(),\ XDrawLine(DWGC, X(W->xp), Y(W->yp), X(x), Y(y))) #define RECT_FN(t, x1, y1, x2, y2) IFOGL(\ glBegin(GL_LINE_LOOP);glVertex2##t(x1, y1);glVertex2##t(x2, y1);glVertex2##t(x2, y2);glVertex2##t(x1, y2);glEnd(),\ XDrawRectangle(DWGC, X(MIN(x1,x2)), Y(MAX(y1,y2)), XR(ABS((x2)-(x1))), YR(ABS((y2)-(y1))))) #define RECTF_FN(t, x1, y1, x2, y2) IFOGL(\ glBegin(GL_POLYGON );glVertex2##t(x1, y1);glVertex2##t(x2, y1);glVertex2##t(x2, y2);glVertex2##t(x1, y2);glEnd(),\ XFillRectangle(DWGC, X(MIN(x1,x2)), Y(MAX(y1,y2)), XR(ABS((x2)-(x1))), YR(ABS((y2)-(y1))))) #define ARC_FN(x, y, r, s, e) IFOGL(\ arc_ogl(x, y, r, s, e, 0),\ r=MAX(0,r); XDrawArc(DWGC, X((x)-(r)), Y((y)+(r)), XR(2*(r)), YR(2*(r)), 64*(s)/10, 64*((e)-(s))/10)) #define ARCF_FN(x, y, r, s, e) IFOGL(\ arc_ogl(x, y, r, s, e, 1),\ r=MAX(0,r); XFillArc(DWGC, X((x)-(r)), Y((y)+(r)), XR(2*(r)), YR(2*(r)), 64*(s)/10, 64*((e)-(s))/10)) /* Points */ void pnt2 (Coo x, Coo y ) { I("pnt2" , "args"); PNT2_FN(f, x, y); F; } void pnt2i (Ico x, Ico y ) { I("pnt2i", "args"); PNT2_FN(i, x, y); F; } void pnt2s (Sco x, Sco y ) { I("pnt2s", "args"); PNT2_FN(s, x, y); F; } void pnt (Coo x, Coo y, Coo z) { I("pnt" , "args"); PNT_FN(f, x, y, z); F; } void pnti (Ico x, Ico y, Ico z) { I("pnti" , "args"); PNT_FN(i, x, y, z); F; } void pnts (Sco x, Sco y, Sco z) { I("pnts" , "args"); PNT_FN(s, x, y, z); F; } /* Lines */ void move2 (Coo x, Coo y ) { SCP( =x, =y, =0);} void move2i(Ico x, Ico y ) { SCP( =x, =y, =0);} void move2s(Sco x, Sco y ) { SCP( =x, =y, =0);} void move (Coo x, Coo y, Coo z) { SCP( =x, =y, =z);} void movei (Ico x, Ico y, Ico z) { SCP( =x, =y, =z);} void moves (Sco x, Sco y, Sco z) { SCP( =x, =y, =z);} void rmv2 (Coo x, Coo y ) { SCP(+=x,+=y,+=0);} void rmv2i (Ico x, Ico y ) { SCP(+=x,+=y,+=0);} void rmv2s (Sco x, Sco y ) { SCP(+=x,+=y,+=0);} void rmv (Coo x, Coo y, Coo z) { SCP(+=x,+=y,+=z);} void rmvi (Ico x, Ico y, Ico z) { SCP(+=x,+=y,+=z);} void rmvs (Sco x, Sco y, Sco z) { SCP(+=x,+=y,+=z);} void draw2 (Coo x, Coo y ) { I("draw2" , "args"); DRAW2_FN(f, x, y); SCP( =x, =y, =0); F;} void draw2i(Ico x, Ico y ) { I("draw2i", "args"); DRAW2_FN(i, x, y); SCP( =x, =y, =0); F;} void draw2s(Sco x, Sco y ) { I("draw2s", "args"); DRAW2_FN(s, x, y); SCP( =x, =y, =0); F;} void draw (Coo x, Coo y, Coo z) { I("draw" , "args"); DRAW_FN(f, x, y, z); SCP( =x, =y, =z); F;} void drawi (Ico x, Ico y, Ico z) { I("drawi" , "args"); DRAW_FN(i, x, y, z); SCP( =x, =y, =z); F;} void draws (Sco x, Sco y, Sco z) { I("draws" , "args"); DRAW_FN(s, x, y, z); SCP( =x, =y, =z); F;} void rdr2 (Coo x, Coo y ) { I("rdr2" , "args"); DRAW2_FN(f, W->xp+x, W->yp+y); SCP(+=x,+=y,+=0); F;} void rdr2i (Ico x, Ico y ) { I("rdr2i" , "args"); DRAW2_FN(i, W->xp+x, W->yp+y); SCP(+=x,+=y,+=0); F;} void rdr2s (Sco x, Sco y ) { I("rdr2s" , "args"); DRAW2_FN(s, W->xp+x, W->yp+y); SCP(+=x,+=y,+=0); F;} void rdr (Coo x, Coo y, Coo z) { I("rdr" , "args"); DRAW_FN(f, W->xp+x, W->yp+y, W->zp+z); SCP(+=x,+=y,+=z); F;} void rdri (Ico x, Ico y, Ico z) { I("rdri" , "args"); DRAW_FN(i, W->xp+x, W->yp+y, W->zp+z); SCP(+=x,+=y,+=z); F;} void rdrs (Sco x, Sco y, Sco z) { I("rdrs" , "args"); DRAW_FN(s, W->xp+x, W->yp+y, W->zp+z); SCP(+=x,+=y,+=z); F;} /* Arcs & Circles */ #ifdef OGL static void arc_ogl(double x, double y, double r, int s, int e, int filled) { #if 0 if(r > 0) { glPushMatrix(); glTranslatef(x, y, 0.0); /* Mesa requires 2 loops -----\ */ gluPartialDisk(filled ? W->circf : W->circ, 0.0, r, 12, 2, 0.1 * s, 0.1 * (e - s)); glPopMatrix(); } #else int i; #define NARC 32 #define SIN(i) ((1 - 2 * (((i) / (NARC/2)) & 1)) * Sin[(i) % (NARC/2)]) #define COS(i) SIN(i + NARC/4) #ifdef DEBUG_NO # define DEBUGPRINT(i) fprintf(stderr, "%g,%g %g %f,%f %f,%f\n",\ x, y, r, glx, gly,\ x + r * cos(2 * M_PI * i / NARC),\ y + r * sin(2 * M_PI * i / NARC)); #else # define DEBUGPRINT(i) #endif const double Sin[NARC] = { 0.0000000000000000, 0.1950903220161283, 0.3826834323650898, 0.5555702330196022, 0.7071067811865476, 0.8314696123025452, 0.9238795325112867, 0.9807852804032304, 1.0000000000000000, 0.9807852804032304, 0.9238795325112867, 0.8314696123025455, 0.7071067811865476, 0.5555702330196022, 0.3826834323650899, 0.1950903220161286 }; if(r > 0) { GLdouble glx, gly; glBegin(filled ? GL_POLYGON : GL_LINE_STRIP); if(s == 0 && e == 3600) { /* circ */ for(i = 0; i <= NARC; i++) { glx = x + r * COS(i); gly = y + r * SIN(i); glVertex2d(glx, gly); } } else { /* arc */ double sd = (double)s/3600*NARC; double ed = (double)e/3600*NARC; double d; i = sd; d = sd - i; /* interpolate first point */ glx = x + r * ((1 - d) * COS(i) + d * COS(i+1)); gly = y + r * ((1 - d) * SIN(i) + d * SIN(i+1)); DEBUGPRINT(sd); glVertex2d(glx, gly); for(i++; i <= (int)ed; i++) { glx = x + r * COS(i); gly = y + r * SIN(i); DEBUGPRINT(i); glVertex2d(glx, gly); } i = ed; d = ed - i; /* interpolate last point */ glx = x + r * ((1 - d) * COS(i) + d * COS(i+1)); gly = y + r * ((1 - d) * SIN(i) + d * SIN(i+1)); DEBUGPRINT(ed); glVertex2d(glx, gly); } glEnd(); } #endif } #endif void arc (Coo x, Coo y, Coo r, Angle s, Angle e) { I("arc" , "args"); ARC_FN(x, y, r, s, e); F;} void arci (Ico x, Ico y, Ico r, Angle s, Angle e) { I("arci" , "args"); ARC_FN(x, y, r, s, e); F;} void arcs (Sco x, Sco y, Sco r, Angle s, Angle e) { I("arcs" , "args"); ARC_FN(x, y, r, s, e); F;} void arcf (Coo x, Coo y, Coo r, Angle s, Angle e) { I("arcf" , "args"); ARCF_FN(x, y, r, s, e); F;} void arcfi (Ico x, Ico y, Ico r, Angle s, Angle e) { I("arcfi" , "args"); ARCF_FN(x, y, r, s, e); F;} void arcfs (Sco x, Sco y, Sco r, Angle s, Angle e) { I("arcfs" , "args"); ARCF_FN(x, y, r, s, e); F;} void circ (Coo x, Coo y, Coo r) { I("circ" , "args"); ARC_FN(x, y, r, 0, 3600); F;} void circi (Ico x, Ico y, Ico r) { I("circi" , "args"); ARC_FN(x, y, r, 0, 3600); F;} void circs (Sco x, Sco y, Sco r) { I("circs" , "args"); ARC_FN(x, y, r, 0, 3600); F;} void circf (Coo x, Coo y, Coo r) { I("circf" , "args"); ARCF_FN(x, y, r, 0, 3600); F;} void circfi(Ico x, Ico y, Ico r) { I("circfi", "args"); ARCF_FN(x, y, r, 0, 3600); F;} void circfs(Sco x, Sco y, Sco r) { I("circfs", "args"); ARCF_FN(x, y, r, 0, 3600); F;} /* Rects & Boxes */ void rect (Coo x1, Coo y1, Coo x2, Coo y2) { I("rect" , "args"); RECT_FN(f, x1, y1, x2, y2); F;} void sbox (Coo x1, Coo y1, Coo x2, Coo y2) { I("sbox" , "args"); RECT_FN(f, x1, y1, x2, y2); F;} void recti (Ico x1, Ico y1, Ico x2, Ico y2) { I("recti" , "args"); RECT_FN(i, x1, y1, x2, y2); F;} void sboxi (Ico x1, Ico y1, Ico x2, Ico y2) { I("sboxi" , "args"); RECT_FN(i, x1, y1, x2, y2); F;} void rects (Sco x1, Sco y1, Sco x2, Sco y2) { I("rects" , "args"); RECT_FN(s, x1, y1, x2, y2); F;} void sboxs (Sco x1, Sco y1, Sco x2, Sco y2) { I("sboxs" , "args"); RECT_FN(s, x1, y1, x2, y2); F;} void rectf (Coo x1, Coo y1, Coo x2, Coo y2) { I("rectf" , "args"); RECTF_FN(f, x1, y1, x2, y2); F;} void sboxf (Coo x1, Coo y1, Coo x2, Coo y2) { I("sboxf" , "args"); RECTF_FN(f, x1, y1, x2, y2); F;} void rectfi(Ico x1, Ico y1, Ico x2, Ico y2) { I("rectfi", "args"); RECTF_FN(i, x1, y1, x2, y2); F;} void sboxfi(Ico x1, Ico y1, Ico x2, Ico y2) { I("sboxfi", "args"); RECTF_FN(i, x1, y1, x2, y2); F;} void rectfs(Sco x1, Sco y1, Sco x2, Sco y2) { I("rectfs", "args"); RECTF_FN(s, x1, y1, x2, y2); F;} void sboxfs(Sco x1, Sco y1, Sco x2, Sco y2) { I("sboxfs", "args"); RECTF_FN(s, x1, y1, x2, y2); F;} static Int32 PMode = Convex; #ifdef X11 static Ulong q_len = 0, q_max = 0; static XPoint *queue = NULL; static void q_add(const char *caller, int x, int y) { if(q_max <= q_len) { q_max += 0x1000; if(queue == NULL) /* Make new queue */ queue = (XPoint*)malloc(q_max * sizeof(XPoint)); else /* Resize queue */ queue = (XPoint*)realloc(queue, q_max * sizeof(XPoint)); if(queue == NULL) { Yprintf(caller, "out of memory.\n"); exit(1); } } /* Add point */ queue[q_len].x = x; queue[q_len].y = y; q_len++; } #endif void concave(Int32 bool) { PMode = bool ? Complex : Convex;} void pmv2 (Coo x, Coo y) { const char *MyName = "pmv2" ; I(MyName, "args"); SCP(=x, =y, =0); IFOGL(NI(MyName),q_len = 0; q_add(MyName, X(x), Y(y)));} void pmv2i(Ico x, Ico y) { const char *MyName = "pmv2i"; I(MyName, "args"); SCP(=x, =y, =0); IFOGL(NI(MyName),q_len = 0; q_add(MyName, X(x), Y(y)));} void pmv2s(Sco x, Sco y) { const char *MyName = "pmv2s"; I(MyName, "args"); SCP(=x, =y, =0); IFOGL(NI(MyName),q_len = 0; q_add(MyName, X(x), Y(y)));} void rpmv2 (Coo x, Coo y) { const char *MyName = "rpmv2" ; I(MyName, "args"); SCP(+=x, +=y, =0); IFOGL(NI(MyName),q_len = 0; q_add(MyName, X(x), Y(y)));} void rpmv2i(Ico x, Ico y) { const char *MyName = "rpmv2i"; I(MyName, "args"); SCP(+=x, +=y, =0); IFOGL(NI(MyName),q_len = 0; q_add(MyName, X(x), Y(y)));} void rpmv2s(Sco x, Sco y) { const char *MyName = "rpmv2s"; I(MyName, "args"); SCP(+=x, +=y, =0); IFOGL(NI(MyName),q_len = 0; q_add(MyName, X(x), Y(y)));} void pdr2 (Coo x, Coo y) { const char *MyName = "pdr2" ; I(MyName, "args"); IFOGL(NI(MyName),q_add(MyName, X(x), Y(y)));} void pdr2i(Ico x, Ico y) { const char *MyName = "pdr2i"; I(MyName, "args"); IFOGL(NI(MyName),q_add(MyName, X(x), Y(y)));} void pdr2s(Sco x, Sco y) { const char *MyName = "pdr2s"; I(MyName, "args"); IFOGL(NI(MyName),q_add(MyName, X(x), Y(y)));} void rpdr2 (Coo x, Coo y) { const char *MyName = "rpdr2" ; I(MyName, "args"); IFOGL(NI(MyName),q_add(MyName, queue[q_len-1].x + X(x), queue[q_len-1].y - Y(y)));} void rpdr2i(Ico x, Ico y) { const char *MyName = "rpdr2i"; I(MyName, "args"); IFOGL(NI(MyName),q_add(MyName, queue[q_len-1].x + X(x), queue[q_len-1].y - Y(y)));} void rpdr2s(Sco x, Sco y) { const char *MyName = "rpdr2s"; I(MyName, "args"); IFOGL(NI(MyName),q_add(MyName, queue[q_len-1].x + X(x), queue[q_len-1].y - Y(y)));} void pclos(void) { const char *MyName = "pclos";I(MyName, ""); IFOGL(NI(MyName),if(q_len) XFillPolygon(DWGC, queue, q_len, PMode, CoordModeOrigin)); F;} void pmv (Coo x, Coo y, Coo z) { const char *MyName = "pmv" ; NI(MyName);} void pmvi(Ico x, Ico y, Ico z) { const char *MyName = "pmvi"; NI(MyName);} void pmvs(Sco x, Sco y, Sco z) { const char *MyName = "pmvs"; NI(MyName);} void rpmv (Coo x, Coo y, Coo z) { const char *MyName = "rpmv" ; NI(MyName);} void rpmvi(Ico x, Ico y, Ico z) { const char *MyName = "rpmvi"; NI(MyName);} void rpmvs(Sco x, Sco y, Sco z) { const char *MyName = "rpmvs"; NI(MyName);} void pdr (Coo x, Coo y, Coo z) { const char *MyName = "pdr" ; NI(MyName);} void pdri(Ico x, Ico y, Ico z) { const char *MyName = "pdri"; NI(MyName);} void pdrs(Sco x, Sco y, Sco z) { const char *MyName = "pdrs"; NI(MyName);} void rpdr (Coo x, Coo y, Coo z) { const char *MyName = "rpdr" ; NI(MyName);} void rpdri(Ico x, Ico y, Ico z) { const char *MyName = "rpdri"; NI(MyName);} void rpdrs(Sco x, Sco y, Sco z) { const char *MyName = "rpdrs"; NI(MyName);} #define MKP(n, p) { Int32 i; q_len = 0; for(i = 0; i < n; i++) { q_add(MyName, X(p[i][0]), Y(p[i][1]));}} void poly2 (Int32 n, Coo p[][2]) { const char *MyName = "poly2" ; I(MyName, "args"); IFOGL(NI(MyName),MKP(n, p); q_add(MyName, XS(p[0][0]), YS(p[0][1])); XDrawLines(DWGC, queue, q_len, CoordModeOrigin)); F;} void poly2i(Int32 n, Ico p[][2]) { const char *MyName = "poly2i"; I(MyName, "args"); IFOGL(NI(MyName),MKP(n, p); q_add(MyName, XS(p[0][0]), YS(p[0][1])); XDrawLines(DWGC, queue, q_len, CoordModeOrigin)); F;} void poly2s(Int32 n, Sco p[][2]) { const char *MyName = "poly2s"; I(MyName, "args"); IFOGL(NI(MyName),MKP(n, p); q_add(MyName, XS(p[0][0]), YS(p[0][1])); XDrawLines(DWGC, queue, q_len, CoordModeOrigin)); F;} void polf2 (Int32 n, Coo p[][2]) { const char *MyName = "polf2" ; I(MyName, "args"); IFOGL(NI(MyName),MKP(n, p); SCP(=p[0][0],=p[0][1], =0); XFillPolygon(DWGC, queue, q_len, PMode, CoordModeOrigin)); F;} void polf2i(Int32 n, Ico p[][2]) { const char *MyName = "polf2i"; I(MyName, "args"); IFOGL(NI(MyName),MKP(n, p); SCP(=p[0][0],=p[0][1], =0); XFillPolygon(DWGC, queue, q_len, PMode, CoordModeOrigin)); F;} void polf2s(Int32 n, Sco p[][2]) { const char *MyName = "polf2s"; I(MyName, "args"); IFOGL(NI(MyName),MKP(n, p); SCP(=p[0][0],=p[0][1], =0); XFillPolygon(DWGC, queue, q_len, PMode, CoordModeOrigin)); F;} #ifdef OGL static void polf_ogl (Int32 n, Coo p[][3]) {int i;glBegin(GL_POLYGON);for(i = 0; i < n; i++) glVertex3fv(p[i]);glEnd();} static void polfi_ogl(Int32 n, Ico p[][3]) {int i;glBegin(GL_POLYGON);for(i = 0; i < n; i++) glVertex3iv(p[i]);glEnd();} static void polfs_ogl(Int32 n, Sco p[][3]) {int i;glBegin(GL_POLYGON);for(i = 0; i < n; i++) glVertex3sv(p[i]);glEnd();} #endif void polf (Int32 n, Coo p[][3]) { const char *MyName = "polf" ; I(MyName, "args"); IFOGL(polf_ogl (n, p),MKP(n, p); SCP(=p[0][0],=p[0][1], =0); XFillPolygon(DWGC, queue, q_len, PMode, CoordModeOrigin)); F;} void polfi (Int32 n, Ico p[][3]) { const char *MyName = "polfi"; I(MyName, "args"); IFOGL(polfi_ogl(n, p),MKP(n, p); SCP(=p[0][0],=p[0][1], =0); XFillPolygon(DWGC, queue, q_len, PMode, CoordModeOrigin)); F;} void polfs (Int32 n, Sco p[][3]) { const char *MyName = "polfs"; I(MyName, "args"); IFOGL(polfs_ogl(n, p),MKP(n, p); SCP(=p[0][0],=p[0][1], =0); XFillPolygon(DWGC, queue, q_len, PMode, CoordModeOrigin)); F;} /* Vertex graphics */ void bgnpoint (void) { const char *MyName = "bgnpoint" ; I(MyName, ""); W->vmode = VertexPoint;IFOGL(glBegin(GL_POINTS ), q_len = 0);} void bgnline (void) { const char *MyName = "bgnline" ; I(MyName, ""); W->vmode = VertexLine; IFOGL(glBegin(GL_LINE_STRIP), q_len = 0);} void bgnclosedline(void) { const char *MyName = "bgnclosedline"; I(MyName, ""); W->vmode = VertexCLine;IFOGL(glBegin(GL_LINE_LOOP ), q_len = 0);} void bgnpolygon (void) { const char *MyName = "bgnpolygon" ; I(MyName, ""); W->vmode = VertexPoly; IFOGL(glBegin(GL_POLYGON ), q_len = 0);} void bgntmesh (void) { const char *MyName = "bgntmesh" ; I(MyName, ""); W->vmode = VertexTMesh;IFOGL(glBegin(GL_TRIANGLE_STRIP), NI(MyName));} void endpoint (void) { const char *MyName = "endpoint" ; I(MyName, ""); if(W->vmode != VertexPoint) {Yprintf(MyName, "missing bgnpoint().\n" ); exit(1);} IFOGL(glEnd(), if(q_len) { XDrawPoints (DWGC, queue, q_len, CoordModeOrigin); });F;} void endline (void) { const char *MyName = "endline" ; I(MyName, ""); if(W->vmode != VertexLine ) {Yprintf(MyName, "missing bgnline().\n" ); exit(1);} IFOGL(glEnd(), if(q_len) { XDrawLines (DWGC, queue, q_len, CoordModeOrigin); });F;} void endclosedline(void) { const char *MyName = "endclosedline"; I(MyName, ""); if(W->vmode != VertexCLine) {Yprintf(MyName, "missing bgnclosedline().\n"); exit(1);} IFOGL(glEnd(), if(q_len) { q_add(MyName, queue[0].x, queue[0].y); XDrawLines (DWGC, queue, q_len, CoordModeOrigin); });F;} void endpolygon (void) { const char *MyName = "endpolygon" ; I(MyName, ""); if(W->vmode != VertexPoly ) {Yprintf(MyName, "missing bgnpolygon().\n" ); exit(1);} IFOGL(glEnd(), if(q_len) { XFillPolygon(DWGC, queue, q_len, PMode, CoordModeOrigin); });F;} void endtmesh (void) { const char *MyName = "endtmesh" ; I(MyName, ""); if(W->vmode != VertexTMesh) {Yprintf(MyName, "missing bgntmesh().\n" ); exit(1);} IFOGL(glEnd(), NI(MyName)); F;} #if 0 #define V_FN(t, gt, v) if(W->vmode == VertexNone) { Yprintf(MyName, "not in vertex mode\n"); exit(1);}\ IFOGL(glVertex##t##v((gt *)v), q_add(MyName, X(v[0]), Y(v[1]))) #endif float vo[2][3]; int vi; #ifdef OGL Float32 no[2][3]; void n3f(Float32 v[3]) { const char * MyName = "n3f"; I(MyName, "{%g,%g,%g}", v[0], v[1], v[2]); if(W->vmode == VertexTMesh) memcpy(no[vi], v, sizeof(no[0])); IFOGL(glNormal3fv(v),NI(MyName)); } void normal(Coord v[3]) { const char * MyName = "normal"; I(MyName, "{%g,%g,%g}", v[0], v[1], v[2]); IFOGL(glNormal3fv(v),NI(MyName)); } #endif #if 1 #define V_FN(t, gt, v) \ switch (W->vmode) { \ case VertexNone: \ Yprintf(MyName, "not in vertex mode.\n"); \ exit(1); \ case VertexTMesh: \ vo[vi][0] = v[0]; \ vo[vi][1] = v[1]; \ vo[vi][2] = v[2]; \ vi = 1 - vi; \ } \ IFOGL(glVertex##t##v((gt *)v), q_add(MyName, X(v[0]), Y(v[1]))) #endif void swaptmesh(void) { const char *MyName = "swaptmesh"; if(W->vmode != VertexTMesh) { Yprintf(MyName, "missing bgntmesh.\n"); exit(1); } /* To swap the tmesh we simply resend the 2nd-last vertex */ /*glNormal3fv(no[vi]);*/ /*glVertex3fv(vo[vi]);*/ /* v3f(vo[vi]); */ } void v2s(Int16 v[2]) { const char *MyName = "v2s"; V_FN(2s, GLshort, v);} void v2i(Int32 v[2]) { const char *MyName = "v2i"; V_FN(2i, GLint, v);} void v2f(Float32 v[2]) { const char *MyName = "v2f"; V_FN(2f, GLfloat, v);} void v2d(Float64 v[2]) { const char *MyName = "v2d"; V_FN(2d, GLdouble, v);} void v3s(Int16 v[3]) { const char *MyName = "v3s"; V_FN(3s, GLshort, v);} void v3i(Int32 v[3]) { const char *MyName = "v3i"; V_FN(3i, GLint, v);} void v3f(Float32 v[3]) { const char *MyName = "v3f"; V_FN(3f, GLfloat, v);} void v3d(Float64 v[3]) { const char *MyName = "v3d"; V_FN(3d, GLdouble, v);} void v4s(Int16 v[4]) { const char *MyName = "v4s"; V_FN(4s, GLshort, v);} void v4i(Int32 v[4]) { const char *MyName = "v4i"; V_FN(4i, GLint, v);} void v4f(Float32 v[4]) { const char *MyName = "v4f"; V_FN(4f, GLfloat, v);} void v4d(Float64 v[4]) { const char *MyName = "v4d"; V_FN(4d, GLdouble, v);} /* Extensions: Routines from X not in gl. Contributed by MiSt (michaelthp.Uni-Duisburg.de) */ #ifdef X11 void arcx (Coo x,Coo y,Coo rx,Coo ry,Angle s,Angle e) { I("arcx" , "args"); XDrawArc(DWGC, X(x-rx), Y(y+ry), XR(2*MAX(0,rx)), YR(2*MAX(0,ry)), (64*s)/10, (64*(e-s))/10); F;} void arcxi (Ico x,Ico y,Ico rx,Ico ry,Angle s,Angle e) { I("arcxi", "args"); XDrawArc(DWGC, X(x-rx), Y(y+ry), XR(2*MAX(0,rx)), YR(2*MAX(0,ry)), (64*s)/10, (64*(e-s))/10); F;} void arcxs (Sco x,Sco y,Sco rx,Sco ry,Angle s,Angle e) { I("arcxs", "args"); XDrawArc(DWGC, X(x-rx), Y(y+ry), XR(2*MAX(0,rx)), YR(2*MAX(0,ry)), (64*s)/10, (64*(e-s))/10); F;} void arcxf (Coo x,Coo y,Coo rx,Coo ry,Angle s,Angle e) { I("arcxf" , "args"); XFillArc(DWGC, X(x-rx), Y(y+ry), XR(2*MAX(0,rx)), YR(2*MAX(0,ry)), (64*s)/10, (64*(e-s))/10); F;} void arcxfi(Ico x,Ico y,Ico rx,Ico ry,Angle s,Angle e) { I("arcxfi", "args"); XFillArc(DWGC, X(x-rx), Y(y+ry), XR(2*MAX(0,rx)), YR(2*MAX(0,ry)), (64*s)/10, (64*(e-s))/10); F;} void arcxfs(Sco x,Sco y,Sco rx,Sco ry,Angle s,Angle e) { I("arcxfs", "args"); XFillArc(DWGC, X(x-rx), Y(y+ry), XR(2*MAX(0,rx)), YR(2*MAX(0,ry)), (64*s)/10, (64*(e-s))/10); F;} #endif ygl-4.2e/Smile-anim.gif0000644000175000017500000000272306651051211014326 0ustar prabhuprabhuGIF89addñÿÿÿÿ!ÿ NETSCAPE2.0!ù2ÿ,ddÿ„©Ëí£œ´Ú‹³Þ¼û†âH–扦êʶî‹ðlöç6]êþãu€Ä¢Lh1*‰HÉòÉl2 Ô¨ôPÍþ®­×'ýŠu±98;«w¯µÛ厳âtýŽºãOú=©¯÷(²$0xs¨TH$àøøH9Y4‰©x–I rɉi*ºåñCZú•Ú 6„š À)Æ)›éÉ ©p«…É«šóª3ÉLU¼p|“«ëØÐZ•¬ ‰›ú]í»k¼ízí3M™5\Žýì.ÝMîh}Ñ>ÏížoZÏ.€_?xûð $³`À½Ì³ á?…©h±úæ/‰½‹×š¼p<¨®‚‘£8 W„Õ•‹* %iÖ—ˆj²™hÊœƒvòìãó§BÒ,Zç(Ò7J=-•ñDCT¤]fJI5êU¬?«Z ÊD¨×–[ñ{²W›h+©]Û“Ê)(mëÈKP]·x§â©b °]Àå¾É2BK1‹ 3B¼·¥_[­LYLŒŒšóœi ÆÎS²)Fó]a:ãœÔh`°¾™&u“Ñ\"÷¬m›nËzw+èí{ŠœàÌojå¸òåÌ›;=ºôéÔ«[¿Ž=x!ù2ÿ,ddÿ„©Ëí£œ´Ú‹³Þ¼û†âH–扦êʶî‹ðlöç6]êþãu€Ä¢Lh1*‰HÉòÉl2 Ô¨ôPÍþ®­×'ýŠu±98;«w¯µÛ厳âtýŽºãOú=©¯÷(2X%°Th¨$ÐèèX²XôX 2IdÉÙˆé¡ùÓÙùÉ*Ê @ºezšc©ÀɺáúúÈ`9›QkëØPYŠÁ‹Sùû|J…˜Ul| ¦ļä©å¼¬›4MmdÝ|‹{ŒL± Þ¾,«½mž®NLÎ~ [>A9ŠïÅßÿNß¹Ðü,ÐɾƒfÊ##ìÛ¿5Ed´Êͨ'¹‡ÕéèqÍ®r@’43ò¤š”*Qšlé…%Ì/2™xìbñå^8•ÐJÄ“£4Ž®zú ô”Q#­’NZ©©ÏPP­ u:¨ªÕ«S³RùPEëʰ`¿"[Ö¬œ,ŠÔŽE›‰­X(5ä¶%snTAZê ¥ibL ]bR¬œrÆÎLˆŠ³™ãÆb0Ëœl’‹Þ>šýjê<Øè€F;øh‚ËÔÜ„²~ ;¶ìÙ´kÛ¾;·îݼ{§.!ù2ÿ,ddÿ„©Ëí£œ´Ú‹³Þ¼û†âH–扦êʶî‹ðlöç6]êþãu€Ä¢Lh1*‰HÉòÉl2 Ô¨ôPÍþ®­×'ýŠu±98;«w¯µÛ厳âtýŽºãOú=©¯÷(²$0xs¨TH$àøøH9Y4‰©x–I rɉi*ºåñCZú•Ú 6„š À)Æ)›éÉ ©p«…É«šóª3ÉLU¼p|“«ëØÐZ•¬ ‰›ú]í»k¼ízí3M™5\Žýì.ÝMîh}Ñ>ÏížoZÏ.€_?xûð $³`À½Ì³ á?…©h±úæ/‰½‹×š¼p<¨®‚‘£8 W„Õ•‹* %iÖ—ˆj²™hÊœƒvòìãó§BÒ,Zç(Ò7J=-•ñDCT¤]fJI5êU¬?«Z ÊD¨×–[ñ{²W›h+©]Û“Ê)(mëÈKP]·x§â©b °]Àå¾É2BK1‹ 3B¼·¥_[­LYLŒŒšóœi ÆÎS²)Fó]a:ãœÔh`°¾™&u“Ñ\"÷¬m›nËzw+èí{ŠœàÌojå¸òåÌ›;=ºôéÔ«[¿Ž=x;ygl-4.2e/Makefile.std0000644000175000017500000000403210200401724014061 0ustar prabhuprabhu# # Ygl: Run 2d-GL programs with standard X11 routines. # (C) Fred Hucht 1993-2002 # EMail: fred@thp.Uni-Duisburg.DE # # $Id: Makefile.std,v 3.4 1996-07-18 18:38:53+02 fred Exp fred $ # Uncomment next line to use X11 bindings (faster, but only 2d) X11 = -DX11 # Uncomment next line to use OpenGL bindings (slower than X11, but also 3d) OGL = -DOGL # Uncomment next two lines to include FORTRAN bindings FBO = fortran.o FBH = X11/Yfgl.h # Uncomment next line to use DoubleBuffer extension with X11 DOUBLEBUF = -DDOUBLEBUF # Uncomment next line to use MultiBuffer extension with X11 MULTIBUF = -DMULTIBUF # Uncomment next two lines to prepend "ygl_" to all function names #YGL_PREFIX = -DYGL_PREFIX #PH = X11/Yglprefix.h #TARGET = libYglp.a CDEBUGFLAGS = -O OBJS = ygl.o draw.o misc.o font.o queue.o color.o menu.o gl2ppm.o $(FBO) TARGET = libYgl.a COPTS = $(X11) $(OGL) $(DOUBLEBUF) $(MULTIBUF) # COPTS = -Aa -D_HPUX_SOURCE -DMULTIBUF -DNO_MULTIBUF_H -L/usr/lib/X11R4 -I/usr/include/X11R4 # For HP-UX 8.0x # COPTS = -Ae $(DOUBLEBUF) $(MULTIBUF) -L/usr/lib/X11R5 -I/usr/include/X11R5 # For HP-UX 9.0x # End of configuration CFLAGS = -I. $(CDEBUGFLAGS) $(COPTS) $(YGL_PREFIX) all: $(TARGET) .c.o: $(CC) -c $(CFLAGS) $< X11/Yglprefix.h: makeYglprefix X11/Ygl.h ./makeYglprefix > $@ X11/Ygltypes.h: makeYgltypes ./makeYgltypes > $@ makeYgltypes: makeYgltypes.c $(CC) $(CFLAGS) -o makeYgltypes makeYgltypes.c usleep.i: header.h $(RM) usleep_tst.c /bin/ln -s header.h usleep_tst.c $(CC) $(CFLAGS) -E usleep_tst.c > usleep.i $(RM) usleep_tst.c usleep.h: usleep.i sed -nf makeusleep.sed usleep.i > usleep.h misc.o: usleep.h $(OBJS): header.h config.h X11/Ygl.h X11/Ygltypes.h $(PH) $(TARGET): $(OBJS) /bin/rm -f $@ ar rv $@ $(OBJS) ranlib $@ install: $(TARGET) /bin/cp $(TARGET) /usr/lib/$(TARGET) ranlib /usr/lib/$(TARGET) /bin/cp X11/Ygl.h X11/Ygltypes.h $(PH) $(FBH) /usr/include/X11 clean: /bin/rm -f *.o *~ $(TARGET) X11/Yglprefix.h X11/Ygltypes.h makeYgltypes usleep.h usleep.i etags: etags *.[ch] ygl-4.2e/LICENSE0000444000175000017500000006126106253515704012663 0ustar prabhuprabhu GNU LIBRARY GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the library GPL. It is numbered 2 because it goes with version 2 of the ordinary GPL.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Library General Public License, applies to some specially designated Free Software Foundation software, and to any other libraries whose authors decide to use it. You can use it for your libraries, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library, or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link a program with the library, you must provide complete object files to the recipients so that they can relink them with the library, after making changes to the library and recompiling it. And you must show them these terms so they know their rights. Our method of protecting your rights has two steps: (1) copyright the library, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the library. Also, for each distributor's protection, we want to make certain that everyone understands that there is no warranty for this free library. If the library is modified by someone else and passed on, we want its recipients to know that what they have is not the original version, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that companies distributing free software will individually obtain patent licenses, thus in effect transforming the program into proprietary software. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License, which was designed for utility programs. This license, the GNU Library General Public License, applies to certain designated libraries. This license is quite different from the ordinary one; be sure to read it in full, and don't assume that anything in it is the same as in the ordinary license. The reason we have a separate public license for some libraries is that they blur the distinction we usually make between modifying or adding to a program and simply using it. Linking a program with a library, without changing the library, is in some sense simply using the library, and is analogous to running a utility program or application program. However, in a textual and legal sense, the linked executable is a combined work, a derivative of the original library, and the ordinary General Public License treats it as such. Because of this blurred distinction, using the ordinary General Public License for libraries did not effectively promote software sharing, because most developers did not use the libraries. We concluded that weaker conditions might promote sharing better. However, unrestricted linking of non-free programs would deprive the users of those programs of all benefit from the free status of the libraries themselves. This Library General Public License is intended to permit developers of non-free programs to use free libraries, while preserving your freedom as a user of such programs to change the free libraries that are incorporated in them. (We have not seen how to achieve this as regards changes in header files, but we have achieved it as regards changes in the actual functions of the Library.) The hope is that this will lead to faster development of free libraries. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, while the latter only works together with the library. Note that it is possible for a library to be covered by the ordinary General Public License rather than by this special one. GNU LIBRARY GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Library General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also compile or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. c) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. d) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Library General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! ygl-4.2e/xmap.c0000644000175000017500000000607310204341626012760 0ustar prabhuprabhu/* * xmap.c: display the active colormap in a [Y]gl window. * * (C) Fred Hucht 1994, EMail: fred@hal6000.Uni-Duisburg.DE * * Feel free to copy and redistribute in terms of the * GNU public license. */ #include /*#include #include */ #include #define SZ 160 #define SI (SZ/m) #ifdef XCOLOR #define COLOR Xcolor #define GETMCOLOR getmXcolor #else #define COLOR color #define GETMCOLOR getmcolor #endif void set_header(char *text) { color(BLACK); rectfi( 0, SZ, SZ, SZ+20); color(WHITE); cmov2i(10, SZ + 5); charstr(text); } int main(int argc, char *argv[]) { Device dev; short val; int i, j, m, p, left = 0; Int16 x,y; Int32 win, index; Int32 xo, yo, xs, ys; char version[20], header[80], buf[80], *name = argv[0], *title, *titles[]={"X11 ColorMap ( quit)", "YGL ColorMap ( quit)", "GL ColorMap ( quit)"}; if(-1 == gversion(version)) { fprintf(stderr, "%s: won't run on this display.\n", version); exit(1); } minsize (SZ, SZ + 20); /* stepunit (SZ, SZ + 20); */ keepaspect(SZ, SZ + 20); if(name[0] == 'g') title = titles[2]; /* glmap */ else if(name[1] == 'g') title = titles[1]; /* yglmap */ else title = titles[0]; /* xmap */ win = winopen(title);winconstraints(); qdevice(WINQUIT); qdevice(KEYBD); qdevice(REDRAW); qdevice(INPUTCHANGE); qenter(REDRAW, win); qdevice(MOUSEX); qdevice(MOUSEY); qdevice(LEFTMOUSE); p = getplanes(); m = 1 << (p/2); sprintf(header, "%s, %d bpp", version, p); while (1) { dev = qread(&val); #ifdef DEBUG printf("%d %d\n", dev, val); #endif switch(dev) { case INPUTCHANGE: if(val==0) set_header(header); break; case MOUSEX: x = val; goto mouse; case MOUSEY: y = val; goto mouse; mouse: { Int32 xw, yw, q; Int16 r,g,b; q = qtest(); if(q == MOUSEX || q == MOUSEY) break; xw = x - xo; yw = y - yo; index = m * (yw*m/xs) + (xw*m/xs); if(index >= 0 && index < (1<= 0 && index < (1<thp.Uni-Duisburg.de */ static const char vcid[] = "$Id: queue.c,v 4.8 2007-05-08 13:27:54+02 fred Exp $"; #include "header.h" #include static Ulong YglButtonMask = 0; static int change_map(Device dev, int on_off); static void set_YglEventMask(void); static Bool more_redraw(Display*, XEvent*, char *); static int check_more_redraw(Int32 wid); static Int32 q_next(int parent, Int16 *val); /* XChangeActivePointerGrab only understands these: */ #define XCAPG_MASK (ButtonPressMask|ButtonReleaseMask|\ EnterWindowMask|LeaveWindowMask|\ Button1MotionMask|Button2MotionMask|\ Button3MotionMask|Button4MotionMask|\ Button5MotionMask|PointerMotionHintMask|\ PointerMotionMask|ButtonMotionMask|KeymapStateMask) #define KeyMask (KeyPressMask | KeyReleaseMask) #define ButtonMask (ButtonPressMask | ButtonReleaseMask) static char IsQueued[MAXYGLDEVICE]; Int32 isqueued(Int16 dev) { return dev >= 0 && dev < MAXYGLDEVICE && IsQueued[dev]; } static int change_map(Device dev, int on_off) { int code, found = False; for (code = 0; code < KEYMAP_LEN; code++) /* several codes may return same keysym (eg MacX) */ if (dev == (Ygl.keymap[code] & (KEYMAP_BIT-1))) { /* found */ found = True; if (on_off) Ygl.keymap[code] |= KEYMAP_BIT; else Ygl.keymap[code] &= ~KEYMAP_BIT; #ifdef DEBUG fprintf(stderr, "change_map: dev = %d (%s), code = %d, new Ygl.keymap[code] = %d\n", dev, Ygl.devicename(dev), code, Ygl.keymap[code]); #endif } return found; } static void set_YglEventMask(void) { int i; /* To change event mask even when a button is pressed: */ XChangeActivePointerGrab(D, Ygl.EventMask & XCAPG_MASK, None, CurrentTime); #ifdef DEBUG fprintf(stderr, "set_YglEventMask: EventMask = 0x%x, IsQueued[ANYKEY] = %d\n", Ygl.EventMask, IsQueued[ANYKEY]); #endif for (i = 1; i < Ygl.NextWindow; i++) { YglWindow *w = &Ygl.Windows[i]; if (w->main != 0) { XSetWMProtocols(D, w->main, &Ygl.wm_dw, Ygl.wm_dw_flag ? 1 : 0); XSelectInput(D, w->main, Ygl.EventMask); #ifdef RGBWIN if (w->rgb) /* Expose events don't propagate */ XSelectInput(D, w->win, Ygl.EventMask & ExposureMask); #endif } } } static int YglTie[3][2] = {{0,0},{0,0},{0,0}}; /* ties to left, middle, right button */ void tie(Device button, Device val1, Device val2) { const char * MyName = "tie"; int tieb; I(MyName, "%d,%d,%d", button, val1, val2); switch (button) { case LEFTMOUSE: tieb = 0; break; case MIDDLEMOUSE: tieb = 1; break; case RIGHTMOUSE: tieb = 2; break; default: Yprintf(MyName, "first argument is not a button: %d.\n", button); return; } switch (val1) { case MOUSEX: break; case MOUSEY: break; default: Yprintf(MyName, "second argument is not a valuator: %d.\n", val1); return; } switch (val2) { case MOUSEX: break; case MOUSEY: break; default: Yprintf(MyName, "third argument is not a valuator: %d.\n", val2); return; } YglTie[tieb][0] = val1; YglTie[tieb][1] = val2; } static int got_sigalrm = 0; static int in_nextevent = False; static jmp_buf alrm_context; static void sigalrm_handler(int sig_no) { #ifdef DEBUG struct timeval tv; struct timezone tz; static double tm, otm; gettimeofday(&tv, NULL); tm = tv.tv_sec + 1e-6 * tv.tv_usec; fprintf(stderr, "In sigalrm_handler after %.6f sec\n", tm - otm); otm = tm; #endif got_sigalrm++; /* Bump out of XNextEvent() */ if (in_nextevent) { in_nextevent = False; longjmp(alrm_context, 1); } } void noise(Device dev, Int16 delta) { const char * MyName = "noise"; I(MyName, "%d,%d", dev, delta); if (isqueued(dev)) { switch (dev) { case TIMER0: { Ulong usec = 20000L * delta; /* default delta: 1 -> 50Hz */ struct itimerval itimer, otimer; itimer.it_interval.tv_sec = usec / 1000000; itimer.it_interval.tv_usec = usec % 1000000; itimer.it_value.tv_sec = usec / 1000000; itimer.it_value.tv_usec = usec % 1000000; #ifdef DEBUG fprintf(stderr, "ALRM time: %g sec\n", itimer.it_value.tv_sec + 1e-6 * itimer.it_value.tv_usec); #endif setitimer(ITIMER_REAL, &itimer, &otimer); } break; default: Yprintf(MyName, "device %d (%s) not implemented.\n", dev, Ygl.devicename(dev)); break; } } else { Yprintf(MyName, "device %d (%s) not queued.\n", dev, Ygl.devicename(dev)); } } void qdevice(Device dev) { const char * MyName = "qdevice"; I(MyName, "%d", dev); switch (dev) { case WINCLOSE: Yprintf(MyName, "device WINCLOSE not longer supported. Using WINQUIT instead...\n"); case WINQUIT: /* This is the event GL sends for WM_DELETE_WINDOW... */ Ygl.wm_dw_flag = True; break; case REDRAW: Ygl.EventMask |= RedrawMask; break; case INPUTCHANGE: Ygl.EventMask |= EnterLeaveMask; break; case MOUSEX: case MOUSEY: Ygl.EventMask |= PointerMotionMask; break; case LEFTMOUSE: YglButtonMask |= Button1Mask; break; case MIDDLEMOUSE: YglButtonMask |= Button2Mask; break; case RIGHTMOUSE: YglButtonMask |= Button3Mask; break; case WHEELUP: YglButtonMask |= Button4Mask; break; case WHEELDOWN: YglButtonMask |= Button5Mask; break; case KEYBD: Ygl.EventMask |= KeyMask; break; case TIMER0: { struct sigaction action, oaction; action.sa_handler = sigalrm_handler; sigfillset(&action.sa_mask); action.sa_flags = 0; if (sigaction(SIGALRM, &action, &oaction)) { perror(MyName); exit(1); } if (oaction.sa_handler) Yprintf(MyName, "TIMER0: warning: SIGALRM already used.\n"); IsQueued[TIMER0] = True; noise(TIMER0, 1); } break; default: if (change_map(dev, True)) { IsQueued[ANYKEY] = True; Ygl.EventMask |= KeyMask; } else { Yprintf(MyName, "unsupported device: %d (%s).\n", dev, Ygl.devicename(dev)); return; } break; } if (YglButtonMask) Ygl.EventMask |= ButtonMask; set_YglEventMask(); IsQueued[dev] = True; } void unqdevice(Device dev) { int i; const char * MyName = "unqdevice"; I(MyName, "%d", dev); switch (dev) { case WINCLOSE: Yprintf(MyName, "device WINCLOSE not longer supported. Using WINQUIT instead...\n"); case WINQUIT: /* This is the event GL sends for WM_DELETE_WINDOW... */ Ygl.wm_dw_flag = False; break; case REDRAW: Ygl.EventMask &= ~RedrawMask; break; case INPUTCHANGE: Ygl.EventMask &= ~EnterLeaveMask; break; case MOUSEX: case MOUSEY: Ygl.EventMask &= ~PointerMotionMask; break; case LEFTMOUSE: YglButtonMask &= ~Button1Mask; break; case MIDDLEMOUSE: YglButtonMask &= ~Button2Mask; break; case RIGHTMOUSE: YglButtonMask &= ~Button3Mask; break; case WHEELUP: YglButtonMask &= ~Button4Mask; break; case WHEELDOWN: YglButtonMask &= ~Button5Mask; break; case KEYBD: if (!IsQueued[ANYKEY]) Ygl.EventMask &= ~KeyMask; break; case TIMER0: { struct sigaction action; action.sa_handler = SIG_DFL; sigfillset(&action.sa_mask); action.sa_flags = 0; noise(TIMER0, 0); if (sigaction(SIGALRM, &action, NULL)) { perror(MyName); exit(1); } } break; default: if (!change_map(dev, False)) { Yprintf(MyName, "unsupported device: %d (%s).\n", dev, Ygl.devicename(dev)); return; } IsQueued[ANYKEY] = False; for (i = 0; i < KEYMAP_LEN; i++) IsQueued[ANYKEY] = IsQueued[ANYKEY] || (Ygl.keymap[i] & KEYMAP_BIT); if (!IsQueued[ANYKEY] && !IsQueued[KEYBD]) Ygl.EventMask &= ~KeyMask; break; } if (!YglButtonMask) Ygl.EventMask &= ~ButtonMask; set_YglEventMask(); IsQueued[dev] = False; } void qreset(void) { const char * MyName = "qreset"; I(MyName, ""); XSync(D, True); /* Don't remove saved mouse/key events, else we may never get * MOUSEY/ANYKEY events. */ /* mousex = -1; mousey = -1; mousexchanged = False; mouseychanged = False; keyevent = 0; */ } struct r_info { Window main; #ifdef RGBWIN Window win; #endif int num; int ret; }; static Bool more_redraw(Display *dpy, XEvent *e, char *rc) { struct r_info *r = (struct r_info*) rc; int ret; if ((e->type == Expose || e->type == ConfigureNotify) && (e->xany.window == r->main || IF_RGBWIN(e->xany.window == r->win, False))) { r->ret = True; /* found Expose or ConfigureNotify event for same window */ } ret = r->ret || --r->num == 0; /* return True if found or queue empty */ #ifdef DEBUG #ifdef RGBWIN fprintf(stderr, "more_redraw: type=%s, r={main=0x%x,win=0x%x,num=%d,ret=%d}, ret=%d\n", Ygl.XEventNames[e->type], r->main, r->win, r->num, r->ret, ret); #else fprintf(stderr, "more_redraw: type=%s, r={main=0x%x,num=%d,ret=%d}, ret=%d\n", Ygl.XEventNames[e->type], r->main, r->num, r->ret, ret); #endif #endif return ret; } static int check_more_redraw(Int32 wid) { XEvent p; struct r_info info; info.main = Ygl.Windows[wid].main; #ifdef RGBWIN info.win = Ygl.Windows[wid].win; #endif info.num = XPending(D); info.ret = False; if (info.num) { #ifdef DEBUG fprintf(stderr, "check_more_redraw: Calling XPeekIfEvent()\n"); #endif XPeekIfEvent(D, &p, more_redraw, (char*)&info); } return info.ret; } #define QREAD 1 #define QTEST 2 static Int32 q_next(int parent, Int16 *val) { XEvent e; Int32 dev = -1, dev2; int tieb = -1; char key; static Int16 keyevent = 0; static Int16 mousexchanged = False; static Int16 mouseychanged = False; static Int16 mousex = -1; static Int16 mousey = -1; char *caller = parent == QTEST ? "qtest" : "qread"; I(caller, ""); /* Let TIMER0, i.e. SIGALRM, bump out of XNextEvent() */ if (parent == QREAD && IsQueued[TIMER0]) if (setjmp(alrm_context)) { /* if we are here, we came from longjmp() */ #ifdef DEBUG fprintf(stderr, "SIGALRM received in XNextEvent.\n"); #endif } while (dev == -1) { if (got_sigalrm) { dev = TIMER0; *val = got_sigalrm; if (parent == QREAD) got_sigalrm = 0; } else if (mousexchanged) { /* Hack for mouse events */ dev = MOUSEX; *val = mousex; if (parent == QREAD) mousexchanged = False; } else if (mouseychanged) { /* Hack for mouse events */ dev = MOUSEY; *val = YglScreenHeight - mousey - 1; if (parent == QREAD) mouseychanged = False; } else if (keyevent > 0) { /* Hack for reporting both KEYBD and ANYKEY device */ dev = keyevent; *val = 1; /* Must be 1 (KeyPress) */ if (parent == QREAD) keyevent = 0; } else if (parent == QTEST && XPending(D) == 0) { dev = 0; } else { if (parent == QREAD) { IFOGL(glFlush(), XFlush(D)); in_nextevent = True; XNextEvent(D, &e); in_nextevent = False; } else { XPeekEvent(D, &e); } #ifdef DEBUG fprintf(stderr, "%s: e.type = %s for window 0x%x, XPending returns %d\n", caller, Ygl.XEventNames[e.type], e.xany.window, XPending(D)); #endif switch (e.type) { Int32 wid; case ConfigureNotify: case Expose: #ifdef RGBWIN wid = Ygl.x2gl_wid(e.xany.window, X2GL_WIN); if (wid == 0) wid = Ygl.x2gl_wid(e.xany.window, X2GL_MAIN); #else wid = Ygl.x2gl_wid(e.xany.window, X2GL_MAIN); #endif if (wid == 0) Yprintf(caller, "REDRAW received for unknown window\n"); if (parent == QTEST) { dev = REDRAW; } else if (e.type == Expose && e.xexpose.count != 0) { /* ignore */ #ifdef DEBUG fprintf(stderr, "%s: e.xexpose.count = %d\n", caller, e.xexpose.count); #endif } else if (check_more_redraw(wid)) { /* more Expose events for the same window in queue? */ #ifdef DEBUG fprintf(stderr, "More Expose or ConfigureNotify events for same window in queue, ignoring this one...\n", caller); #endif } else { dev = REDRAW; *val = wid; } break; case EnterNotify: dev = INPUTCHANGE; *val = Ygl.x2gl_wid(e.xany.window, X2GL_MAIN); break; case LeaveNotify: dev = INPUTCHANGE; *val = 0; break; case MotionNotify: #ifdef DEBUG fprintf(stderr, "%s: e.xmotion.x_root = %d, e.xmotion.y_root = %d\n", /**/ caller, e.xmotion.x_root, e.xmotion.y_root); #endif if (parent == QTEST) { if (mousex != e.xmotion.x_root) dev = MOUSEX; /* if both values have changed, report x first... */ else dev = MOUSEY; } else { if (mousey != e.xmotion.y_root) { mousey = e.xmotion.y_root; mouseychanged = True; } if (mousex != e.xmotion.x_root) { dev = MOUSEX; *val = mousex = e.xmotion.x_root; } } break; case KeyPress: case KeyRelease: /* Note: KeyReleases are not reported as KEYBD events */ #ifdef DEBUG fprintf(stderr, "%s: e.xkey.keycode = %d, Ygl.keymap[%d] = %d\n", caller, e.xkey.keycode, e.xkey.keycode, Ygl.keymap[e.xkey.keycode]); #endif if (IsQueued[KEYBD] && e.type == KeyPress && 1 == XLookupString(&e.xkey, &key, 1, NULL, NULL)) { /* return code */ dev = KEYBD; *val = (Int16)key; } if (IsQueued[ANYKEY] && (dev2 = Ygl.keymap[e.xkey.keycode]) & KEYMAP_BIT ) { /* Individual keys requested? */ dev2 &= (KEYMAP_BIT-1); if (dev == KEYBD) { /* first report KEYBD event */ if (parent == QREAD) keyevent = dev2; } else { dev = dev2; *val = e.type == KeyPress ? 1 : 0; } } break; case ButtonPress: case ButtonRelease: switch (e.xbutton.button) { case Button1: if (YglButtonMask & Button1Mask) { dev = LEFTMOUSE; if (parent == QREAD) tieb = 0; } break; case Button2: if (YglButtonMask & Button2Mask) { dev = MIDDLEMOUSE; if (parent == QREAD) tieb = 1; } break; case Button3: if (YglButtonMask & Button3Mask) { dev = RIGHTMOUSE; if (parent == QREAD) tieb = 2; } break; case Button4: if (YglButtonMask & Button4Mask) { dev = WHEELUP; } break; case Button5: if (YglButtonMask & Button5Mask) { dev = WHEELDOWN; } break; default: Yprintf(caller, "unknown button: %d.\n", e.xbutton.button); break; } if (parent == QREAD && dev != -1) { *val = e.type == ButtonPress ? 1 : 0; if (tieb != -1) { switch (YglTie[tieb][0]) { case MOUSEX: mousexchanged = True; mousex = e.xbutton.x_root; break; case MOUSEY: mouseychanged = True; mousey = e.xbutton.y_root; break; } switch (YglTie[tieb][1]) { case MOUSEX: mousexchanged = True; mousex = e.xbutton.x_root; break; case MOUSEY: mouseychanged = True; mousey = e.xbutton.y_root; break; } } } break; case ClientMessage: #ifdef DEBUG fprintf(stderr, "%s: e.xclient.message_type = %d\n", caller, e.xclient.message_type); #endif dev = WINQUIT; *val = Ygl.x2gl_wid(e.xany.window, X2GL_MAIN); break; case CirculateNotify: case CreateNotify: case DestroyNotify: case GravityNotify: case ReparentNotify: case MapNotify: case UnmapNotify: /* Ignore these Events... */ break; case MappingNotify: /* We should reload Ygl.keymap[] here, but who cares... */ break; default: Yprintf(caller, "unknown event (type=%d) for window %d(0x%x) received.\n", e.type, Ygl.x2gl_wid(e.xany.window, X2GL_MAIN), e.xany.window); break; } /* end switch */ if (dev == -1 && parent == QTEST) { #ifdef DEBUG fprintf(stderr, "qtest: eating event: e.type = %d(%s)\n", e.type, Ygl.XEventNames[e.type]); #endif XNextEvent(D, &e); /* read and ignore unreported events so they don't block the queue */ } if (dev != -1 && parent == QREAD) Ygl.lastreadevent = e; } } #ifdef DEBUG if (dev != 0) fprintf(stderr, "%s: returning dev = %d (%s), *val = %d\n", caller, dev, Ygl.devicename(dev), *val); #endif return dev; } Int32 qtest(void) { Int16 val; return q_next(QTEST, &val); } Int32 qread(Int16 *val) { return q_next(QREAD, val); } void qenter(Int16 dev, Int16 val) { XEvent e; const char * MyName = "qenter"; I(MyName, "%d,%d", dev, val); switch (dev) { case REDRAW: e.type = Expose; /* if RGBWIN, send to .win, not .main */ e.xexpose.window = (val > 0 && val < Ygl.NextWindow) ? Ygl.Windows[val].IF_RGBWIN(win,main) : 0; e.xexpose.count = 0; break; #if 0 case INPUTCHANGE: Yprintf(MyName, "unsupported device: INPUTCHANGE.\n") ; return; break; /* e.type = EnterNotify; e.xcrossing.window = val; break; */ case KEYBD: Yprintf(MyName, "unsupported device: KEYBD.\n") ; return; break; case MENUBUTTON: Yprintf(MyName, "unsupported device: MENUBUTTON.\n") ; return; break; #endif default: Yprintf(MyName, "unsupported device: %d (%s).\n", dev, Ygl.devicename(dev)); return; break; } XPutBackEvent(D, &e); } #ifdef OGL /* picking/names stuff */ static Int32 pick_bufferlen, mySelectBufferLen; static GLuint *mySelectBuffer; static Int16 picksize_deltax = 10; static Int16 picksize_deltay = 10; void picksize(Int16 deltax, Int16 deltay) { const char * MyName = "picksize"; I(MyName, "%d,%d", deltax, deltay); if(!Ygl.UseOGL) NI(MyName); picksize_deltax = deltax; picksize_deltay = deltay; } void pick(Int16 buffer[], Int32 bufferlen) { const char * MyName = "pick"; I(MyName, "0x%x,%d", buffer, bufferlen); if(!Ygl.UseOGL) NI(MyName); if (Ygl.SelectMode) { Yprintf(MyName, "already in picking mode\n"); return; } pick_bufferlen = bufferlen; /* save for endpick() */ mySelectBufferLen = 4 * bufferlen; /* should be sufficient */ mySelectBuffer = (GLuint*) calloc(mySelectBufferLen, sizeof(GLuint)); if (mySelectBuffer == NULL) { Yprintf(MyName, "can't allocate memory.\n"); exit(1); } glSelectBuffer(mySelectBufferLen, mySelectBuffer); #ifndef VIEWPICK glRenderMode(GL_SELECT); #endif Ygl.SelectMode = True; initnames(); { Window junkwin; int rx, ry, cx, cy; Uint mask; GLint viewport[4]; GLdouble x, y, delx, dely; glGetIntegerv(GL_VIEWPORT, viewport); XQueryPointer(D, W->main, &junkwin, &junkwin, &rx, &ry, &cx, &cy, &mask); #ifdef DEBUG fprintf(stderr, "pick: root = (%d,%d), child = (%d,%d) mask=0x%x\n", rx, ry, cx, cy, mask); #endif x = (double)cx; y = (double)viewport[3] - cy; delx = (double)picksize_deltax; dely = (double)picksize_deltay; glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); #ifdef DEBUG fprintf(stderr, "pick: gluPickMatrix(%g, %g, %g, %g, (%d,%d,%d,%d))\n", x, y, delx, dely, viewport[0],viewport[1],viewport[2],viewport[3]); #endif gluPickMatrix(x, y, delx, dely, viewport); glMatrixMode(GL_MODELVIEW); } } Int32 endpick(Int16 buffer[]) { const char * MyName = "endpick"; Int32 hits, i, bi, mi; I(MyName, "0x%x", buffer); if(!Ygl.UseOGL) NIR(MyName, 0); if (!Ygl.SelectMode) { Yprintf(MyName, "not in picking mode\n"); return 0; } glMatrixMode(GL_PROJECTION); glPopMatrix(); /* pushed in pick() */ glMatrixMode(GL_MODELVIEW); Ygl.SelectMode = False; hits = glRenderMode(GL_RENDER); #ifdef VIEWPICK swapbuffers(); #endif #ifdef DEBUG Yprintf(MyName, "mySelectBuffer[0..%d] : ", MIN(mySelectBufferLen, 20) - 1); for(i = 0; i < MIN(mySelectBufferLen, 20); i++) { fprintf(stderr, "%d ", mySelectBuffer[i]); } fprintf(stderr, "\n"); #endif #define BUF_CHK() (bi < pick_bufferlen && mi < mySelectBufferLen) /* copy select buffer from OpenGL to GL format */ for(i = bi = mi = 0; i < hits; i++) { GLuint depth = 0; /* stack depth */ if (BUF_CHK()) depth = buffer[bi++] = mySelectBuffer[mi++]; else hits = -i; /* return -valid hits if buffer too small */ mi += 2; /* skip depth info */ for (; depth > 0; depth--) { if (BUF_CHK()) buffer[bi++] = mySelectBuffer[mi++]; else hits = -i; } } #undef BUF_CHK if (mi >= mySelectBufferLen) { /* should not happen... */ Yprintf(MyName, "mySelectBuffer too small, this should not happen\n"); } free(mySelectBuffer); #ifdef DEBUG Yprintf(MyName, "hits = %d, buffer[0..%d] : ", hits, bi - 1); for(i = 0; i < bi; i++) { fprintf(stderr, "%d ", buffer[i]); } fprintf(stderr, "\n"); #endif return hits; } void initnames(void) { const char * MyName = "initnames"; I(MyName, ""); if(!Ygl.UseOGL) NI(MyName); glInitNames(); glPushName(-1); /* Why do we have to push someting onto the stack? */ } void loadname(Int16 name) { const char * MyName = "loadname"; I(MyName, "%d", name); if(!Ygl.UseOGL) NI(MyName); glLoadName(name); } void pushname(Int16 name){ const char * MyName = "pushname"; I(MyName, "%d", name); if(!Ygl.UseOGL) NI(MyName); glPushName(name); } void popname(void){ const char * MyName = "popname"; I(MyName, ""); if(!Ygl.UseOGL) NI(MyName); glPopName(); } #endif /* OGL */ ygl-4.2e/menu.c0000444000175000017500000003635110620057057012763 0ustar prabhuprabhu/* * Ygl: Run GL programs with standard X11 routines. * (C) Fred Hucht 1993-2007 * EMail: fred@thp.Uni-Duisburg.de */ static const char vcid[] = "$Id: menu.c,v 3.6 2007-05-08 13:25:35+02 fred Exp $"; #include "header.h" #include #include #define MENUPADW 14 #define MENUPADH 4 #define MENUSHADE 8 #define SUBMENUOFFSET 10 #define ON 1 #define OFF 0 typedef Int32(*YglMenuCallback)(Int32, ...); typedef struct YglMenu_ { Window win; int nitem; int x, y; Uint w, h; struct YglMenuItem_ *longest; struct YglMenuItem_ **item; } YglMenu; typedef struct YglMenuItem_ { char *name; YglMenuCallback callback; struct YglMenu_ *submenu; Int32 retval; Int32 mode; Uint callF:1; Uint line:1; } YglMenuItem; static YglMenu **YglMenus = NULL; static int YglLastMenu; static GC menugc = NULL; static Cursor menucursor; static int fontascent; static int menuheight; static int white, black; static YglMenu *mid_to_m(const char *caller, Int32 mid); static void add_to_pup(const char *caller, Int32 mid, const char *string, va_list argp); static void create_menu(YglMenu *m); static void map_menu(YglMenu *m, YglMenu *parent, int item); static int do_pup(YglMenu *m, int issub); static Int32 displayitem(YglMenu *m, int i, int on, int dosub); static void create_menu(YglMenu *m) { if(menugc == NULL) { XColor fg, bg; menucursor = XCreateFontCursor(D, XC_right_ptr); bg.red = 0 ; bg.green = 0 ; bg.blue = 0xffff; fg.red = 0xffff; fg.green = 0xffff; fg.blue = 0 ; XRecolorCursor(D, menucursor, &fg, &bg); black = YGL_COLORS(BLACK); white = YGL_COLORS(WHITE); } { Ulong mask = 0; XSetWindowAttributes swa; mask |= CWBackPixmap; swa.background_pixmap = None; mask |= CWSaveUnder; swa.save_under = True; mask |= CWEventMask; swa.event_mask = ExposureMask /*StructureNotifyMask*/; mask |= CWOverrideRedirect; swa.override_redirect = True; mask |= CWColormap; swa.colormap = Ygl.CCmap; mask |= CWCursor; swa.cursor = menucursor; m->win = XCreateWindow(D, RootWindow(D, YglScreen), 0, 0, m->w + MENUSHADE, m->h + MENUSHADE, 0, Ygl.CV.depth, InputOutput, Ygl.CV.visual, mask, &swa); } if(menugc == NULL) { Ulong mask = 0; XGCValues gcv; Pixmap stipple; stipple = XCreatePixmapFromBitmapData(D, m->win, gray1_bits, gray1_width, gray1_height, black, white, 1); mask |= GCGraphicsExposures; gcv.graphics_exposures = False; mask |= GCLineWidth; gcv.line_width = 0; mask |= GCForeground; gcv.background = black; mask |= GCBackground; gcv.foreground = white; mask |= GCStipple; gcv.stipple = stipple; menugc = XCreateGC(D, m->win, mask, &gcv); } } static YglMenu *mid_to_m(const char *caller, Int32 mid) { if(mid < 1 || mid > YglLastMenu || YglMenus[mid] == NULL) { Yprintf(caller, "invalid menu id: %d\n", mid); exit(1); } return YglMenus[mid]; } static void add_to_pup(const char *caller, Int32 mid, const char *s, va_list argp) { YglMenu *m; int i; m = mid_to_m(caller, mid); for(i = 0; s[i];) { YglMenuItem *next; char buf[1024], *bufp = buf; int tflag = False; next = m->item[m->nitem]; next->callF = True; next->callback = NULL; next->submenu = NULL; next->retval = m->nitem; next->mode = PUP_NONE; next->line = False; #ifdef DEBUG fprintf(stderr, "add_to_pup: caller = '%s', mid = %d, i = %d, string = '%s'\n", caller, mid, i, &s[i]); #endif for(;s[i] && s[i] != '|'; i++) { switch(s[i]) { case '%': i++; switch(s[i]) { case '%': *bufp++ = s[i]; break; case 't': tflag = True; next = m->item[0]; break; case 'F': /* m->item[0]->callback = (Int32(*)(Int32, ...)) va_arg(argp, void*);*/ m->item[0]->callback = va_arg(argp, YglMenuCallback); #ifdef DEBUG fprintf(stderr, "added %%F callback = 0x%x\n", m->item[0]->callback); #endif break; case 'n': case 'm': next->callF = False; /* No break */ case 'f': case 'M': /* %M is not available in SGI's gl. See examples/popup.c. */ if(tflag) { Yprintf(caller, "invalid combination of '%%t' and '%%%c' in '%s', position %d\n", s[i], s, i); exit(1); } if(s[i] == 'm' || s[i] == 'M') { Int32 mid = va_arg(argp, Int32); next->submenu = mid_to_m(caller, mid); #ifdef DEBUG fprintf(stderr, "added %%m submenu = %d\n", mid); #endif } else { /* 'f' or 'n' */ next->callback = va_arg(argp, YglMenuCallback); /* (Int32(*)(Int32, ...)) va_arg(argp, void*); */ #ifdef DEBUG fprintf(stderr, "added %%fn callback = 0x%x\n", next->callback); #endif } break; case 'x': { char *endp; i++; next->retval = (Int32) strtol(&s[i], &endp, 0); i = endp - s - 1; } break; case 'l': next->line = True; break; default: Yprintf(caller, "unknown token '%%%c' in '%s', position %d\n", s[i], s, i); /* exit(1); */ break; } break; default: *bufp++ = s[i]; break; } } /* for(;...) */ *bufp = '\0'; if(NULL == (next->name = (char*)malloc(strlen(buf) + 1))) { Yprintf(caller, "can't allocate memory.\n"); exit(-1); } strcpy(next->name, buf); if (strlen(next->name) > strlen(m->longest->name)) m->longest = next; if(!tflag) { m->nitem++; if(NULL == (m->item = (YglMenuItem**)realloc(m->item, (m->nitem + 1) * sizeof(YglMenuItem*))) || NULL == (m->item[m->nitem] = (YglMenuItem*)calloc(1, sizeof(YglMenuItem)))) { Yprintf(caller, "can't allocate memory.\n"); exit(-1); } } if(s[i] == '|') i++; } /* for */ } static Int32 displayitem(YglMenu *m, int i, int on, int dosub) { int fg = 0, bg = 0, r = -1; YglMenuItem *item; if(i == -1) return -1; item = m->item[i]; switch(item->mode) { case PUP_GREY: XSetFillStyle(D, menugc, FillStippled); fg = bg = black; break; case PUP_NONE: if(on) { fg = white; bg = black; } else { bg = white; fg = black; } break; } XSetForeground(D, menugc, bg); XFillRectangle(D, m->win, menugc, 1, menuheight * i + 5, m->w - 1, menuheight); XSetForeground(D, menugc, fg); XSetFillStyle(D, menugc, FillSolid); XDrawString(D, m->win, menugc, MENUPADW, menuheight * i + (menuheight + fontascent)/2 + 3, item->name, strlen(item->name)); if(item->line) XDrawLine(D, m->win, menugc, 1, menuheight * (i + 1) + 4, m->w - 1, menuheight * (i + 1) + 4); if(item->submenu) { XPoint arrow[] = {{0, 0}, {-6, -3}, {0, 6}, {6, -3}}; arrow[0].x = m->w - SUBMENUOFFSET + 6; arrow[0].y = menuheight * i + menuheight/2 + 4; XFillPolygon(D, m->win, menugc, arrow, 4, Convex, CoordModePrevious); if(dosub && item->mode != PUP_GREY) { if(on) { map_menu(item->submenu, m, i); r = do_pup(item->submenu, True); } else { XUnmapWindow(D, item->submenu->win); } } } return r; } static void map_menu(YglMenu *m, YglMenu *parent, int item) { int i; if(parent == NULL) { /* Mainmenu */ m->x = Ygl.lastreadevent.xbutton.x_root; m->y = Ygl.lastreadevent.xbutton.y_root - menuheight; } else { /* Submenu */ m->x = parent->x + parent->w - SUBMENUOFFSET; m->y = parent->y + item * menuheight + 4; } m->w = strwidth(m->longest->name) + 2 * MENUPADW; m->h = m->nitem * menuheight + 5; #ifdef DEBUG fprintf(stderr, "map_menu: width = %d height = %d longest = %s\n", m->w, m->h, m->longest->name); #endif XMoveResizeWindow(D, m->win, MIN(m->x, YglScreenWidth - (m->w + MENUSHADE)) - 2, MIN(m->y, YglScreenHeight - (m->h + MENUSHADE)) - 2, m->w + MENUSHADE, m->h + MENUSHADE); XMapRaised(D, m->win); XSync(D, False); /* SaveUnder doesn't work properly when we only wait for MapNotify. Strange */ /*Ygl.await_windowevent(m->win, StructureNotifyMask, MapNotify);*/ Ygl.await_windowevent(m->win, ExposureMask, Expose); XSetForeground(D, menugc, white); XFillRectangle(D, m->win, menugc, 0, 0, m->w, m->h); XSetForeground(D, menugc, black); XDrawRectangle(D, m->win, menugc, 0, 0, m->w, m->h); XSetFillStyle(D, menugc, FillStippled); XFillRectangle(D, m->win, menugc, m->w, MENUSHADE, MENUSHADE, m->h); XFillRectangle(D, m->win, menugc, MENUSHADE, m->h, m->w - MENUSHADE, MENUSHADE); XSetFillStyle(D, menugc, FillSolid); XDrawString(D, m->win, menugc, (m->w - strwidth(m->item[0]->name)) / 2, (menuheight + fontascent)/2 + 2, m->item[0]->name, strlen(m->item[0]->name)); XDrawRectangle(D, m->win, menugc, 2, 2, m->w - 4, menuheight); XDrawLine(D, m->win, menugc, 0, menuheight + 4, m->w, menuheight + 4); for (i = 1; i < m->nitem; i++) { displayitem(m, i, OFF, 0); } } static int do_pup(YglMenu *m, int issub) { int menuval = -1, oldmenuval = -1, r, subr = -1, olddosub = -1; Uint mask; YglMenuItem *item = NULL; do { Window root, win; int rx, ry, wx, wy, dosub; subr = -1; #if DEBUG > 1 fprintf(stderr, "XQ: win = 0x%x\n", m->win); #endif XQueryPointer(D, m->win, &root, &win, &rx, &ry, &wx, &wy, &mask); dosub = wx > m->w - SUBMENUOFFSET; if(issub && wx < 0) { /* Close submenus on left leave */ menuval = -1; break; } if(wx > 0 && wx < m->w && wy > menuheight + 4 && wy < menuheight * m->nitem + 4) { menuval = (wy - 4) / menuheight; item = m->item[menuval]; if(oldmenuval != menuval || olddosub != dosub) { /* Something changed */ #ifdef DEBUG fprintf(stderr, "menuval = %d old = %d\n", menuval, oldmenuval); #endif /* */ displayitem(m, oldmenuval, OFF, dosub); subr = displayitem(m, menuval, ON, dosub); oldmenuval = menuval; olddosub = dosub; } } else if(oldmenuval != -1) { displayitem(m, oldmenuval, OFF, dosub); oldmenuval = menuval = -1; } } while(subr == -1 && mask & Button3Mask); #ifdef DEBUG if(subr >= 0) fprintf(stderr, "while done, subr = %d, menuval = %d, retval = %d, " "item[0]->callback = 0x%x, callback = 0x%x\n", subr, menuval, item->retval, m->item[0]->callback, item->callback); #endif XUnmapWindow(D, m->win); if(subr != -1) { if(item->callF && m->item[0]->callback) { #ifdef DEBUG Int32 prev = subr; #endif subr = m->item[0]->callback(menuval, subr); #ifdef DEBUG fprintf(stderr, "do_pupx: %%F(%d, %d) = %d\n", menuval, prev, subr); #endif } return subr; } if(menuval != -1 && item->submenu == NULL && item->mode != PUP_GREY) { /* Valid item selected */ r = item->retval; if(item->callback) { #ifdef DEBUG Int32 prev = r; #endif r = item->callback(r); #ifdef DEBUG fprintf(stderr, "do_pup: %%f(%d) = %d\n", prev, r); #endif } if(item->callF && m->item[0]->callback) { #ifdef DEBUG Int32 prev = r; #endif r = m->item[0]->callback(r); #ifdef DEBUG fprintf(stderr, "do_pup: %%F(%d) = %d\n", prev, r); #endif } } else { r = -1; } return r; } Int32 newpup(void) { YglMenu *m; int mid; const char * MyName = "newpup"; I(MyName, ""); if(YglMenus == NULL) { /* initialize */ mid = YglLastMenu = 1; YglMenus = (YglMenu**)malloc(2 * sizeof(YglMenu*)); /* First el. never used */ } else { for(mid = 1; mid <= YglLastMenu && YglMenus[mid] != NULL; mid++); if(mid > YglLastMenu) { YglLastMenu++; YglMenus = (YglMenu**)realloc(YglMenus, (YglLastMenu + 1) * sizeof(YglMenu*)); } } if(YglMenus == NULL || NULL == (m = YglMenus[mid] = (YglMenu*)calloc(1, sizeof(YglMenu)))) { Yprintf(MyName, "can't allocate memory.\n"); exit(-1); } if(NULL == (m->item = (YglMenuItem**)malloc(2 * sizeof(YglMenuItem*))) || NULL == (m->item[0] = (YglMenuItem*)calloc(1, sizeof(YglMenuItem))) || NULL == (m->item[1] = (YglMenuItem*)calloc(1, sizeof(YglMenuItem))) || NULL == (m->item[0]->name = malloc(16))) { Yprintf(MyName, "can't allocate memory.\n"); exit(-1); } sprintf(m->item[0]->name, "Menu %d", mid); m->item[0]->callback = NULL; m->longest = m->item[0]; m->nitem = 1; m->w = 10; m->h = 10; create_menu(m); #ifdef DEBUG fprintf(stderr, "newpup: ready, mid = %d, m = 0x%x\n", mid, m); #endif return mid; } Int32 defpup(Char8 *string, ...) { Int32 mid; va_list Argp; const char * MyName = "defpup"; I(MyName, "'%s',...", string); mid = newpup(); va_start(Argp, string); add_to_pup(MyName, mid, string, Argp); va_end(Argp); return mid; } void addtopup(Int32 mid, Char8 *string, ...) { va_list Argp; const char * MyName = "addtopup"; I(MyName, "%d,'%s',...", mid, string); va_start(Argp, string); add_to_pup(MyName, mid, string, Argp); va_end(Argp); } void freepup(Int32 mid) { YglMenu *m; int i; const char * MyName = "freepup"; I(MyName, "%d", mid); m = mid_to_m(MyName, mid); XDestroyWindow(D, m->win); for(i = 0; i <= m->nitem; i++) { if(m->item[i]->name) free(m->item[i]->name); free(m->item[i]); } free(m->item); free(m); YglMenus[mid] = NULL; } void setpup(Int32 mid, Int32 entry, Int32 mode) { YglMenu *m; const char * MyName = "setpup"; I(MyName, "%d,%d,%d", mid, entry, mode); m = mid_to_m(MyName, mid); if(entry < 1 || entry > m->nitem - 1) { Yprintf(MyName, "entry %d in menu %d does not exist.\n", entry, mid); return; } switch(mode) { case PUP_NONE: case PUP_GREY: m->item[entry]->mode = mode; break; default: Yprintf(MyName, "invalid mode: %d.\n", mode); return; } } Int32 dopup(Int32 mid) { YglMenu *m; Int32 r; const char * MyName = "dopup"; Colormap *cmaps; int i, numcmaps, install = 1; /*Window CMapWindows[3];*/ I(MyName, "%d", mid); m = mid_to_m(MyName, mid); if(Ygl.lastreadevent.type != ButtonPress) { Yprintf(MyName, "last event was not ButtonPress.\n"); return -1; } XSetFont(D, menugc, Ygl.Fonts[W->font].fs->fid); fontascent = Ygl.Fonts[W->font].fs->ascent; menuheight = MENUPADH + Ygl.Fonts[W->font].fs->descent + fontascent; cmaps = XListInstalledColormaps(D, m->win, &numcmaps); /* Do we have to install menu cmap? */ for(i = 0; i < numcmaps && (install &= cmaps[i] != Ygl.CCmap); i++); #if 0 /* Any better idea how to get the cmap installed when popping up the menu in RGB mode??? */ CMapWindows[0] = m->win; CMapWindows[1] = W->win; CMapWindows[2] = W->top; if(XSetWMColormapWindows(D, W->top, CMapWindows, 3) == 0) { Yprintf(MyName, "cannot change WM_COLORMAP_WINDOWS property.\n"); } /*XUngrabPointer(D, 0);*/ #endif if(install) { #ifdef DEBUG fprintf(stderr, "dopup: installing colormap\n"); #endif XInstallColormap(D, Ygl.CCmap); /* As we may be in RGBmode */ } /* Switch cursor on */ XChangeActivePointerGrab(D, 0, menucursor, CurrentTime); map_menu(m, NULL, 0); r = do_pup(m, False); /* Restore installed colormaps */ if(install) for(i = 0; i < numcmaps; i++) XInstallColormap(D, cmaps[i]); XFree((char*) cmaps); return r; } ygl-4.2e/makeYgltypes.c0000444000175000017500000000203406407303152014462 0ustar prabhuprabhu/* * Ygl: Run GL programs with standard X11 routines. * (C) Fred Hucht 1993-97 * EMail: fred@thp.Uni-Duisburg.DE * * $Id: makeYgltypes.c,v 4.4 1997-09-15 21:03:06+02 fred Exp $ */ #include int main() { int i; int done[] = {0,0}; char *prefix[] = {" Int", "Float"}; struct { int len; int i_f; char *name; } sz[] = { {sizeof(char), 0, "char "}, {sizeof(short), 0, "short "}, {sizeof(int), 0, "int "}, {sizeof(long), 0, "long "}, {sizeof(float), 1, "float "}, {sizeof(double), 1, "double"}, {-1, -1,""} }; printf("/*\n" " * Automagically created by makeYgltypes. Do not change!\n" " */\n"); for(i = 0; sz[i].len > 0; i++) { int i_f = sz[i].i_f; if(!(done[i_f] & sz[i].len)) { done[i_f] |= sz[i].len; printf("typedef %s%s %s%d;\n", i_f ? " " : "signed ", sz[i].name, prefix[i_f], 8*sz[i].len); if(i_f == 0) printf("typedef unsigned %s Uint%d;\n", sz[i].name, 8*sz[i].len); } } return 0; } ygl-4.2e/3d.c0000444000175000017500000006150310620057353012321 0ustar prabhuprabhu/* * Ygl: Run GL programs with standard X11 and/or OpenGL routines. * (C) Fred Hucht 1996-2007 * EMail: fredthp.Uni-Duisburg.de */ static const char vcid[] = "$Id: 3d.c,v 4.9 2007-05-08 13:28:43+02 fred Exp $"; #include "header.h" #ifdef OGL static int msingle = 1; /* IrisGL is in single matrix mode per default */ #endif /* * Projection transformations (apply to projection matrix stack) */ void ortho(Coord left, Coord right, Coord bottom, Coord top, Coord near, Coord far) { const char * MyName = "ortho"; I(MyName, "%g,%g,%g,%g,%g,%g", left, right, bottom, top, near, far); IFOGL( GLint old; glGetIntegerv(GL_MATRIX_MODE, &old); /* save old mmode */ glMatrixMode(GL_PROJECTION); /*switch to PROJECTION mode*/ if (!Ygl.SelectMode) glLoadIdentity(); /* reset matrix */ glOrtho(left, right, bottom, top, near, far); if (msingle || Ygl.SelectMode) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } glMatrixMode(old), /* restore mmode */ /* In X11 2d mode we allow ortho() calls and ignore the z-component */ ortho2(left, right, bottom, top) ); } #ifdef OGL /* the remaining stuff is only available in OpenGL mode */ void perspective(Angle ang, Float32 aspect, Coord near, Coord far) { const char * MyName = "perspective"; GLint old; I(MyName, "%d,%g,%g,%g", ang, aspect, near, far); if(!Ygl.UseOGL) NI(MyName); glGetIntegerv(GL_MATRIX_MODE, &old); glMatrixMode(GL_PROJECTION); if (!Ygl.SelectMode) glLoadIdentity(); gluPerspective(0.1 * ang, aspect, near, far); if (msingle || Ygl.SelectMode) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } glMatrixMode(old); } void window(Coord left, Coord right, Coord bottom, Coord top, Coord near, Coord far) { const char * MyName = "window"; GLint old; I(MyName, "%g,%g,%g,%g,%g,%g", left, right, bottom, top, near, far); if(!Ygl.UseOGL) NI(MyName); glGetIntegerv(GL_MATRIX_MODE, &old); glMatrixMode(GL_PROJECTION); if (!Ygl.SelectMode) glLoadIdentity(); glFrustum(left, right, bottom, top, near, far); if (msingle || Ygl.SelectMode) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } glMatrixMode(old); } /* * Coordinate transformations */ void lookat(Coord eyex, Coord eyey, Coord eyez, Coord cenx, Coord ceny, Coord cenz, Angle twist) { const char * MyName = "lookat"; GLdouble rx = cenx - eyex; GLdouble ry = ceny - eyey; GLdouble rz = cenz - eyez; GLdouble upx, upy, upz; I(MyName, "%g,%g,%g,%g,%g,%g,%d", eyex, eyey, eyez, cenx, ceny, cenz, twist); if(!Ygl.UseOGL) NI(MyName); if(rx != 0.0 || rz != 0.0) { /* OK, view line is not y-axis, so up direction is y-axis */ upx = 0.0; upy = 1.0; upz = 0.0; } else { /* Special case: looking along y-axis, up = -z */ upx = 0.0; upy = 0.0; upz = -1.0; } gluLookAt(eyex, eyey, eyez, cenx, ceny, cenz, upx, upy, upz); glRotatef(0.1 * twist, rx, ry, rz); } void polarview(Coord distance, Angle azim, Angle inc, Angle twist) { const char * MyName = "polarview"; I(MyName, "%g,%d,%d,%d", distance, azim, inc, twist); if(!Ygl.UseOGL) NI(MyName); glTranslatef(0.0, 0.0, -distance); glRotatef(-0.1 * twist, 0.0, 0.0, 1.0); glRotatef(-0.1 * inc, 1.0, 0.0, 0.0); glRotatef(-0.1 * azim, 0.0, 0.0, 1.0); } void rotate(Angle angle, Char8 axis) { const char * MyName = "rotate"; I(MyName, "%d,'%c'", angle, axis); if(!Ygl.UseOGL) NI(MyName); rot(0.1 * angle, axis); } void rot(Float32 angle, Char8 axis) { const char * MyName = "rot"; GLfloat x = 0.0F, y = 0.0F, z = 0.0F; I(MyName, "%g,'%c'", angle, axis); if(!Ygl.UseOGL) NI(MyName); switch(axis) { case 'x': case 'X': x = 1.0F; break; case 'y': case 'Y': y = 1.0F; break; case 'z': case 'Z': z = 1.0F; break; default: Yprintf(MyName, "invalid axis '%c'.\n", axis); return; } glRotatef(angle, x, y, z); } void translate(Coord x, Coord y, Coord z) { const char * MyName = "translate"; I(MyName, "%g,%g,%g", x, y, z); if(!Ygl.UseOGL) NI(MyName); glTranslatef(x, y, z); } void scale(Float32 x, Float32 y, Float32 z) { const char * MyName = "scale"; I(MyName, "%g,%g,%g", x, y, z); if(!Ygl.UseOGL) NI(MyName); glScalef(x, y, z); #if 0 /* done in setup_visuals */ if(x != 1.0 || y != 1.0 || z != 1.0) { glEnable(GL_NORMALIZE); /* Could be better... */ } #endif } /* * Matrix ops */ void pushmatrix(void) { const char * MyName = "pushmatrix"; I(MyName, ""); if(!Ygl.UseOGL) NI(MyName); glPushMatrix(); } void popmatrix(void) { const char * MyName = "popmatrix"; I(MyName, ""); if(!Ygl.UseOGL) NI(MyName); glPopMatrix(); } void loadmatrix(Matrix m) { const char * MyName = "loadmatrix"; GLfloat glm[16]; short i, j; I(MyName, "Matrix"); if(!Ygl.UseOGL) NI(MyName); /* Under OpenGL matrices are in column order, transpose... */ for(i = 0; i < 4; i++) for(j = 0; j < 4; j++) glm[4*j + i] = m[i][j]; glLoadMatrixf(glm); } /* getmatrix: see misc.c */ void multmatrix(Matrix m) { const char * MyName = "multmatrix"; GLfloat glm[16]; short i, j; I(MyName, "Matrix"); if(!Ygl.UseOGL) NI(MyName); /* Under OpenGL matrices are in column order, transpose... */ for(i = 0; i < 4; i++) for(j = 0; j < 4; j++) glm[4*j + i] = m[i][j]; glMultMatrixf(glm); } void mmode(Int16 mode) { const char * MyName = "mmode"; I(MyName, "%d", mode); if(!Ygl.UseOGL) NI(MyName); switch(mode) { case MSINGLE: msingle = 1; glMatrixMode(GL_MODELVIEW); break; case MPROJECTION: msingle = 0; glMatrixMode(GL_PROJECTION); break; case MVIEWING: msingle = 0; glMatrixMode(GL_MODELVIEW); break; default: Yprintf(MyName, "invalid mode %d.\n", mode); break; } } Int32 getmmode(void) { const char * MyName = "getmmode"; GLint mode; I(MyName, ""); if(!Ygl.UseOGL) NIR(MyName, -1); glGetIntegerv(GL_MATRIX_MODE, &mode); switch(mode) { case GL_MODELVIEW: return MVIEWING; case GL_PROJECTION: return MPROJECTION; default: Yprintf(MyName, "strange OpenGL matrix mode %d\n", mode); return -1; } } /* * z-buffer stuff */ void depthcue(Int32 mode) { const char * MyName = "depthcue"; I(MyName, "%d", mode); if(!Ygl.UseOGL) NI(MyName); if(!Ygl.PCM && !W->rgb) { Yprintf(MyName, "private colormap required.\n"); return; } switch (mode) { case True: glEnable (GL_FOG); break; case False: glDisable(GL_FOG); break; default: Yprintf(MyName, "invalid mode %d.\n", mode); return; } } #define GL2OGL_Z(z) (((double)(z) + 0x800000)/0xFFFFFF) void lshaderange(Colorindex low, Colorindex high, Int32 near, Int32 far) { const char * MyName = "lshaderange"; I(MyName, "%d,%d,%d,%d", low, high, near, far); if(!Ygl.UseOGL) NI(MyName); glFogi(GL_FOG_MODE, GL_LINEAR); glFogi(GL_FOG_START, near); glFogi(GL_FOG_END, far); glFogi(GL_FOG_INDEX, YGL_COLORS(low)); } void lRGBrange(Int16 rmin, Int16 gmin, Int16 bmin, Int16 rmax, Int16 gmax, Int16 bmax, Int32 near, Int32 far) { const char * MyName = "lRGBrange"; GLfloat color[3]; I(MyName, "%d,%d,%d,%d,%d,%d,%d,%d", rmin, gmin, bmin, rmax, gmax, bmax, near, far); if(!Ygl.UseOGL) NI(MyName); color[0] = rmax; color[1] = gmax; color[2] = bmax; glFogi(GL_FOG_MODE, GL_LINEAR); glFogi(GL_FOG_START, near); glFogi(GL_FOG_END, far); glFogfv(GL_FOG_COLOR, color); } void zbuffer(Int32 mode) { const char * MyName = "zbuffer"; I(MyName, "%d", mode); if(!Ygl.UseOGL) NI(MyName); switch (mode) { case True: glEnable (GL_DEPTH_TEST); break; case False: glDisable(GL_DEPTH_TEST); break; default: Yprintf(MyName, "invalid mode %d.\n", mode); return; } } void lsetdepth(Int32 near, Int32 far) { const char * MyName = "lsetdepth"; I(MyName, "%d,%d", near, far); if(!Ygl.UseOGL) NI(MyName); glDepthRange(GL2OGL_Z(near), GL2OGL_Z(far)); } void zclear(void) { const char * MyName = "zclear"; I(MyName, ""); if(!Ygl.UseOGL) NI(MyName); /*glClearDepth(1.0);*/ glClear(GL_DEPTH_BUFFER_BIT); } void zdraw(Int32 bool) { const char * MyName = "zdraw"; I(MyName, "%d", bool); if(!Ygl.UseOGL) NI(MyName); glDepthMask(bool); } void czclear(Int32 cval, Int32 zval) { const char * MyName = "czclear"; I(MyName, "%d,%d", cval, zval); if(!Ygl.UseOGL) NI(MyName); glClearDepth(GL2OGL_Z(zval)); /*if(Ygl.RGB) glClearColor(glColor4ubv((GLubyte *)&cval); else */ glClearIndex(cval); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } void zfunction(Int32 func) { const char * MyName = "zfunction"; GLenum glfunc; I(MyName, "%d", func); if(!Ygl.UseOGL) NI(MyName); switch(func) { case ZF_NEVER: glfunc = GL_NEVER; break; case ZF_LESS: glfunc = GL_LESS; break; case ZF_LEQUAL: glfunc = GL_LEQUAL; break; case ZF_GREATER: glfunc = GL_GREATER; break; case ZF_NOTEQUAL: glfunc = GL_NOTEQUAL; break; case ZF_GEQUAL: glfunc = GL_GEQUAL; break; case ZF_ALWAYS: glfunc = GL_ALWAYS; break; default: Yprintf(MyName, "invalid function %d.\n", func); return; } glDepthFunc(glfunc); } /* Display lists */ Int32 genobj(void) { const char * MyName = "genobj"; I(MyName, ""); if(!Ygl.UseOGL) NIR(MyName, -1); return glGenLists(1); } Int32 isobj(Int32 object) { const char * MyName = "isobj"; I(MyName, "%d", object); if(!Ygl.UseOGL) NIR(MyName, -1); return glIsList(object); } void makeobj(Int32 object) { const char * MyName = "makeobj"; I(MyName, "%d", object); if(!Ygl.UseOGL) NI(MyName); glNewList(object, GL_COMPILE); } Int32 getopenobj(void) { const char * MyName = "getopenobj"; GLint object; I(MyName, ""); if(!Ygl.UseOGL) NIR(MyName, -1); glGetIntegerv(GL_LIST_INDEX, &object); return object; } void closeobj(void) { const char * MyName = "closeobj"; I(MyName, ""); if(!Ygl.UseOGL) NI(MyName); glEndList(); } void callobj(Int32 object) { const char * MyName = "callobj"; I(MyName, "%d", object); if(!Ygl.UseOGL) NI(MyName); glCallList(object); } void delobj(Int32 object) { const char * MyName = "delobj"; I(MyName, "%d", object); if(!Ygl.UseOGL) NI(MyName); glDeleteLists(object, 1); } /* Lighting */ /* * Material */ static int MaterialNum = 0; static struct Material { Uint index; /* lmdef index */ GLuint list; /* 1st of 2 OpenGL List IDs for MATERIAL */ Float32 emission[4]; /* and BACKMATERIAL */ Float32 ambient[4]; Float32 diffuse[4]; Float32 specular[4]; Float32 shininess[1]; Float32 alpha[1]; Float32 colorindexes[4]; } *Materials = NULL, Materialdefault = { 0, 0, {0.0F, 0.0F, 0.0F, 1.0F}, /* emission */ {0.2F, 0.2F, 0.2F, 1.0F}, /* ambient */ {0.8F, 0.8F, 0.8F, 1.0F}, /* diffuse */ {0.0F, 0.0F, 0.0F, 1.0F}, /* specular */ {0.0F}, /* shininess */ {1.0F}, /* alpha */ {0.0F, 127.5F, 255.0F}}; /* colorindexes */ static void defmaterial(const char *caller, Int16 index, Int16 numpoints, Float32 prop[]) { int i; int newmaterial = False; struct Material *material; if(Materials == NULL) { /* initialize */ i = MaterialNum++; Materials = (struct Material*)malloc(sizeof(struct Material)); newmaterial = True; } else { for(i = MaterialNum - 1; i >= 0 && Materials[i].index != index; i--); if(i < 0) { /* not found, allocate new */ i = MaterialNum++; Materials = (struct Material*) realloc(Materials, MaterialNum * sizeof(struct Material)); newmaterial = True; } } if(Materials == NULL) { Yprintf(caller, "can't allocate memory.\n"); exit(-1); } material = &Materials[i]; if(newmaterial) { /* initialize with defaults */ memcpy(material, &Materialdefault, sizeof(struct Material)); material->index = index; material->list = glGenLists(2); } else { glDeleteLists(material->list, 2); } for(i = 0; i < numpoints && prop[i];) switch((int)(prop[i++])) { int j; case EMISSION: for(j = 0; j < 3; j++) material->emission[j] = prop[i++]; break; case AMBIENT: for(j = 0; j < 3; j++) material->ambient[j] = prop[i++]; break; case DIFFUSE: for(j = 0; j < 3; j++) material->diffuse[j] = prop[i++]; break; case SPECULAR: for(j = 0; j < 3; j++) material->specular[j] = prop[i++]; break; case SHININESS: material->shininess[0] = prop[i++]; break; case ALPHA: material->alpha[0] = prop[i++]; break; case COLORINDEXES: for(j = 0; j < 3; j++) material->colorindexes[j] = prop[i++]; break; default: Yprintf(caller, "invalid MATERIAL property %g.\n", prop[i-1]); return; } /* Set alpha components */ material->emission[3] = material->alpha[0]; material->ambient[3] = material->alpha[0]; material->diffuse[3] = material->alpha[0]; material->specular[3] = material->alpha[0]; /* Put the complete definition into a display list */ glNewList(material->list, GL_COMPILE); glMaterialfv(GL_FRONT, GL_EMISSION, material->emission); glMaterialfv(GL_FRONT, GL_AMBIENT, material->ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, material->diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, material->specular); glMaterialfv(GL_FRONT, GL_SHININESS, material->shininess); glMaterialfv(GL_FRONT, GL_COLOR_INDEXES, material->colorindexes); glEndList(); /* and again for BACKMATERIAL */ glNewList(material->list + 1, GL_COMPILE); glMaterialfv(GL_BACK, GL_EMISSION, material->emission); glMaterialfv(GL_BACK, GL_AMBIENT, material->ambient); glMaterialfv(GL_BACK, GL_DIFFUSE, material->diffuse); glMaterialfv(GL_BACK, GL_SPECULAR, material->specular); glMaterialfv(GL_BACK, GL_SHININESS, material->shininess); glMaterialfv(GL_BACK, GL_COLOR_INDEXES, material->colorindexes); glEndList(); } /* * LightModel */ static int LightModelNum = 0; static struct LightModel { Uint index; /* lmdef index */ GLuint list; /* OpenGL List ID */ Float32 ambient[4]; Float32 localviewer[1]; Float32 twoside[1]; } *LightModels = NULL, LightModeldefault = { 0, 0, {0.2F, 0.2F, 0.2F, 1.0F}, /* ambient */ {0.0F}, /* localviewer */ {0.0F} /* twoside */ }; static struct Attenuation_ { Float32 constant; Float32 linear; Float32 quadratic; } Attenuation = { 1.0F, 0.0F, 0.0F }; static void deflightmodel(const char *caller, Int16 index, Int16 numpoints, Float32 prop[]) { int i; int newlightmodel = False; struct LightModel *lightmodel; if(LightModels == NULL) { /* initialize */ i = LightModelNum++; LightModels = (struct LightModel*)malloc(sizeof(struct LightModel)); newlightmodel = True; } else { for(i = LightModelNum - 1; i >= 0 && LightModels[i].index != index; i--); if(i < 0) { /* not found, allocate new */ i = LightModelNum++; LightModels = (struct LightModel*) realloc(LightModels, LightModelNum * sizeof(struct LightModel)); newlightmodel = True; } } if(LightModels == NULL) { Yprintf(caller, "can't allocate memory.\n"); exit(-1); } lightmodel = &LightModels[i]; if(newlightmodel) { /* initialize with defaults */ memcpy(lightmodel, &LightModeldefault, sizeof(struct LightModel)); lightmodel->index = index; lightmodel->list = glGenLists(1); } else { glDeleteLists(lightmodel->list, 1); } for(i = 0; i < numpoints && prop[i];) switch((int)(prop[i++])) { int j; case AMBIENT: for(j = 0; j < 3; j++) lightmodel->ambient[j] = prop[i++]; break; case LOCALVIEWER: lightmodel->localviewer[0] = prop[i++]; break; case ATTENUATION: /* used in lmbind */ Attenuation.constant = prop[i++]; Attenuation.linear = prop[i++]; /*Yprintf(caller, "LMODEL ATTENUATION experimental.\n");*/ break; case ATTENUATION2: /* used in lmbind */ Attenuation.quadratic = prop[i++]; /*Yprintf(caller, "LMODEL ATTENUATION2 experimental.\n");*/ break; case TWOSIDE: lightmodel->twoside[0] = prop[i++]; break; default: Yprintf(caller, "invalid LMODEL property %g.\n", prop[i-1]); return; } /* Put the complete definition into a display list */ glNewList(lightmodel->list, GL_COMPILE); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lightmodel->ambient); glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lightmodel->localviewer); glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lightmodel->twoside); glEndList(); } /* * Light */ static int LightNum = 0; static struct Light { Uint index; Float32 ambient[4]; Float32 lcolor[4]; Float32 position[4]; Float32 spotdir[3]; Float32 spotexp[1]; Float32 spotcut[1]; } *Lights = NULL, Lightdefault = { 0, {0.0F, 0.0F, 0.0F, 1.0F}, /* ambient */ {1.0F, 1.0F, 1.0F, 1.0F}, /* lcolor */ {0.0F, 0.0F, 1.0F, 0.0F}, /* position */ {0.0F, 0.0F,-1.0F}, /* spotdir */ {0.0F}, /* spotexp */ {180.0F}}; /* spotcut */ /* Which definition is already bound to light i? */ static Int32 boundLightindex[8]; static void deflight(const char *caller, Int16 index, Int16 numpoints, Float32 prop[]) { int i; int newlight = False; struct Light *light; /* Reset entry in boundLightindex so lmbind reload definition */ for(i = 0; i < 8; i++) if(boundLightindex[i] == index) boundLightindex[i] = 0; if(Lights == NULL) { /* initialize */ i = LightNum++; Lights = (struct Light*)malloc(sizeof(struct Light)); newlight = True; } else { for(i = LightNum - 1; i >= 0 && Lights[i].index != index; i--); if(i < 0) { /* not found, allocate new */ i = LightNum++; Lights = (struct Light*) realloc(Lights, LightNum * sizeof(struct Light)); newlight = True; } } if(Lights == NULL) { Yprintf(caller, "can't allocate memory.\n"); exit(-1); } light = &Lights[i]; if(newlight) { /* initialize with defaults */ memcpy(light, &Lightdefault, sizeof(struct Light)); light->index = index; } for(i = 0; i < numpoints && prop[i];) switch((int)(prop[i++])) { int j; case AMBIENT: for(j = 0; j < 3; j++) light->ambient[j] = prop[i++]; break; case LCOLOR: for(j = 0; j < 3; j++) light->lcolor[j] = prop[i++]; break; case POSITION: for(j = 0; j < 4; j++) light->position[j] = prop[i++]; break; case SPOTDIRECTION: for(j = 0; j < 3; j++) light->spotdir[j] = prop[i++]; break; case SPOTLIGHT: light->spotexp[0] = prop[i++]; light->spotcut[0] = prop[i++]; break; default: Yprintf(caller, "invalid LIGHT property %g.\n", prop[i-1]); return; } } void lmdef(Int16 deftype, Int16 index, Int16 numpoints, Float32 prop[]) { const char * MyName = "lmdef"; I(MyName, "%d,%d,%d,*", deftype, index, numpoints); if(!Ygl.UseOGL) NI(MyName); #ifdef DEBUG { int i; Yprintf(MyName, "deftype=%d, index=%d, numpoints=%d: ", deftype, index, numpoints); for(i = 0; i < numpoints; i++) fprintf(stderr, "%g ", prop[i]); fprintf(stderr, "\n"); } #endif if(index == 0) { Yprintf(MyName, "can't redefine index 0.\n"); return; } switch(deftype) { case DEFMATERIAL: defmaterial(MyName, index, numpoints, prop); break; case DEFLIGHT: deflight(MyName, index, numpoints, prop); break; case DEFLMODEL: deflightmodel(MyName, index, numpoints, prop); break; default: Yprintf(MyName, "invalid type %d.\n", deftype); return; } } void lmbind(Int32 target, Int32 index) { const char * MyName = "lmbind"; GLenum gllight; int i, boundi; I(MyName, "%d,%d", target, index); if(!Ygl.UseOGL) NI(MyName); if(target == MATERIAL || target == LMODEL) { if(index == 0) { glDisable(GL_LIGHTING); glDisable(GL_NORMALIZE); return; } else { glEnable(GL_LIGHTING); glEnable(GL_NORMALIZE); /* GL sets this */ } } switch(target) { case MATERIAL: for(i = MaterialNum - 1; i >= 0 && Materials[i].index != index; i--); if(i < 0) { Yprintf(MyName, "MATERIAL %d not defined.\n", index); return; } glCallList(Materials[i].list); return; case BACKMATERIAL: for(i = MaterialNum - 1; i >= 0 && Materials[i].index != index; i--); if(i < 0) { Yprintf(MyName, "MATERIAL %d not defined.\n", index); return; } glCallList(Materials[i].list + 1); return; case LMODEL: for(i = LightModelNum - 1; i >= 0 && LightModels[i].index != index; i--); if(i < 0) { Yprintf(MyName, "MATERIAL %d not defined.\n", index); return; } glCallList(LightModels[i].list); return; case LIGHT0: boundi = 0; gllight = GL_LIGHT0; break; case LIGHT1: boundi = 1; gllight = GL_LIGHT1; break; case LIGHT2: boundi = 2; gllight = GL_LIGHT2; break; case LIGHT3: boundi = 3; gllight = GL_LIGHT3; break; case LIGHT4: boundi = 4; gllight = GL_LIGHT4; break; case LIGHT5: boundi = 5; gllight = GL_LIGHT5; break; case LIGHT6: boundi = 6; gllight = GL_LIGHT6; break; case LIGHT7: boundi = 7; gllight = GL_LIGHT7; break; default: Yprintf(MyName, "invalid target %d.\n", target); return; } if(index == 0) { glDisable(gllight); } else { glEnable(gllight); if(index != boundLightindex[boundi]) { /* load definition for light if changed or not already loaded */ boundLightindex[boundi] = index; for(i = LightNum - 1; i >= 0 && Lights[i].index != index; i--); if(i < 0) { Yprintf(MyName, "LIGHT %d not defined.\n", index); return; } glLightfv(gllight, GL_AMBIENT, Lights[i].ambient); glLightfv(gllight, GL_DIFFUSE, Lights[i].lcolor); glLightfv(gllight, GL_SPECULAR, Lights[i].lcolor); glLightfv(gllight, GL_POSITION, Lights[i].position); glLightfv(gllight, GL_SPOT_DIRECTION, Lights[i].spotdir); glLightfv(gllight, GL_SPOT_EXPONENT, Lights[i].spotexp); glLightfv(gllight, GL_SPOT_CUTOFF, Lights[i].spotcut); glLightf(gllight, GL_CONSTANT_ATTENUATION, Attenuation.constant); glLightf(gllight, GL_LINEAR_ATTENUATION, Attenuation.linear); glLightf(gllight, GL_QUADRATIC_ATTENUATION, Attenuation.quadratic); } } } void lmcolor(Int32 mode) { const char * MyName = "lmcolor"; GLenum glmode; I(MyName, "%d", mode); if(!Ygl.UseOGL) NI(MyName); switch(mode) { case LMC_COLOR: glDisable(GL_COLOR_MATERIAL); return; case LMC_NULL: Yprintf(MyName, "unimplemented mode %d.\n", mode); return; case LMC_EMISSION: glmode = GL_EMISSION; break; case LMC_AMBIENT: glmode = GL_AMBIENT; break; case LMC_DIFFUSE: glmode = GL_DIFFUSE; break; case LMC_SPECULAR: glmode = GL_SPECULAR; break; case LMC_AD: glmode = GL_AMBIENT_AND_DIFFUSE; break; default: Yprintf(MyName, "invalid mode %d.\n", mode); return; } glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK, glmode); } void shademodel(Int32 mode) { const char * MyName = "shademodel"; GLenum glmode; I(MyName, "%d", mode); if(!Ygl.UseOGL) NI(MyName); switch(mode) { case FLAT: glmode = GL_FLAT; break; case GOURAUD: glmode = GL_SMOOTH; break; default: Yprintf(MyName, "invalid mode %d.\n", mode); return; } glShadeModel(glmode); } static int Face[] = {False, False}; static void front_back(const char *caller, GLenum glcull, Int32 mode) { I(caller, "%d", mode); if(!Ygl.UseOGL) NI(caller); switch(mode) { case True: Face[0] = True; glCullFace(glcull); break; case False: Face[0] = False; break; default: Yprintf(caller, "invalid mode %d.\n", mode); return; } if(Face[0] || Face[1]) { glEnable(GL_CULL_FACE); } else { glDisable(GL_CULL_FACE); } } void frontface(Int32 mode) { const char * MyName = "frontface"; front_back(MyName, GL_FRONT, mode); } void backface(Int32 mode) { const char * MyName = "backface"; front_back(MyName, GL_BACK, mode); } void RGBwritemask(Int16 red, Int16 green, Int16 blue) { const char * MyName = "RGBwritemask"; I(MyName, "%d,%d,%d", red, green, blue); if(!Ygl.UseOGL) NI(MyName); glColorMask(red != 0, green != 0, blue != 0, GL_FALSE); } /* for Pete Riley */ void drawmode(Int32 mode) { const char * MyName = "drawmode"; I(MyName, "%d", mode); if(!Ygl.UseOGL) NI(MyName); NI(MyName); } void iconsize(Int32 sx, Int32 sy) { const char * MyName = "iconsize"; I(MyName, "%d,%d", sx, sy); if(!Ygl.UseOGL) NI(MyName); NI(MyName); } void overlay(Int32 arg) { const char * MyName = "overlay"; I(MyName, "%d", arg); if(!Ygl.UseOGL) NI(MyName); NI(MyName); } void pushattributes(void) { const char * MyName = "pushattributes"; I(MyName, ""); if(!Ygl.UseOGL) NI(MyName); glPushAttrib(GL_ALL_ATTRIB_BITS); } void popattributes(void) { const char * MyName = "popattributes"; I(MyName, ""); if(!Ygl.UseOGL) NI(MyName); glPopAttrib(); } void fullscrn(void) { const char * MyName = "fullscrn"; I(MyName, ""); if(!Ygl.UseOGL) NI(MyName); NI(MyName); } void endfullscrn(void) { const char * MyName = "endfullscrn"; I(MyName, ""); if(!Ygl.UseOGL) NI(MyName); NI(MyName); } void scrmask(Screencoord l, Screencoord r, Screencoord b, Screencoord t) { const char * MyName = "scrmask"; I(MyName, "%d,%d,%d,%d", l, r, b, t); if(!Ygl.UseOGL) NI(MyName); glScissor(l, b, r - l, t - b); glEnable(GL_SCISSOR_TEST); } #endif /* OGL */ ygl-4.2e/Makefile0000644000175000017500000000000010200401724016750 1ygl-4.2e/Makefile.stdustar prabhuprabhuygl-4.2e/.desc0000644000175000017500000000017610374405244012571 0ustar prabhuprabhu Ygl: Run GL programs with standard X11 and/or OpenGL routines. (C) Fred Hucht 1993-2006 EMail: fredthp.Uni-Duisburg.de ygl-4.2e/Imakefile0000444000175000017500000001264510620056544013464 0ustar prabhuprabhuXCOMM XCOMM Ygl: Run GL programs with standard X11 routines. XCOMM (C) Fred Hucht 1993-2007 XCOMM EMail: fred(AT)thp.Uni-Duisburg.de XCOMM XCOMM $Id: Imakefile,v 4.5 2007-05-08 11:00:41+02 fred Exp $ XCOMM Set UseX11 to 1 if you want X11 bindings (faster, but only 2d) #define UseX11 1 XCOMM Set UseOpenGL to 1 if you want OpenGL bindings XCOMM (might be slower than X11, but also 3d) #define UseOpenGL 1 XCOMM Set Has_GLX_SGI_video_sync to 0 if you get link errors like XCOMM "ld: 0711-317 ERROR: Undefined symbol: .glXGetVideoSyncSGI" XCOMM (e.g. under AIX 4.3) #define Has_GLX_SGI_video_sync 1 XCOMM Set DoubleBuffer to 1 if your system has the include file XCOMM and the library libXext.a XCOMM This should be true for X11R6.1. Only nessesary with UseX11 == 1 #define DoubleBuffer 1 XCOMM Set MultiBuffer to 1 if your system has the include file XCOMM and the library libXext.a XCOMM This should be true for X11R5. Only nessesary with UseX11 == 1 #define MultiBuffer 1 XCOMM Set FortranBindings to 1 to include FORTRAN bindings into XCOMM the Ygl library. #define FortranBindings 1 XCOMM Set UseGlobalColormap to 1 to use experimental colormap handling. XCOMM You must have the include file and libXmu.a #define UseGlobalColormaps 0 XCOMM Set YglPrefix to 1 to prepend "ygl_" to all function names #define YglPrefix 0 XCOMM ******* The following stuff is obsolete! *************** XCOMM Set UseMesa to 1 if you want OpenGL bindings using Mesa. XCOMM Don\'t define both UseOpenGL and UseMesa! XCOMM If you installed Mesa with the OpenGL names (libGL.a etc.) XCOMM set UseOpenGL to 1. XCOMM You may have to change the path to the Mesa lib below... #define UseMesa 0 /* NOT SUPPORTED YET... */ #if UseMesa OGL = -I/usr/local/Mesa/include -DOGL OGLIB = -L/usr/local/Mesa/lib -lMesaGL -lMesaGLU #endif XCOMM ***************** End of configuable part ******************** SOYGLREV = 4.2 #if !defined(DoSharedLib) && (defined(AIXArchitecture) || defined(RsArchitecture)) # define DoSharedLib 1 # undef DoNormalLib # define DoNormalLib 0 #endif #if defined(HPArchitecture) && !HasGcc2 #undef CCOPTIONS CCOPTIONS = -Ae +ESlit /* CCOPTIONS = -Aa -D_HPUX_SOURCE */ #endif #ifdef MacIIArchitecture XCOMM A/UX must have prefix due to naming conflict #define YglForcePrefix 1 CCOPTIONS = -D_AUX_SOURCE #endif #if UseOpenGL && UseMesa #error UseOpenGL and UseMesa are exclusive!!! #endif #if UseOpenGL OGL = -DOGL OGLIB = -lGL -lGLU #endif #if UseX11 X11 = -DX11 #if Has_GLX_SGI_video_sync GSvs = -DGSvs #endif #if DoubleBuffer DOUBLEBUF = -DDOUBLEBUF #endif #if MultiBuffer MULTIBUF = -DMULTIBUF #endif #if DoubleBuffer || MultiBuffer DMBUFLIB = -lXext #endif #if UseGlobalColormaps HASXMU = -DHASXMU THEXMULIB = -lXmu #endif #endif /* UseX11 */ #if YglPrefix YGL_PREFIX = -DYGL_PREFIX YGL_PREFIX_HDR = X11/Yglprefix.h TARGET = Yglp #else TARGET = Ygl #endif #if YglForcePrefix /* A/UX */ YGL_PREFIX = -DYGL_PREFIX YGL_PREFIX_HDR = X11/Yglprefix.h #endif DEFINES = $(OGL) $(X11) $(GSvs) $(DOUBLEBUF) $(MULTIBUF) $(HASXMU) $(YGL_PREFIX) #if FortranBindings FSRC = fortran.c FOBJ = fortran.o FHDR = X11/Yfgl.h #endif SRCS = ygl.c draw.c misc.c font.c queue.c color.c menu.c gl2ppm.c 3d.c $(FSRC) OBJS = ygl.o draw.o misc.o font.o queue.o color.o menu.o gl2ppm.o 3d.o $(FOBJ) INCLUDES = -I. XLIBS = $(OGLIB) $(DMBUFLIB) $(THEXMULIB) -lX11 HEADERS = X11/Ygl.h X11/Ygltypes.h $(FHDR) $(YGL_PREFIX_HDR) INCDIR = $(INCROOT)/X11 REQUIREDLIBS = -L$(USRLIBDIR) $(XLIBS) #if defined(AIXArchitecture) || defined(RsArchitecture) CC = xlc -qinfo #endif #if ProjectX > 5 XCOMM This stuff and more contributed by Larry Schwimmer # undef BuildIncludesTop # define BuildIncludesTop(x) # define LibName $(TARGET) # define SoRev SOYGLREV # ifndef DoSharedLib # define DoSharedLib HasSharedLibraries # endif # ifndef DoNormalLib # define DoNormalLib (!DoSharedLib || ForceNormalLib) # endif # include #else /* ProjectX > 5 */ # if DoSharedLib SharedLibraryTarget ($(TARGET),ShlibRev,$(OBJS),.,.) InstallSharedLibrary($(TARGET),ShlibRev,$(USRLIBDIR)) # endif /* DoSharedLib */ # if DoNormalLib NormalLibraryTarget($(TARGET),$(OBJS)) InstallLibrary($(TARGET),$(USRLIBDIR)) # endif /* DoNormalLib */ INSTALLFLAGS = $(INSTINCFLAGS) InstallMultiple($(HEADERS),$(INCDIR)) #endif /* ProjectX > 5 */ DependTarget() $(YGL_PREFIX_HDR): makeYglprefix X11/Ygl.h ./makeYglprefix > $@ X11/Ygltypes.h: makeYgltypes ./makeYgltypes > $@ makeYgltypes: makeYgltypes.c $(CC) $(CFLAGS) -o makeYgltypes makeYgltypes.c usleep.i: header.h $(RM) usleep_tst.c $(LN) header.h usleep_tst.c $(CC) $(CFLAGS) -E usleep_tst.c > usleep.i $(RM) usleep_tst.c usleep.h: usleep.i sed -nf makeusleep.sed usleep.i > usleep.h misc.o: usleep.h #if UseOpenGL || UseMesa XCOMM For directory examples THREE_D_TARGETS = lmbind #endif #define IHaveSubdirs #define PassCDebugFlags 'THREE_D_TARGETS=$(THREE_D_TARGETS)' SUBDIRS = examples MakeSubdirs($(SUBDIRS)) DependSubdirs($(SUBDIRS)) includes:: X11/Ygltypes.h $(YGL_PREFIX_HDR) usleep.h $(OBJS): X11/Ygltypes.h $(YGL_PREFIX_HDR) etags:: etags $(SRCS) header.h config.h X11/Ygl.h clean:: $(RM) a.out makeYgltypes usleep.h usleep.i cd X11 ; $(RM) Yglprefix.h Ygltypes.h *~ ; cd .. #if ProjectX < 6 lint:: $(LINT) -MA $(ALLDEFINES) $(LINTOPTS) -Nn10000 -Nd10000 $(SRCS) #endif ygl-4.2e/fortran.c0000444000175000017500000005177710620056715013503 0ustar prabhuprabhu/* * Ygl: Run GL programs with standard X11 and/or OpenGL routines. * (C) Fred Hucht 1993-2006 * EMail: fredthp.Uni-Duisburg.de */ static const char vcid[] = "$Id: fortran.c,v 4.2 2007-05-08 13:23:57+02 fred Exp $"; #include "header.h" /* for COVERSLEEP & string.h */ #ifndef YGL_PRE # define YGL_PRE(x) x #endif /* Fortran types */ #define REAL Float32 #define REAL8 Float64 #define INT2 Int16 #define INT4 Int32 #define LOGICAL Int32 #define CHAR char /* Append '\0' to FORTRAN string. * Thx to Frank Scott for reporting bug and fix */ #define L_TBUF 255 static char Tbuf[L_TBUF+1]; static char *apnd_0(CHAR * str, INT4 * len) { int l = *len > L_TBUF ? L_TBUF : *len; strncpy(Tbuf, str, l); Tbuf[l] = '\0'; return Tbuf; } void setval_(INT4*x1, INT4*x2, INT4*x3, INT4*x4) {} void curson_(void) {} void cursof_(void) {} void chunks_(void) {} void greset_(void) {} /********************* draw.c */ void YGL_PRE(clear_) (void) { clear();} /* Points */ void YGL_PRE(pnt2_) (REAL*x1, REAL*x2) { pnt2 (*x1, *x2);} void YGL_PRE(pnt2i_) (INT4*x1, INT4*x2) { pnt2i(*x1, *x2);} void YGL_PRE(pnt2s_) (INT2*x1, INT2*x2) { pnt2s(*x1, *x2);} /* Lines */ void YGL_PRE(move2_) (REAL*x1, REAL*x2) { move2 (*x1, *x2);} void YGL_PRE(move2i_)(INT4*x1, INT4*x2) { move2i(*x1, *x2);} void YGL_PRE(move2s_)(INT2*x1, INT2*x2) { move2s(*x1, *x2);} void YGL_PRE(rmv2_) (REAL*x1, REAL*x2) { rmv2 (*x1, *x2);} void YGL_PRE(rmv2i_) (INT4*x1, INT4*x2) { rmv2i(*x1, *x2);} void YGL_PRE(rmv2s_) (INT2*x1, INT2*x2) { rmv2s(*x1, *x2);} void YGL_PRE(draw2_) (REAL*x1, REAL*x2) { draw2 (*x1, *x2);} void YGL_PRE(draw2i_)(INT4*x1, INT4*x2) { draw2i(*x1, *x2);} void YGL_PRE(draw2s_)(INT2*x1, INT2*x2) { draw2s(*x1, *x2);} void YGL_PRE(rdr2_) (REAL*x1, REAL*x2) { rdr2 (*x1, *x2);} void YGL_PRE(rdr2i_) (INT4*x1, INT4*x2) { rdr2i(*x1, *x2);} void YGL_PRE(rdr2s_) (INT2*x1, INT2*x2) { rdr2s(*x1, *x2);} /* Arcs & Circles */ void YGL_PRE(arc_) (REAL*x1, REAL*x2, REAL*x3, INT4*x4, INT4*x5) { arc (*x1, *x2, *x3, *x4, *x5);} void YGL_PRE(arci_) (INT4*x1, INT4*x2, INT4*x3, INT4*x4, INT4*x5) { arci (*x1, *x2, *x3, *x4, *x5);} void YGL_PRE(arcs_) (INT2*x1, INT2*x2, INT2*x3, INT4*x4, INT4*x5) { arcs (*x1, *x2, *x3, *x4, *x5);} void YGL_PRE(arcf_) (REAL*x1, REAL*x2, REAL*x3, INT4*x4, INT4*x5) { arcf (*x1, *x2, *x3, *x4, *x5);} void YGL_PRE(arcfi_) (INT4*x1, INT4*x2, INT4*x3, INT4*x4, INT4*x5) { arcfi(*x1, *x2, *x3, *x4, *x5);} void YGL_PRE(arcfs_) (INT2*x1, INT2*x2, INT2*x3, INT4*x4, INT4*x5) { arcfs(*x1, *x2, *x3, *x4, *x5);} void YGL_PRE(circ_) (REAL*x1, REAL*x2, REAL*x3) { circ (*x1, *x2, *x3);} void YGL_PRE(circi_) (INT4*x1, INT4*x2, INT4*x3) { circi (*x1, *x2, *x3);} void YGL_PRE(circs_) (INT2*x1, INT2*x2, INT2*x3) { circs (*x1, *x2, *x3);} void YGL_PRE(circf_) (REAL*x1, REAL*x2, REAL*x3) { circf (*x1, *x2, *x3);} void YGL_PRE(circfi_)(INT4*x1, INT4*x2, INT4*x3) { circfi(*x1, *x2, *x3);} void YGL_PRE(circfs_)(INT2*x1, INT2*x2, INT2*x3) { circfs(*x1, *x2, *x3);} /* Rects & Boxes */ void YGL_PRE(rect_) (REAL*x1, REAL*x2, REAL*x3, REAL*x4) { rect (*x1, *x2, *x3, *x4);} void YGL_PRE(recti_) (INT4*x1, INT4*x2, INT4*x3, INT4*x4) { recti (*x1, *x2, *x3, *x4);} void YGL_PRE(rects_) (INT2*x1, INT2*x2, INT2*x3, INT2*x4) { rects (*x1, *x2, *x3, *x4);} void YGL_PRE(rectf_) (REAL*x1, REAL*x2, REAL*x3, REAL*x4) { rectf (*x1, *x2, *x3, *x4);} void YGL_PRE(rectfi_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4) { rectfi(*x1, *x2, *x3, *x4);} void YGL_PRE(rectfs_)(INT2*x1, INT2*x2, INT2*x3, INT2*x4) { rectfs(*x1, *x2, *x3, *x4);} void YGL_PRE(sbox_) (REAL*x1, REAL*x2, REAL*x3, REAL*x4) { sbox (*x1, *x2, *x3, *x4);} void YGL_PRE(sboxi_) (INT4*x1, INT4*x2, INT4*x3, INT4*x4) { sboxi (*x1, *x2, *x3, *x4);} void YGL_PRE(sboxs_) (INT2*x1, INT2*x2, INT2*x3, INT2*x4) { sboxs (*x1, *x2, *x3, *x4);} void YGL_PRE(sboxf_) (REAL*x1, REAL*x2, REAL*x3, REAL*x4) { sboxf (*x1, *x2, *x3, *x4);} void YGL_PRE(sboxfi_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4) { sboxfi(*x1, *x2, *x3, *x4);} void YGL_PRE(sboxfs_)(INT2*x1, INT2*x2, INT2*x3, INT2*x4) { sboxfs(*x1, *x2, *x3, *x4);} /* Filled Polygons */ void YGL_PRE(concav_)(LOGICAL*x1) { concave(*x1);} void YGL_PRE(pmv2_) (REAL*x1, REAL*x2) { pmv2 (*x1, *x2);} void YGL_PRE(pmv2i_) (INT4*x1, INT4*x2) { pmv2i(*x1, *x2);} void YGL_PRE(pmv2s_) (INT2*x1, INT2*x2) { pmv2s(*x1, *x2);} void YGL_PRE(rpmv2_) (REAL*x1, REAL*x2) { rpmv2 (*x1, *x2);} void YGL_PRE(rpmv2i_)(INT4*x1, INT4*x2) { rpmv2i(*x1, *x2);} void YGL_PRE(rpmv2s_)(INT2*x1, INT2*x2) { rpmv2s(*x1, *x2);} void YGL_PRE(pdr2_) (REAL*x1, REAL*x2) { pdr2 (*x1, *x2);} void YGL_PRE(pdr2i_) (INT4*x1, INT4*x2) { pdr2i(*x1, *x2);} void YGL_PRE(pdr2s_) (INT2*x1, INT2*x2) { pdr2s(*x1, *x2);} void YGL_PRE(rpdr2_) (REAL*x1, REAL*x2) { rpdr2 (*x1, *x2);} void YGL_PRE(rpdr2i_)(INT4*x1, INT4*x2) { rpdr2i(*x1, *x2);} void YGL_PRE(rpdr2s_)(INT2*x1, INT2*x2) { rpdr2s(*x1, *x2);} void YGL_PRE(pclos_) (void) { pclos();} void YGL_PRE(poly2_) (INT4*x1, REAL x2[][2]) { polf2 (*x1, x2); } void YGL_PRE(poly2i_)(INT4*x1, INT4 x2[][2]) { polf2i(*x1, x2); } void YGL_PRE(poly2s_)(INT4*x1, INT2 x2[][2]) { polf2s(*x1, x2); } void YGL_PRE(polf2_) (INT4*x1, REAL x2[][2]) { polf2 (*x1, x2); } void YGL_PRE(polf2i_)(INT4*x1, INT4 x2[][2]) { polf2i(*x1, x2); } void YGL_PRE(polf2s_)(INT4*x1, INT2 x2[][2]) { polf2s(*x1, x2); } /* Vertex graphics */ void YGL_PRE(bgnpoi_)(void) { bgnpoint ();} void YGL_PRE(bgnlin_)(void) { bgnline ();} void YGL_PRE(bgnclo_)(void) { bgnclosedline();} void YGL_PRE(bgnpol_)(void) { bgnpolygon ();} void YGL_PRE(bgntme_)(void) { bgntmesh ();} void YGL_PRE(endpoi_)(void) { endpoint ();} void YGL_PRE(endlin_)(void) { endline ();} void YGL_PRE(endclo_)(void) { endclosedline();} void YGL_PRE(endpol_)(void) { endpolygon ();} void YGL_PRE(endtme_)(void) { endtmesh ();} void YGL_PRE(v2s_) (INT2 x1[2]) { v2s(x1);} void YGL_PRE(v2i_) (INT4 x1[2]) { v2i(x1);} void YGL_PRE(v2f_) (REAL x1[2]) { v2f(x1);} void YGL_PRE(v2d_) (REAL8 x1[2]) { v2d(x1);} /* Text */ void YGL_PRE(cmov2_) (REAL*x1, REAL*x2) { cmov2 (*x1, *x2);} void YGL_PRE(cmov2i_)(INT4*x1, INT4*x2) { cmov2i(*x1, *x2);} void YGL_PRE(cmov2s_)(INT2*x1, INT2*x2) { cmov2s(*x1, *x2);} void YGL_PRE(getcpo_)(INT2*x1, INT2*x2) { getcpos(x1, x2);} /* Extensions: Routines not in gl by MiSt (michael@hal6000.thp.Uni-Duisburg.DE) */ #ifdef X11 void YGL_PRE(arcx_) (REAL*x1, REAL*x2, REAL*x3, REAL*x4, INT4*x5, INT4*x6) { arcx (*x1,*x2,*x3,*x4,*x5,*x6); } void YGL_PRE(arcxi_) (INT4*x1, INT4*x2, INT4*x3, INT4*x4, INT4*x5, INT4*x6) { arcxi (*x1,*x2,*x3,*x4,*x5,*x6); } void YGL_PRE(arcxs_) (INT2*x1, INT2*x2, INT2*x3, INT2*x4, INT4*x5, INT4*x6) { arcxs (*x1,*x2,*x3,*x4,*x5,*x6); } void YGL_PRE(arcxf_) (REAL*x1, REAL*x2, REAL*x3, REAL*x4, INT4*x5, INT4*x6) { arcxf (*x1,*x2,*x3,*x4,*x5,*x6); } void YGL_PRE(arcxfi_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4, INT4*x5, INT4*x6) { arcxfi(*x1,*x2,*x3,*x4,*x5,*x6); } void YGL_PRE(arcxfs_)(INT2*x1, INT2*x2, INT2*x3, INT2*x4, INT4*x5, INT4*x6) { arcxfs(*x1,*x2,*x3,*x4,*x5,*x6); } #endif /********************* queue.c */ void YGL_PRE(tie_) (INT4*x1, INT4*x2, INT4*x3) { tie(*x1, *x2, *x3); } void YGL_PRE(noise_) (INT4*x1, INT4*x2) { noise(*x1, *x2); } INT4 YGL_PRE(isqueu_)(INT4*x1) { return isqueued(*x1); } void YGL_PRE(qdevic_)(INT4*x1) { qdevice(*x1); } void YGL_PRE(unqdev_)(INT4*x1) { unqdevice(*x1); } void YGL_PRE(qreset_)(void) { qreset(); } INT4 YGL_PRE(qtest_) (void) { return qtest(); } INT4 YGL_PRE(qread_) (INT2*x1) { return qread(x1); } void YGL_PRE(qenter_)(INT4*x1, INT4*x2) { qenter(*x1, *x2); } #ifdef OGL void YGL_PRE(pick_) (INT2*x1, INT4*x2) { pick(x1, *x2); } INT4 YGL_PRE(endpic_)(INT2*x1) { return (INT4)endpick(x1); } void YGL_PRE(picksi_)(INT4*x1, INT4*x2) { picksize(*x1, *x2); } void YGL_PRE(initna_)(void) { initnames(); } void YGL_PRE(loadna_)(INT4*x1) { loadname(*x1); } void YGL_PRE(pushna_)(INT4*x1) { pushname(*x1); } void YGL_PRE(popnam_)(void) { popname(); } #endif /* OGL */ /********************* misc.c */ void YGL_PRE(single_)(void) { singlebuffer(); } void YGL_PRE(doublebuffer_)(void) { doublebuffer(); } /* > 6 */ void YGL_PRE(double_)(void) { doublebuffer(); } void YGL_PRE(swapbu_)(void) { swapbuffers(); } void YGL_PRE(frontb_)(LOGICAL*x1) { frontbuffer(*x1); } void YGL_PRE(backbu_)(LOGICAL*x1) { backbuffer (*x1); } void YGL_PRE(gflush_)(void) { gflush(); } void YGL_PRE(gsync_) (void) { gsync(); } INT4 YGL_PRE(getxdpy_)(void) { return (INT4)getXdpy(); } /* > 6 */ INT4 YGL_PRE(getxwid_)(void) { return (INT4)getXwid(); } /* > 6 */ #ifdef X11 INT4 YGL_PRE(getxdid_)(void) { return (INT4)getXdid(); } /* > 6 */ INT4 YGL_PRE(getxgc_) (void) { return (INT4)getXgc (); } #endif void YGL_PRE(wintit_)(CHAR*x1, INT4*len) { wintitle(apnd_0(x1,len));} void YGL_PRE(winset_)(INT4*x1) { winset(*x1);} INT4 YGL_PRE(winget_)(void) { return winget();} INT4 YGL_PRE(getpla_)(void) { return getplanes();} INT4 YGL_PRE(getval_)(INT4*x1) { return getvaluator(*x1);} INT4 YGL_PRE(getbut_)(INT4*x1) { return getbutton(*x1);} INT4 YGL_PRE(gversi_)(CHAR*x1, INT4*len) { INT4 r = gversion(x1);if(len) *len = strlen(x1);return r;} void YGL_PRE(ortho2_)(REAL*x1, REAL*x2, REAL*x3, REAL*x4) { ortho2(*x1, *x2, *x3, *x4);} void YGL_PRE(viewpo_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4) { viewport(*x1, *x2, *x3, *x4);} void YGL_PRE(getvie_)(INT2*x1, INT2*x2, INT2*x3, INT2*x4) { getviewport(x1, x2, x3, x4);} void YGL_PRE(reshap_)(void) { reshapeviewport();} void YGL_PRE(pushvi_)(void) { pushviewport();} void YGL_PRE(popvie_)(void) { popviewport();} void YGL_PRE(winpop_)(void) { winpop();} void YGL_PRE(winpus_)(void) { winpush();} INT4 YGL_PRE(windep_)(INT4*x1) { return windepth(*x1);} void YGL_PRE(linewi_)(INT4*x1) { linewidth(*x1);} INT4 YGL_PRE(getlwi_)(void) { return getlwidth();} void YGL_PRE(deflin_)(INT4*x1, INT4*x2) { deflinestyle(*x1, *x2);} void YGL_PRE(setlin_)(INT4*x1) { setlinestyle(*x1);} INT4 YGL_PRE(getlst_)(void) { return getlstyle();} void YGL_PRE(lsrepe_)(INT4*x1) { lsrepeat(*x1);} INT4 YGL_PRE(getlsr_)(void) { return getlsrepeat();} INT4 YGL_PRE(getdis_)(void) { return getdisplaymode();} void YGL_PRE(setbel_)(CHAR*x1) { setbell(*x1);} void YGL_PRE(ringbe_)(void) { ringbell();} INT4 YGL_PRE(getgde_)(INT4*x1) { return getgdesc(*x1);} void YGL_PRE(foregr_)(void) { } void YGL_PRE(logico_)(INT4*x1) { logicop(*x1);} void YGL_PRE(getmat_)(Matrix x1) { getmatrix(x1);} /********************* font.c */ void YGL_PRE(loadxf_)(INT4*x1, CHAR*x2, INT4*len) { loadXfont(*x1, apnd_0(x2,len)); } void YGL_PRE(font_) (INT4*x1) { font(*x1);} INT4 YGL_PRE(getfon_)(void) { return getfont();} void YGL_PRE(getfontencoding_)(CHAR*x1, INT4*len) { getfontencoding(x1);if(len) *len = strlen(x1);} /* > 6 */ INT4 YGL_PRE(gethei_)(void) { return getheight();} INT4 YGL_PRE(getdes_)(void) { return getdescender();} INT4 YGL_PRE(strwid_)(CHAR*x1, INT4*len) { return strwidth(apnd_0(x1,len));} void YGL_PRE(charst_)(CHAR*x1, INT4*len) { charstr(apnd_0(x1,len));} /********************* color.c */ void YGL_PRE(mapcol_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4) { mapcolor(*x1, *x2, *x3, *x4);} void YGL_PRE(rgbcol_)(INT4*x1, INT4*x2, INT4*x3) { RGBcolor(*x1, *x2, *x3);} void YGL_PRE(cpack_) (INT4*x1) { cpack(*x1);} void YGL_PRE(c3s_) (INT2 x1[3]) { c3s(x1);} void YGL_PRE(c3i_) (INT4 x1[3]) { c3i(x1);} void YGL_PRE(c3f_) (REAL x1[3]) { c3f(x1);} INT4 YGL_PRE(getcol_)(void) { return getcolor();} void YGL_PRE(getmco_)(INT4*x1, INT2*x2, INT2*x3, INT2*x4) { getmcolor (*x1, x2, x3, x4); } void YGL_PRE(getmcolors_)(INT4*x1, INT4*x2, INT2*x3, INT2*x4, INT2*x5) { getmcolors(*x1, *x2, x3, x4, x5); } void YGL_PRE(grgbco_)(INT2*x1, INT2*x2, INT2*x3) { gRGBcolor(x1, x2, x3);} void YGL_PRE(color_) (INT4*x1) { color(*x1);} void YGL_PRE(readso_)(INT4*x1) { readsource(*x1);} void YGL_PRE(rectzo_)(REAL*x1, REAL*x2) { rectzoom(*x1, *x2);} INT4 YGL_PRE(crectr_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4,Uint8*x5) { return crectread(*x1,*x2,*x3,*x4,x5); } INT4 YGL_PRE(rectre_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4, INT2*x5) { return rectread(*x1,*x2,*x3,*x4,x5); } INT4 YGL_PRE(lrectr_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4, INT4*x5) { return lrectread(*x1,*x2,*x3,*x4,x5); } void YGL_PRE(crectw_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4,Uint8*x5) { crectwrite(*x1,*x2,*x3,*x4,x5); } void YGL_PRE(rectwr_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4, INT2*x5) { rectwrite(*x1,*x2,*x3,*x4,x5); } void YGL_PRE(lrectw_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4, INT4*x5) { lrectwrite(*x1,*x2,*x3,*x4,x5); } void YGL_PRE(rectco_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4, INT4*x5, INT4*x6) { rectcopy(*x1,*x2,*x3,*x4,*x5,*x6); } INT4 YGL_PRE(readpi_)(INT4*x1, INT2 x2[]) { return readpixels(*x1, (Colorindex*)x2); } void YGL_PRE(writep_)(INT4*x1, INT2 x2[]) { writepixels(*x1, (Colorindex*)x2); } INT4 YGL_PRE(readrg_)(INT4*x1, CHAR*x2, CHAR*x3, CHAR*x4) { return readRGB(*x1,(RGBvalue*)x2,(RGBvalue*)x3,(RGBvalue*)x4); } void YGL_PRE(writer_)(INT4*x1, CHAR*x2, CHAR*x3, CHAR*x4) { writeRGB(*x1,(RGBvalue*)x2,(RGBvalue*)x3,(RGBvalue*)x4); } void YGL_PRE(blendf_)(INT4*x1, INT4*x2) { blendfunction(*x1,*x2); } /********************* menu.c */ void YGL_PRE(addtop_)(INT4*x1, CHAR*x2, INT4*len, INT4*x3) { addtopup(*x1, apnd_0(x2,len), *x3);} /* defpup() not available in FORTRAN */ INT4 YGL_PRE(dopup_) (INT4*x1) { return dopup(*x1);} void YGL_PRE(freepu_)(INT4*x1) { freepup(*x1);} INT4 YGL_PRE(newpup_)(void) { return newpup();} void YGL_PRE(setpup_)(INT4*x1, INT4*x2, INT4*x3) { setpup(*x1, *x2, *x3);} /********************* ygl.c */ /* Contraints */ void YGL_PRE(minsiz_)(INT4*x1, INT4*x2) { minsize(*x1, *x2);} void YGL_PRE(maxsiz_)(INT4*x1, INT4*x2) { maxsize(*x1, *x2);} void YGL_PRE(prefsi_)(INT4*x1, INT4*x2) { prefsize(*x1, *x2);} void YGL_PRE(prefpo_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4) { prefposition(*x1, *x2, *x3, *x4);} void YGL_PRE(stepun_)(INT4*x1, INT4*x2) { stepunit(*x1, *x2);} void YGL_PRE(keepas_)(INT4*x1, INT4*x2) { keepaspect(*x1, *x2);} void YGL_PRE(noport_)(void) { noport();} void YGL_PRE(nobord_)(void) { noborder();} void YGL_PRE(ginit_) (void) { ginit();} void YGL_PRE(wincon_)(void) { winconstraints();} INT4 YGL_PRE(winope_)(CHAR*x1, INT4*len) { return winopen(apnd_0(x1,len));} INT4 YGL_PRE(swinop_)(INT4*x1) { return swinopen(*x1);} void YGL_PRE(winpos_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4) { winposition(*x1, *x2, *x3, *x4);} void YGL_PRE(winmov_)(INT4*x1, INT4*x2) { winmove(*x1, *x2);} void YGL_PRE(getsiz_)(INT4*x1, INT4*x2) { getsize (x1, x2);} void YGL_PRE(getori_)(INT4*x1, INT4*x2) { getorigin(x1, x2);} void YGL_PRE(rgbmod_)(void) { RGBmode();} void YGL_PRE(cmode_) (void) { cmode();} void YGL_PRE(gconfi_)(void) { gconfig();} void YGL_PRE(winclo_)(INT4*x1) { winclose(*x1);} void YGL_PRE(gexit_) (void) { gexit();} INT4 YGL_PRE(winx_) (INT4*dpy, INT4*win) { return winX((Display*)dpy, (Window)*win);} /* gl2ppm.c */ INT4 YGL_PRE(gl2ppm_)(CHAR*x1, INT4*len) { return gl2ppm(apnd_0(x1,len)); } /* 3d.c */ #ifdef OGL void YGL_PRE(cmov_) (REAL*x1, REAL*x2, REAL*x3) { cmov (*x1, *x2, *x3);} void YGL_PRE(cmovi_) (INT4*x1, INT4*x2, INT4*x3) { cmovi(*x1, *x2, *x3);} void YGL_PRE(cmovs_) (INT2*x1, INT2*x2, INT2*x3) { cmovs(*x1, *x2, *x3);} void YGL_PRE(pnt_) (REAL*x1, REAL*x2, REAL*x3) { pnt (*x1, *x2, *x3);} void YGL_PRE(pnti_) (INT4*x1, INT4*x2, INT4*x3) { pnti(*x1, *x2, *x3);} void YGL_PRE(pnts_) (INT2*x1, INT2*x2, INT2*x3) { pnts(*x1, *x2, *x3);} void YGL_PRE(move_) (REAL*x1, REAL*x2, REAL*x3) { move (*x1, *x2, *x3);} void YGL_PRE(movei_) (INT4*x1, INT4*x2, INT4*x3) { movei(*x1, *x2, *x3);} void YGL_PRE(moves_) (INT2*x1, INT2*x2, INT2*x3) { moves(*x1, *x2, *x3);} void YGL_PRE(rmv_) (REAL*x1, REAL*x2, REAL*x3) { rmv (*x1, *x2, *x3);} void YGL_PRE(rmvi_) (INT4*x1, INT4*x2, INT4*x3) { rmvi(*x1, *x2, *x3);} void YGL_PRE(rmvs_) (INT2*x1, INT2*x2, INT2*x3) { rmvs(*x1, *x2, *x3);} void YGL_PRE(draw_) (REAL*x1, REAL*x2, REAL*x3) { draw (*x1, *x2, *x3);} void YGL_PRE(drawi_) (INT4*x1, INT4*x2, INT4*x3) { drawi(*x1, *x2, *x3);} void YGL_PRE(draws_) (INT2*x1, INT2*x2, INT2*x3) { draws(*x1, *x2, *x3);} void YGL_PRE(rdr_) (REAL*x1, REAL*x2, REAL*x3) { rdr (*x1, *x2, *x3);} void YGL_PRE(rdri_) (INT4*x1, INT4*x2, INT4*x3) { rdri(*x1, *x2, *x3);} void YGL_PRE(rdrs_) (INT2*x1, INT2*x2, INT2*x3) { rdrs(*x1, *x2, *x3);} void YGL_PRE(pmv_) (REAL*x1, REAL*x2, REAL*x3) { pmv (*x1, *x2, *x3);} void YGL_PRE(pmvi_) (INT4*x1, INT4*x2, INT4*x3) { pmvi(*x1, *x2, *x3);} void YGL_PRE(pmvs_) (INT2*x1, INT2*x2, INT2*x3) { pmvs(*x1, *x2, *x3);} void YGL_PRE(rpmv_) (REAL*x1, REAL*x2, REAL*x3) { rpmv (*x1, *x2, *x3);} void YGL_PRE(rpmvi_) (INT4*x1, INT4*x2, INT4*x3) { rpmvi(*x1, *x2, *x3);} void YGL_PRE(rpmvs_) (INT2*x1, INT2*x2, INT2*x3) { rpmvs(*x1, *x2, *x3);} void YGL_PRE(pdr_) (REAL*x1, REAL*x2, REAL*x3) { pdr (*x1, *x2, *x3);} void YGL_PRE(pdri_) (INT4*x1, INT4*x2, INT4*x3) { pdri(*x1, *x2, *x3);} void YGL_PRE(pdrs_) (INT2*x1, INT2*x2, INT2*x3) { pdrs(*x1, *x2, *x3);} void YGL_PRE(rpdr_) (REAL*x1, REAL*x2, REAL*x3) { rpdr (*x1, *x2, *x3);} void YGL_PRE(rpdri_) (INT4*x1, INT4*x2, INT4*x3) { rpdri(*x1, *x2, *x3);} void YGL_PRE(rpdrs_) (INT2*x1, INT2*x2, INT2*x3) { rpdrs(*x1, *x2, *x3);} void YGL_PRE(poly_) (INT4*x1, REAL x2[][3]) { polf (*x1, x2); } void YGL_PRE(polyi_) (INT4*x1, INT4 x2[][3]) { polfi(*x1, x2); } void YGL_PRE(polys_) (INT4*x1, INT2 x2[][3]) { polfs(*x1, x2); } void YGL_PRE(polf_) (INT4*x1, REAL x2[][3]) { polf (*x1, x2); } void YGL_PRE(polfi_) (INT4*x1, INT4 x2[][3]) { polfi(*x1, x2); } void YGL_PRE(polfs_) (INT4*x1, INT2 x2[][3]) { polfs(*x1, x2); } void YGL_PRE(v3s_) (INT2 x1[3]) { v3s(x1);} void YGL_PRE(v3i_) (INT4 x1[3]) { v3i(x1);} void YGL_PRE(v3f_) (REAL x1[3]) { v3f(x1);} void YGL_PRE(v3d_) (REAL8 x1[3]) { v3d(x1);} void YGL_PRE(v4s_) (INT2 x1[4]) { v4s(x1);} void YGL_PRE(v4i_) (INT4 x1[4]) { v4i(x1);} void YGL_PRE(v4f_) (REAL x1[4]) { v4f(x1);} void YGL_PRE(v4d_) (REAL8 x1[4]) { v4d(x1);} void YGL_PRE(swaptm_)(void) { swaptmesh();} void YGL_PRE(ortho_) (REAL*x1, REAL*x2, REAL*x3, REAL*x4, REAL*x5, REAL*x6) { ortho(*x1, *x2, *x3, *x4, *x5, *x6);} void YGL_PRE(lookat_)(REAL*x1, REAL*x2, REAL*x3, REAL*x4, REAL*x5, REAL*x6, INT4*x7) { lookat(*x1, *x2, *x3, *x4, *x5, *x6, *x7);} void YGL_PRE(window_)(REAL*x1, REAL*x2, REAL*x3, REAL*x4, REAL*x5, REAL*x6) { window(*x1, *x2, *x3, *x4, *x5, *x6);} void YGL_PRE(perspe_)(INT4*x1, REAL*x2, REAL*x3, REAL*x4) { perspective(*x1, *x2, *x3, *x4);} void YGL_PRE(polarv_)(REAL*x1, INT4*x2, INT4*x3, INT4*x4) { polarview(*x1, *x2, *x3, *x4);} void YGL_PRE(rot_) (REAL*x1, CHAR*x2) { rot(*x1, *x2);} void YGL_PRE(rotate_)(INT4*x1, CHAR*x2) { rotate(*x1, *x2);} void YGL_PRE(scale_) (REAL*x1, REAL*x2, REAL*x3) { scale(*x1, *x2, *x3);} void YGL_PRE(transl_)(REAL*x1, REAL*x2, REAL*x3) { translate(*x1, *x2, *x3);} void YGL_PRE(loadma_)(Matrix x1) { loadmatrix(x1);} void YGL_PRE(multma_)(Matrix x1) { multmatrix(x1);} void YGL_PRE(pushma_)(void) { pushmatrix();} void YGL_PRE(popmat_)(void) { popmatrix();} void YGL_PRE(shadem_)(INT4*x1) { shademodel(*x1);} void YGL_PRE(c4s_) (INT2 x1[4]) { c4s(x1);} void YGL_PRE(c4i_) (INT4 x1[4]) { c4i(x1);} void YGL_PRE(c4f_) (REAL x1[4]) { c4f(x1);} void YGL_PRE(n3f_) (REAL x1[3]) { n3f(x1);} void YGL_PRE(normal_)(REAL x1[3]) { normal(x1);} void YGL_PRE(backfa_)(LOGICAL*x1) { backface(*x1);} void YGL_PRE(frontf_)(LOGICAL*x1) { frontface(*x1);} INT4 YGL_PRE(getmmo_)(void) { return getmmode();} void YGL_PRE(mmode_) (INT4*x1) { mmode(*x1);} void YGL_PRE(zbuffe_)(LOGICAL*x1) { zbuffer(*x1);} void YGL_PRE(zclear_)(void) { zclear();} void YGL_PRE(zdraw_) (INT4*x1) { zdraw(*x1);} void YGL_PRE(zfunct_)(INT4*x1) { zfunction(*x1);} void YGL_PRE(czclea_)(INT4*x1, INT4*x2) { czclear(*x1, *x2);} void YGL_PRE(depthc_)(INT4*x1) { depthcue(*x1);} void YGL_PRE(lrgbra_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4, INT4*x5, INT4*x6, INT4*x7, INT4*x8) { lRGBrange(*x1, *x2, *x3, *x4, *x5, *x6, *x7, *x8);} void YGL_PRE(lsetde_)(INT4*x1, INT4*x2) { lsetdepth(*x1, *x2);} void YGL_PRE(lshade_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4) { lshaderange(*x1, *x2, *x3, *x4);} /* Display lists */ INT4 YGL_PRE(genobj_)(void) { return genobj();} INT4 YGL_PRE(isobj_) (INT4*x1) { return isobj(*x1);} void YGL_PRE(makeob_)(INT4*x1) { makeobj(*x1);} INT4 YGL_PRE(getope_)(void) { return getopenobj();} void YGL_PRE(closeo_)(void) { closeobj();} void YGL_PRE(callob_)(INT4*x1) { callobj(*x1);} void YGL_PRE(delobj_)(INT4*x1) { delobj(*x1);} /* Lighting */ void YGL_PRE(lmbind_)(INT4*x1, INT4*x2) { lmbind(*x1, *x2);} void YGL_PRE(lmcolo_)(INT4*x1) { lmcolor(*x1);} void YGL_PRE(lmdef_) (INT4*x1, INT4*x2, INT4*x3, REAL x4[]) { lmdef(*x1, *x2, *x3, x4);} void YGL_PRE(rgbwri_)(INT4*x1, INT4*x2, INT4*x3) { RGBwritemask(*x1, *x2, *x3);} /* for Pete Riley */ void YGL_PRE(drawmo_)(INT4*x1) { drawmode(*x1);} void YGL_PRE(iconsi_)(INT4*x1, INT4*x2) { iconsize(*x1, *x2);} void YGL_PRE(overla_)(INT4*x1) { overlay(*x1);} void YGL_PRE(pushat_)(void) { pushattributes();} void YGL_PRE(popatt_)(void) { popattributes();} void YGL_PRE(fullsc_)(void) { fullscrn();} void YGL_PRE(endful_)(void) { endfullscrn();} void YGL_PRE(scrmas_)(INT4*x1, INT4*x2, INT4*x3, INT4*x4) { scrmask(*x1,*x2,*x3,*x4);} #endif /* OGL */ #ifdef COVERSLEEP void YGL_PRE(usleep_)(INT4*x1) {usleep(*x1);} void YGL_PRE(sleep_) (INT4*x1) { sleep(*x1);} #endif /* COVERSLEEP */ ygl-4.2e/examples/0000755000175000017500000000000010621135164013460 5ustar prabhuprabhuygl-4.2e/examples/popup.c0000644000175000017500000000560207463541337015007 0ustar prabhuprabhu/* popup.c by Fred Hucht (C) 1993-2002. * Example program for popup menus */ static const char vcid[] = "$Id: popup.c,v 3.2 1996/07/18 16:35:57 fred Exp $"; #include #include #include #include /* Callback functions */ Int32 fn1(Int32 x) { printf("---> fn1(%d)\n", x); return(100 * x);} Int32 fn2(Int32 x) { printf("---> fn2(%d)\n", x); return(10 + x);} Int32 fe0(Int32 m) { return(m-1); } Int32 fe1(Int32 m, Int32 s) { return(10 *(m-1) + s); } Int32 fe2(Int32 m, Int32 s) { return(100*(m-1) + s); } Int32 End(Int32 x) { return(4711); } int main() { Int32 menu, sub, subsub, dev, r, sub1, sub10, sub100; Int16 val; minsize(300, 300); winopen("Menu"); ortho2(-1.0, 1.0, -1.0, 1.0); subsub = defpup("Sub%%sub!%t%F|#s4%x34|#s5%x35", fn1); /* %F */ sub = defpup("Sub!%t%F|#s4%x24%m|#s5%x25", fn1, /* %F */ subsub); /* %m */ sub1 = defpup("0%t%F|0|1|2|3|4|5|6|7|8|9", fe0); /* %F: fe0 is applied to default return code */ sub10 = defpup("00%t%F|00%M|10%M|20%M|30%M|40%M|50%M|60%M|70%M|80%M|90%M", fe1, /* %F */ /* All submenus are defined with %M, * hence fe1(retval, subretval) is returned. * Example: 30 (item #4) and 6 (item #7) selected * => fe1(4, fe0(7)) == 36 */ sub1,sub1,sub1,sub1,sub1,sub1,sub1,sub1,sub1,sub1); sub100 = defpup("000%t%F|000%M|100%M|200%M|300%M|400%M|500%M|600%M|700%M|800%M|900%M", fe2, /* %F */ /* All submenus are defined with %M, * hence fe2(retval, subretval) is returned. * Example: 100 (item #2), 30 (item #4) and 6 (item #7) selected * => fe2(2, fe1(4, fe0(7))) == 136 */ sub10,sub10,sub10,sub10,sub10,sub10,sub10,sub10,sub10,sub10); menu = defpup("The Title%t%F|Numbers%m|#2%l%f|#3%n|SubSub%m|#5|Sub%m|Exit%n", fn1, /* %F: overall menu callback */ /* #1 */ sub100, /* %m: item #1 has submenu 'sub100' */ /* #2 */ fn2, /* %f: return fn1(fn2(2)) == 1200 */ /* #3 */ fn2, /* %n: don't call fn1(), return fn2(3) == 13*/ /* #4 */ subsub, /* %m: item #4 has submenu 'subsub' */ /* #5 */ /* #6 */ sub, /* %m: item #6 has submenu 'sub' */ /* #7 */ End); /* %n: don't call fn1(), return End(7) == 4711 */ setpup(menu, 5, PUP_GREY); /* Greyout item #5 in menu menu */ setpup(menu, 4, PUP_GREY); /* Greyout item #4 in menu menu */ qdevice(MENUBUTTON); loadXfont(2, "-*-times-medium-r-*-*-*-140-*-*-*-*-iso8859-1"); font(2); while((dev = qread(&val))) { switch(dev) { case REDRAW: color(BLACK); clear(); color(WHITE); circf(0.0, 0.0, 0.8); sleep(0); break; case MENUBUTTON: /* Right button */ if(val == 1) { r = dopup(menu); printf("----> dopup returned %d\n", r); if(r == 4711) { gexit(); exit(0); } } break; } } return 0; } ygl-4.2e/examples/rgbtest.c0000644000175000017500000000630407463541337015316 0ustar prabhuprabhu/* rgbtest.c by Fred Hucht (C) 1993-2002. * Example program with two windows, * one in RGBmode and one in Colormap mode */ static const char vcid[] = "$Id: rgbtest.c,v 3.3 1996/07/18 16:35:57 fred Exp $"; #include #include #include #define STEP 2 #define SIZE (256 * STEP) Int32 RGBwin, cwin; void drawit(int g) { short r,b; reshapeviewport(); for(r = 0; r < 256; r++) for(b = 0; b < 256; b++) { RGBcolor(r, g, b); rectfi(r*STEP, b*STEP, (r+1)*STEP, (b+1)*STEP); } sleep(1); RGBcolor(255,255,0); font(4711); cmov2i(10, 10); charstr("Hello in Yellow"); } void drawitgrey(void) { short i; reshapeviewport(); for(i = 0; i < 256; i++) { RGBcolor(i, i, i); rectfi(i*STEP, 0, (i+1)*STEP, 255); } RGBcolor(255,255,0); font(4711); cmov2i(10, 10); charstr("Hey in Grey"); } void drawit2(void) { winset(cwin); reshapeviewport(); color(BLACK); clear(); color(RED); circf(0.0, 0.0, 0.8); sleep(1); winset(RGBwin); } int main() { Device dev; short val; int green = 128, openwins=0; Int32 xo, yo; Char8 *Title = "RGBmode Window"; /* putenv("YGL_BS=1");*/ /* setenv("YGL_BS","1",1); *//* use this ones under BSD unixes */ minsize(512, 512); cwin = winopen("Colormap Window"); openwins++; winconstraints(); /* remove all constraints */ ortho2(-1.0, 1.0, -1.0, 1.0); color(BLUE); clear(); /* noport(); */ minsize(SIZE, SIZE); #ifdef SUBWIN RGBwin = swinopen(cwin); #else RGBwin = winopen("RGB mode"); #endif openwins++; RGBmode(); gconfig(); /*ortho2(0.0, SIZE - 1, 0.0, SIZE - 1);*/ qdevice(REDRAW); qdevice(KEYBD); qdevice(WINQUIT); qdevice(LEFTMOUSE); tie(LEFTMOUSE, MOUSEX, MOUSEY); /* report mouse position on buttonpress */ winset(RGBwin); getsize(&xo,&yo); loadXfont(4711, "-*-times-medium-r-*-*-*-140-*-*-*-*-iso8859-1"); while (1) { dev = qread(&val); switch(dev) { case LEFTMOUSE: if(val==1) { /* If button pressed */ Int32 x, y, xs, ys; Int16 r, g, b, mx, my; char buf[80]; getorigin(&x, &y); getsize(&xs, &ys); if(MOUSEX != qread(&mx) || MOUSEY != qread(&my)) printf("tie doesn't work, strange...\n"); x = (mx - x) * xo / xs; y = (my - y) * yo / ys; /* Next line is to get the real color (not the desired) * on <24 bit Visuals */ RGBcolor(x, green, y); gRGBcolor(&r, &g, &b); sprintf(buf,"Color at (%d,%d) is (%d,%d,%d).",x,y,r,g,b); wintitle(buf); } else { /* Restore original title */ wintitle(Title); } break; case KEYBD: switch(val) { case '\033' : gexit(); return(0); break; case '0': green = 0; drawit(green); break; case '9': green = 255; drawit(green); break; case '+': green += 16; drawit(green); break; case '-': green -= 16; drawit(green); break; case 'g': drawitgrey(); break; case 'p': printf("Piping RGB window through 'ppmtogif > RGB.gif'\n"); gl2ppm("| ppmtogif > RGB.gif"); ringbell(); break; } break; case WINQUIT: winclose(val); if(0 == --openwins) { gexit(); return(0); } break; case REDRAW: if(val == cwin) drawit2(); else if(val == RGBwin) drawit(green); break; } } } ygl-4.2e/examples/Makefile.std0000644000175000017500000000261006410253271015711 0ustar prabhuprabhu# # Ygl: Run 3d-GL programs with standard X11 routines. # (C) Fred Hucht 1993-97 # EMail: fred@thp.Uni-Duisburg.DE # # $Id: Makefile.std,v 3.3 1997-03-13 16:19:21+01 fred Exp fred $ # Uncomment next line to use X11 bindings X11LIB = -lX11 # Uncomment next line to use OpenGL bindings #OGLIB = -lGL -lGLU # Uncomment next line to use DoubleBuffer or MultiBuffer extension with X11 MBUFLIB = -lXext CDEBUGFLAGS = -O COPTS = # COPTS = -Aa -D_HPUX_SOURCE -L/usr/lib/X11R4 -I/usr/include/X11R4 # For HP-UX 8.0x # COPTS = -Ae -L/usr/lib/X11R5 -I/usr/include/X11R5 # For HP-UX 9.0x # *************************** End of configuration ************************* .SUFFIXES: .gl CFLAGS= $(CDEBUGFLAGS) $(COPTS) -I.. REQUIREDLIBS = -L.. -lYgl $(MBUFLIB) $(X11LIB) $(OGLIB) GLTARGETS = coltest.gl lines.gl rgbtest.gl smile.gl popup.gl lmbind.gl YGLTARGETS = coltest lines rgbtest smile popup lmbind all: $(YGLTARGETS) gl: $(GLTARGETS) .c: $(CC) $(CFLAGS) -o $@ $< $(REQUIREDLIBS) -lm .c.gl: $(CC) $(CFLAGS) -o $@ $< ../gl2ppm.o -lgl -lm clean: /bin/rm -f *.o *~ $(YGLTARGETS) $(GLTARGETS) *.gif smile_xlf smile_f77 smile_f2c smile_f77.c smile_f2c: smile_f77.f f2c smile_f77.f $(CC) $(CFLAGS) -o $@ smile_f77.c -lf2c $(REQUIREDLIBS) smile_f77: smile_f77.f $(FC) $(FFLAGS) -o $@ smile_f77.f $(REQUIREDLIBS) smile_xlf: smile_xlf.f xlf $(FFLAGS) -o $@ smile_xlf.f $(REQUIREDLIBS) ygl-4.2e/examples/lmbind.c0000644000175000017500000001165110374353547015111 0ustar prabhuprabhu/* lmbind.c by Fred Hucht (C) 1996-2002. * Example program for 3D stuff */ static const char vcid[] = "$Id: lmbind.c,v 3.3 1998-10-28 19:23:01+01 fred Exp fred $"; #include #include #include #include #ifndef M_PI # define M_PI 3.1415926536 #endif #define NSPHERE 10 float lmodel[] = { TWOSIDE, 0.00, LMNULL }; float material1[] = { EMISSION, 0.10, 0.10, 0.10, AMBIENT, 0.00, 0.00, 0.00, DIFFUSE, 0.80, 0.80, 0.80, SPECULAR, 1.00, 1.00, 1.00, SHININESS, 10.0, ALPHA, 1.0, LMNULL }; float material2[] = { EMISSION, 1.00, 1.00, 1.00, AMBIENT, 0.00, 0.00, 0.00, DIFFUSE, 0.00, 0.00, 0.00, SPECULAR, 0.00, 0.00, 0.00, LMNULL }; float light1[] = { POSITION, 0.0, 0.0, 1.0, 0.0, /* z +inf */ /* AMBIENT, 0.0, 0.0, 0.0, SPOTDIRECTION, 0.0, 0.0,-1.0,*/ LCOLOR, 1.0, 0.0, 0.0, LMNULL }; float light2[] = { POSITION, 0.0, 1.0, 0.0, 0.0, /* y +inf */ LCOLOR, 0.0, 1.0, 0.0, LMNULL }; float light3[] = { POSITION, 1.0, 0.0, 0.0, 0.0, /* x +inf */ LCOLOR, 0.0, 0.0, 1.0, LMNULL }; Matrix idmat = { {1.0,0.0,0.0,0.0}, /* identity matrix */ {0.0,1.0,0.0,0.0}, {0.0,0.0,1.0,0.0}, {0.0,0.0,0.0,1.0} }; int main(int argc, char *argv[]) { int i; Int32 dev; Int16 val; int mx = 0, my = 0, mz = 0, smi = 0, bf = 0, ff = 0, zb = 1; int l1 = 1, l2 = 2, l3 = 3; int sm[] = {FLAT, GOURAUD}; Int32 Kugel; double d = 0.0; int nsphere = NSPHERE; if (argc > 1) { nsphere = atoi(argv[1]); } minsize(400,400); putenv("YGL_OGL=1"); /* setenv("YGL_OGL","1",1); *//* use this ones under BSD unixes */ winopen("lmbind"); RGBmode(); doublebuffer(); gconfig(); qdevice(MOUSEX); qdevice(MOUSEY); qdevice(KEYBD); qdevice(UPARROWKEY); qdevice(DOWNARROWKEY); Kugel = genobj(); makeobj(Kugel); bgntmesh(); for (i = nsphere / 6; i < nsphere; i++) { double theta = (M_PI / nsphere) * i; double theta2 = (M_PI / nsphere) * (i+1); int j; for (j = 0; j <= 2 * nsphere; j++) { double phi = (M_PI / nsphere) * j; Float32 v[3], n[3]; n[0] = sin(theta) * cos(phi); n[1] = sin(theta) * sin(phi); n[2] = cos(theta); v[0] = n[0]; v[1] = n[1]; v[2] = n[2]; n3f(n); v3f(v); n[0] = sin(theta2) * cos(phi); n[1] = sin(theta2) * sin(phi); n[2] = cos(theta2); v[0] = n[0]; v[1] = n[1]; v[2] = n[2]; n3f(n); v3f(v); } } endtmesh(); closeobj(); lsetdepth(0, 0x7FFFFF); zbuffer(zb); #if 1 mmode(MVIEWING); perspective(600, 1.0, 1.0, 30.0); loadmatrix(idmat); /* redundant here */ lookat(3.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0); #else ortho(-2.0,2.0,-2.0,2.0,-2.0,2.0); /* lookat(0,0,0, 3,3,2, 0);*/ #endif lmdef(DEFLMODEL, 1, sizeof(lmodel)/sizeof(lmodel[0]), lmodel); lmdef(DEFMATERIAL, 1, sizeof(material1)/sizeof(material1[0]), material1); lmdef(DEFMATERIAL, 2, sizeof(material2)/sizeof(material2[0]), material2); /* lmdef(DEFLIGHT, 1, 0, NULL); */ lmdef(DEFLIGHT, 1, sizeof(light1)/sizeof(light1[0]), light1); lmdef(DEFLIGHT, 2, sizeof(light2)/sizeof(light2[0]), light2); lmdef(DEFLIGHT, 3, sizeof(light3)/sizeof(light3[0]), light3); lmbind(LMODEL, 1); lmbind(MATERIAL, 1); lmbind(BACKMATERIAL, 2); lmbind(LIGHT3, l1); lmbind(LIGHT1, l2); lmbind(LIGHT2, l3); while ((dev = qread(&val))) { d = 0; switch (dev) { case MOUSEX: mx = val; break; case MOUSEY: my = val; break; case KEYBD: switch (val) { case '\033': case 'q': exit(0); case '1': l1 = 1 - l1; lmbind(LIGHT3, l1); break; case '2': l2 = 2 - l2; lmbind(LIGHT1, l2); break; case '3': l3 = 3 - l3; lmbind(LIGHT2, l3); break; case 'x': mx += 5; break; case 'y': my += 5; break; case 'z': mz += 5; break; case 'X': mx -= 5; break; case 'Y': my -= 5; break; case 'Z': mz -= 5; break; case 'r': mx = my = mz = 0; break; case 'g': shademodel(sm[smi]); smi = 1 - smi; break; case 'b': bf = 1 - bf; backface(bf); break; case 'f': ff = 1 - ff; frontface(ff); break; case 'u': zb = 1 - zb; zbuffer(zb); break; case 'p': gl2ppm("| ppmtogif > lmbind.gif"); break; } break; case UPARROWKEY: if (val) d = 0.5; break; case DOWNARROWKEY: if (val) d = -0.5; break; } /* No qreset(), drops important events */ /* Move eye */ mmode(MPROJECTION); translate(0.0, 0.0, d); mmode(MVIEWING); pushmatrix(); rotate(30 * mx, 'x'); rotate(30 * my, 'y'); rotate(30 * mz, 'z'); RGBcolor(0,0,0); clear(); zclear(); callobj(Kugel); #if 1 translate(0.0, 0.0, 2.0); callobj(Kugel); translate(0.0, 2.0,-2.0); callobj(Kugel); translate(2.0,-2.0, 0.0); callobj(Kugel); #endif popmatrix(); swapbuffers(); } return 0; } ygl-4.2e/examples/smile_f77.f0000644000175000017500000000243610620321045015422 0ustar prabhuprabhuc c smile_f77.f by Fred Hucht (C) 1993-2007. c Short and simple example program for FORTRAN bindings. c Compile with c make smile_f77 (uses f77 compiler) c or c make smile_f2c (uses f2c compiler) c c NOTE: This example uses the FORTRAN bindings from Ygl, c so most routine- and parameter-names are truncated c to six characters. c c $Id: smile_f77.f,v 3.3 2007-05-09 12:27:49+02 fred Exp $ c program smile integer*4 win include "../irisgl/fgl.h" call prefsi(100, 100) win = winope('Smile!', 6) c write(*,*) win c The background call color(BLACK) call clear() c The face call color(RED) call circfi(50, 50, 40) c The eyes call color(WHITE) call circfi(30, 60, 10) call circfi(70, 60, 10) call color(BLACK) call circfi(30, 60, 5) call circfi(70, 60, 5) c The smile call arci(50, 50, 25, 2000, 3400) c The sleep call sleep(2) c The twinkle call color(RED) call circfi(30, 65, 10) call sleep(1) call color(WHITE) call circfi(30, 60, 10) call color(BLACK) call circfi(30, 60, 5) c The end call sleep(2) call gexit() end ygl-4.2e/examples/smile_xlf.f0000644000175000017500000000300110620321053015574 0ustar prabhuprabhuc c smile.f by Fred Hucht (C) %VAL(1993-2007). c Short and simple example program. This program c works under AIX. c Compile with c c make smile_xlf c c NOTE: This example uses the C routines from libYgl.a. c c c $Id: smile_xlf.f,v 3.3 2007-05-09 12:27:55+02 fred Exp $ c c program smile integer*4 win include "../irisgl/fgl.h" c fgl.h only declares winope, so... integer*4 winopen call prefsize(%VAL(100),%VAL(100)) win = winopen('Smile!') c write(*,*) win c The background call color(%VAL(BLACK)) call clear() c The face call color(%VAL(RED)) call circfi(%VAL(50), %VAL(50), %VAL(40)) c The eyes call color(%VAL(WHITE)) call circfi(%VAL(30), %VAL(60), %VAL(10)) call circfi(%VAL(70), %VAL(60), %VAL(10)) call color(%VAL(BLACK)) call circfi(%VAL(30), %VAL(60), %VAL(5)) call circfi(%VAL(70), %VAL(60), %VAL(5)) c The smile call arci(%VAL(50), %VAL(50), %VAL(25), %VAL(2000), %VAL(3400)) c The sleep call sleep(%VAL(2)) c The twinkle call color(%VAL(RED)) call circfi(%VAL(30), %VAL(65), %VAL(10)) call sleep(%VAL(1)) call color(%VAL(WHITE)) call circfi(%VAL(30), %VAL(60), %VAL(10)) call color(%VAL(BLACK)) call circfi(%VAL(30), %VAL(60), %VAL(5)) c The end call sleep(%VAL(2)) call gexit() end ygl-4.2e/examples/lines.c0000644000175000017500000000566410374054021014746 0ustar prabhuprabhu/* lines.c by Fred Hucht (C) 1993-2005. * Example program to compare performance */ static const char vcid[] = "$Id: lines.c,v 3.3 2005-02-15 11:29:09+01 fred Exp $"; #include #include #define SIZE 400 /* Size of main window */ #define STEP 4 /* Width of lines */ #ifndef TRUE # define TRUE (0==0) # define FALSE (!TRUE) #endif int ncolors; Int32 win, swin; void drawit(Int32 w) { int i, j, col; winset(w); if(w == win) { char *text = "This is font Times 14. Press ESC to exit..."; color(WHITE); clear(); col = 0; for(i=0; i Window1.gif'\n"); winset( win); gl2ppm("| ppmtogif > Window1.gif"); printf("Piping subwindow through 'ppmtogif > Window2.gif'\n"); winset(swin); gl2ppm("| ppmtogif > Window2.gif"); ringbell(); break; case 'q': case '\033': running = FALSE; break; } break; case UPARROWKEY: printf("UpArrow %s\n", (val==1) ? "pressed" : "released"); break; case WINQUIT: running = FALSE; break; } } gexit(); return(0); } ygl-4.2e/examples/coltest.c0000644000175000017500000000303107463541337015313 0ustar prabhuprabhu/* coltest.c by Fred Hucht (C) 1993-2002. * Example for color animation with private colormap */ static const char vcid[] = "$Id: coltest.c,v 3.3 1996/07/18 16:35:57 fred Exp $"; #include #include #include #include #include #include #ifndef M_PI #define M_PI 3.14159265359 #endif void map_hue(Colorindex i, double phi) { mapcolor(i, (int)(127.5 * (1.0+cos(phi ))), (int)(127.5 * (1.0+cos(phi-2./3.*M_PI))), (int)(127.5 * (1.0+cos(phi-4./3.*M_PI))) ); } int main() { int i=0; double phi; Int16 val; Int32 win; minsize(400,400); puts("Using private colormap"); putenv("YGL_PCM=1"); /* setenv("YGL_PCM","1",1); *//* use this ones under BSD unixes */ win = winopen("Coltest, to quit"); qdevice(ESCKEY); qdevice(REDRAW); qdevice(WINQUIT); unqdevice(INPUTCHANGE); while(1) { phi = 2.0 * M_PI * (double)(++i) / 64.0; map_hue(12, phi ); map_hue(13, phi + 0.5 * M_PI); map_hue(14, phi + 1.0 * M_PI); map_hue(15, phi + 1.5 * M_PI); if(qtest()) switch(qread(&val)) { /* process events */ case REDRAW: reshapeviewport(); color(WHITE); clear(); color(12); circfi(100,100,80); color(13); circfi(100,300,80); color(14); circfi(300,300,80); color(15); circfi(300,100,80); break; case ESCKEY: case WINQUIT: gexit(); return(0); break; } usleep(100000); /* Too short sleeps may stress your XServer... */ } } ygl-4.2e/examples/Makefile0000644000175000017500000000000006410253271022416 1ygl-4.2e/examples/Makefile.stdustar prabhuprabhuygl-4.2e/examples/smile.c0000644000175000017500000000151007463541337014747 0ustar prabhuprabhu/* smile.c by Fred Hucht (C) 1993-2002. * Short and simple example program */ static const char vcid[] = "$Id: smile.c,v 3.2 1996/07/18 16:35:57 fred Exp $"; #include #include #include int main() { Int32 win; prefsize(100, 100); win = winopen("Smile!"); /*printf("%d\n", win);*/ /* The background */ color(BLACK); clear(); /* The face */ color(RED); circfi(50, 50, 40); /* The eyes */ color(WHITE); circfi(30, 60, 10); circfi(70, 60, 10); color(BLACK); circfi(30, 60, 5); circfi(70, 60, 5); /* The smile */ arci(50, 50, 25, 2000, 3400); /* The sleep */ sleep(2); /* The twinkle */ color(RED);circfi(30, 65, 10); sleep(1); color(WHITE); circfi(30, 60, 10); color(BLACK); circfi(30, 60, 5); /* The end */ sleep(2); gexit(); return(0); } ygl-4.2e/examples/Imakefile0000644000175000017500000000374307463532664015320 0ustar prabhuprabhuXCOMM XCOMM Ygl: Run 3d-GL programs with standard X11 routines. XCOMM (C) Fred Hucht 1993-2002 XCOMM EMail: fred@thp.Uni-Duisburg.DE XCOMM XCOMM $Id: Imakefile,v 3.4 1997-03-13 16:16:45+01 fred Exp fred $ SRCS = lines.c rgbtest.c coltest.c smile.c popup.c lmbind.c INCLUDES = -I.. #ifdef LinuxArchitecture LOCAL_LDFLAGS = -Xlinker -rpath .. -L.. #else LOCAL_LDFLAGS = -L.. #endif LOCAL_LIBRARIES = -lYgl AllTarget(lines coltest rgbtest smile popup $(THREE_D_TARGETS)) NormalProgramTarget(lines.gl, lines.o, NullParameter,../gl2ppm.o -lgl,NullParameter) NormalProgramTarget(rgbtest.gl,rgbtest.o,NullParameter,../gl2ppm.o -lgl,NullParameter) NormalProgramTarget(coltest.gl,coltest.o,NullParameter,-lgl -lm, NullParameter) NormalProgramTarget(smile.gl, smile.o, NullParameter,-lgl, NullParameter) NormalProgramTarget(popup.gl, popup.o, NullParameter,-lgl, NullParameter) NormalProgramTarget(lmbind.gl, lmbind.o, NullParameter,-lgl -lm, NullParameter) NormalProgramTarget(lines, lines.o, NullParameter,$(LOCAL_LIBRARIES),NullParameter) NormalProgramTarget(rgbtest, rgbtest.o,NullParameter,$(LOCAL_LIBRARIES),NullParameter) NormalProgramTarget(coltest, coltest.o,NullParameter,$(LOCAL_LIBRARIES),-lm) NormalProgramTarget(smile, smile.o, NullParameter,$(LOCAL_LIBRARIES),NullParameter) NormalProgramTarget(popup, popup.o, NullParameter,$(LOCAL_LIBRARIES),NullParameter) NormalProgramTarget(lmbind, lmbind.o, NullParameter,$(LOCAL_LIBRARIES),-lm) DependTarget() gl:: lines.gl coltest.gl rgbtest.gl smile.gl popup.gl lmbind.gl clean:: $(RM) *.gif smile_xlf smile_f2c smile_f77 smile_f77.c smile_f2c:: smile_f77.f f2c smile_f77.f $(CC) $(CFLAGS) -o $@ smile_f77.c -lf2c $(LOCAL_LDFLAGS) $(LOCAL_LIBRARIES) smile_f77:: smile_f77.f $(FC) $(EXTNAME) $(FFLAGS) -o $@ smile_f77.f $(LOCAL_LDFLAGS) $(LOCAL_LIBRARIES) #if defined(AIXArchitecture) || defined(RsArchitecture) smile_xlf:: smile_xlf.f xlf $(FFLAGS) -o $@ smile_xlf.f $(LOCAL_LDFLAGS) $(LOCAL_LIBRARIES) #endif ygl-4.2e/INSTALLATION0000444000175000017500000000336206226152117013473 0ustar prabhuprabhu-*-Text-*- Ygl: Run 2d-GL programs with standard X11 routines. (C) Fred Hucht 1993-96 EMail: fred@thp.Uni-Duisburg.DE Ygl is written in ANSI C, so use gcc if you have problems during compilation. To compile Ygl, follow the following steps: If you have imake, enter: $ xmkmf $ make else edit the file Makefile and type $ make On RS/6000, ignore the warnings from the linker. If the compiler can't find the include file or the linker can't find functions like "XmbufDisplayBuffers", undefine MultiBuffer in the Imakefile. You won't be able to do doublebuffering then. Note for AIX 4.1: You need the LPP X11.adt.ext to compile Ygl with doublebuffering enabled. To make the examples, do a: $ cd examples $ xmkmf # if you have it $ make If you have GL, enter "make gl" to compile the GL versions of the examples. To make the FORTRAN examples, enter: $ make smile_f77 smile_f2c To install the library and the include files Ygl.h and Yfgl.h, type (as root) $ make install If you want the GL-style include files, and Ygl.h and Yfgl.h were installed in /usr/include/X11, enter (as root): $ mkdir /usr/include/gl $ cd /usr/include/gl $ ln -s /usr/include/X11/Ygl.h gl.h $ ln -s /usr/include/X11/Ygl.h device.h $ ln -s /usr/include/X11/Yfgl.h fgl.h $ ln -s /usr/include/X11/Yfgl.h fdevice.h The program "lines.c" is included to test the library and to compare the performance with standard GL. The program "coltest.c" is an example for the use of a private colormap. The program "rgbtest.c" opens both a colormap mode and a RGBcolor window (if your X-Server has a {True|Direct}Color visual...) The program "smile.c" is very simple... The program "smile_f77.f" does same like "smile.c" in FORTRAN. Have fun... Fred