static int Info(int help) { int i; if (help) { p_stderr("gist: info command syntax:\n info\n"); p_stderr(" Print descriptions of all current output files.\n"); return 0; } p_stdout("\n"); CGMinfo(); p_stdout("Number Draw Send Type Name\n"); for (i=0 ; i<8 ; i++) { if (outEngines[i]) { char msg[80]; sprintf(msg, "%3d %s %s %s ", i, yorn[outDraw[i]], yorn[outSend[i]], tname[outTypes[i]]); p_stdout(msg); p_stdout(outNames[i]? outNames[i] : ""); p_stdout("\n"); } } p_stdout("\n"); return 0; }
static int MakePS(int help) { char *token; int device; if (help) { p_stderr("gist: ps command syntax:\n ps psout\n"); p_stderr(" Opens a PostScript file psout for output.\n"); p_stderr(" Subsequent send commands will write to psout,\n"); p_stderr(" unless the send to list is modified (see send).\n"); return 0; } token= strtok(0, " \t\n"); if (!token) { p_stderr("gist: (SYNTAX) psout name missing in ps command\n"); return 0; } if (CheckEOL("ps")) return 0; device= FindDevice(); if (device>=8) return 0; CreatePS(device, token); return 0; }
static int GetPageGroup(char *token) { int n, m, s; char *suffix, *tok; s= 1; n= m= (int)strtol(token, &suffix, 10); if (suffix!=token && *suffix=='-') { tok= suffix+1; n= (int)strtol(tok, &suffix, 10); if (suffix!=tok && *suffix=='-') { tok= suffix+1; s= (int)strtol(tok, &suffix, 10); if (suffix==tok) suffix= tok-1; /* this is an error */ } } if (*suffix) { p_stderr("gist: (SYNTAX) "); p_stderr(token); p_stderr(" is not a legal page number group\n"); return 1; } if (nPageGroups>=32) { p_stderr("gist: (SYNTAX) too many page number groups (32 max)\n"); return 1; } mPage[nPageGroups]= m; nPage[nPageGroups]= n; sPage[nPageGroups]= s; nPageGroups++; return 0; }
static int MessageAndExit(char *msg) { p_stderr("gist: "); p_stderr(msg); p_stderr("\ngist: try gist -help for usage\n"); p_quit(); return 1; }
static int Quit(int help) { if (help) { p_stderr("gist: quit command syntax:\n quit\n"); p_stderr(" Finish and close any output files, then exit.\n"); p_stderr(" Synonyms: exit, end (no abbreviations allowed)\n"); return 0; } return 1; }
static int CheckEOL(char *command) { if (strtok(0, " \t\n")) { p_stderr("gist: (SYNTAX) garbage after "); p_stderr(command); p_stderr(" command\n"); return 1; } else { return 0; } }
void Warning(char *general, char *particular) { if (++warningCount > 5) return; if (no_warnings) { if (no_warnings==1) p_stderr("gist: (WARNING) rerun without -nowarn to see warnings"); no_warnings= 2; return; } p_stderr("gist: (WARNING) "); p_stderr(general); p_stderr(particular); p_stderr("\n"); }
static int MakeX(int help) { char *token, *server; int dpi, device, defDPI; if (help) { p_stderr("gist: display command syntax:\n "); p_stderr("display host:server.screen [dpi]\n"); p_stderr(" Connects to the specified X server.\n"); p_stderr(" Subsequent draw commands will write to server,\n"); p_stderr(" unless the draw to list is modified (see draw).\n"); p_stderr(" If specified, 40<=dpi<=200 (default 100).\n"); return 0; } token= strtok(0, " \t\n"); if (!token) { p_stderr("gist: (SYNTAX) cgmoutput name missing in cgm command\n"); return 0; } server= token; token= strtok(0, " \t\n"); if (token) { char *suffix; dpi= (int)strtol(token, &suffix, 0); if (*suffix) { p_stderr("gist: (SYNTAX) dpi unintelligble in display command\n"); return 0; } if (dpi<40 && dpi>200) { p_stderr( "gist: (SYNTAX) dpi not between 40 and 200 in display command\n"); return 0; } if (CheckEOL("display")) return 0; } else { dpi= 100; } device= FindDevice(); if (device>=8) return 0; defDPI= defaultDPI; defaultDPI= dpi; CreateX(device, server); defaultDPI= defDPI; return 0; }
static int Special(int help) { if (help) { char msg[80]; sprintf(msg, "gist: n%c command syntax:\n n%c\n", cSuffix, cSuffix); p_stderr(msg); if (cSuffix=='f') p_stderr(" Forward n (default 1) pages, then draw\n"); else if (cSuffix=='b') p_stderr(" Backward n (default 1) pages, then draw\n"); else p_stderr(" Go to page n (default 1), then draw\n"); return 0; } if (CheckEOL("nf, nb, or ng")) return 0; DoSpecial(nPrefix, cSuffix); return 0; }
static int GetDeviceList(int ds, char *command) { int device; char *token= strtok(0, " \t\n"); if (token) { char *suffix; for (device=0 ; device<8 ; device++) outMark[device]= 0; do { device= (int)strtol(token, &suffix, 10); if (*suffix || device<0 || device>7) { p_stderr("gist: (SYNTAX) "); p_stderr(token); p_stderr(" not a legal device# in "); p_stderr(command); p_stderr(" command\n"); return 1; } if (!outEngines[device]) Warning("ignoring non-existent device# ", token); else outMark[device]= 1; } while ((token= strtok(0, " \t\n"))); if (ds==0) { for (device=0 ; device<8 ; device++) if (outMark[device]) break; if (device>=8) { Warning(command, " command with no legal devices, no action taken"); return 1; } } } else if (ds==0) { for (device=0 ; device<8 ; device++) outMark[device]= 0; } else { for (device=0 ; device<8 ; device++) outMark[device]= outSend[device]; } return 0; }
static int FreeAny(int help) { int i; if (help) { p_stderr("gist: free command syntax:\n free [device# ...]\n"); p_stderr(" Finish and close the device#(s). If none given,\n"); p_stderr(" frees all send devices,\n"); p_stderr(" (Use the info command to describe current device numbers.)\n"); return 0; } if (GetDeviceList(1, "free")) return 0; for (i=0 ; i<8 ; i++) { if (outMark[i]) { GpKillEngine(outEngines[i]); outEngines[i]= 0; } } return 0; }
static int MakeCGM(int help) { char *token, *cgmout; long size= 0; int device; if (help) { p_stderr("gist: cgm command syntax:\n cgm cgmout [size]\n"); p_stderr(" Opens a CGM file cgmout for output.\n"); p_stderr(" The size (default 1000000) is the maximum size of a\n"); p_stderr(" single file in the output family, in bytes.\n"); p_stderr(" Subsequent send commands will write to cgmout,\n"); p_stderr(" unless the send to list is modified (see send).\n"); return 0; } token= strtok(0, " \t\n"); if (!token) { p_stderr("gist: (SYNTAX) cgmout name missing in cgm command\n"); return 0; } cgmout= token; token= strtok(0, " \t\n"); if (token) { char *suffix; size= strtol(token, &suffix, 0); if (*suffix) { p_stderr("gist: (SYNTAX) size unintelligble in cgm command\n"); return 0; } if (CheckEOL("cgm")) return 0; } device= FindDevice(); if (device>=8) return 0; if (!CreateCGM(device, cgmout) && size>0) ((CGMEngine *)outEngines[device])->fileSize= size; return 0; }
/* ARGSUSED */ static void u_fd0_ready(void *c) { char *line = u_input_line; int n; /* before calling fgets, check to be sure that this process is * not in the background (via UNIX shell job control) */ if (u_in_background()) return; do { if (u_input_max < (line-u_input_line)+1024) { if (u_input_max > 16000) break; n = line - u_input_line; u_input_line = p_realloc(u_input_line, u_input_max+1024); u_input_max += 1024; line = u_input_line + n; } if (!fgets(line, 1024, stdin)) { int at_eof = feof(stdin); clearerr(stdin); if (++u_term_errs>3 || at_eof) { /* cannot read stdin -- maybe serious error, remove it */ u_event_src(0, (void (*)(void *))0, (void *)0); return; } } else { u_term_errs = 0; /* reset error counter on each successful read */ } n = strlen(line); line += n; } while (n==1023 && line[-1]!='\n'); if (line[-1]=='\n') line[-1] = '\0'; if (u_stdin) u_stdin(u_input_line); else p_stderr("\a"); /* beep to indicate rejection */ if (u_input_max>1024) { u_input_line = p_realloc(u_input_line, 1024); u_input_max = 1024; } }
static int SaveName(int device, char *name) { int len; if (name == outNames[device]) return 0; len= name? (int)strlen(name) : 0; if (len>outLengths[device]) { if (outLengths[device]>0) p_free(outNames[device]); outNames[device]= (char *)p_malloc(len+1); if (!outNames[device]) { p_stderr("gist: (SEVERE) memory manager failed in SaveName\n"); outLengths[device]= 0; return 1; } outLengths[device]= len; } if (name) strcpy(outNames[device], name); else if (outLengths[device]>0) outNames[device][0]= '\0'; else outNames[device]= 0; return 0; }
static int OpenIn(int help) { char *token; if (help) { p_stderr("gist: open command syntax:\n open cgminput\n"); p_stderr(" Closes the current CGM input file, then opens cgminput.\n"); p_stderr(" Only a Gist-compliant binary CGM file is legal.\n"); p_stderr(" The cgminput may be the first file of a family.\n"); p_stderr(" Subsequent page numbers refer to this input file.\n"); return 0; } token= strtok(0, " \t\n"); if (!token) { p_stderr("gist: (SYNTAX) cgminput name missing in open command\n"); return 0; } if (CheckEOL("open")) return 0; if (no_warnings) no_warnings= 1; /* one warning per file family */ OpenCGM(token); return 0; }
static int EPS(int help) { char *token; int device; if (help) { p_stderr("gist: eps command syntax:\n eps epsout\n"); p_stderr(" Open an Encapsulated PostScript file epsout, write\n"); p_stderr(" the current page to it, then close epsout.\n"); p_stderr(" (Note that an EPS file can have only a single page.)\n"); return 0; } token= strtok(0, " \t\n"); if (!token) { p_stderr("gist: (SYNTAX) epsout name missing in eps command\n"); return 0; } if (CheckEOL("eps")) return 0; device= FindDevice(); if (device>=8) return 0; device= FindDevice(); if (device>=8) return 0; outEngines[device]= GpPSEngine("CGM Viewer", cgmLandscape, 0, "_tmp.eps"); if (!outEngines[device]) { Warning(gistError, ""); Warning("Unable to create PostScript engine ", token); return 0; } GpPreempt(outEngines[device]); nPage[0]= mPage[0]= CGMRelative(0); sPage[0]= 1; nPageGroups= 1; /* First read does PS part, second computes EPS preview */ if (!ReadCGM(mPage, nPage, sPage, nPageGroups)) { GpPreempt(0); outEngines[device]= EPSPreview(outEngines[device], token); if (outEngines[device]) { GpPreempt(outEngines[device]); ReadCGM(mPage, nPage, sPage, nPageGroups); } else { Warning("memory manager failed creating EPS engine ", token); return 0; } } if (outEngines[device]) { GpPreempt(0); GpKillEngine(outEngines[device]); outEngines[device]= 0; } return 0; }
static int HelpAndExit(void) { p_stderr("Usage: gist [cgminput] [options] [page list]\n\n"); p_stderr(" options: -in cgminput (open cgminput for input)\n"); p_stderr(" -cgm cgmout (open cgmout for output)\n"); p_stderr(" -ps psout (open psout for output)\n"); p_stderr(" -display host:n.m (connect to X server)\n"); p_stderr(" -75 (default to 75 dpi)\n"); p_stderr(" -100 (default to 100 dpi)\n"); p_stderr(" -gks (default to 8x8 inches)\n"); p_stderr(" -geometry WxH (initial window size in pixels)\n"); p_stderr(" -nd (not even default X server)\n"); p_stderr(" -b (batch mode, implies -nd)\n"); p_stderr(" -x (graphics window only, no keyboard)\n"); p_stderr(" -nowarn (only one warning message printed)\n"); p_stderr(" -f (PostScript to stdout, implies -b)\n"); p_stderr(" -fmbug (if EPS files are for FrameMaker)\n"); p_stderr(" -bg0fg1 (force color 0 to bg, 1 to fg)\n"); p_stderr(" -esc0 (skip ^_! escapes-assumed if -gks)\n"); p_stderr(" -esc1 (handle ^_! text escapes-default)\n"); p_stderr(" page list: [page group] [page group] ...\n"); p_stderr(" page group: n (output page n)\n"); p_stderr(" page group: n-m (output pages n->m inclusive)\n"); p_stderr(" page group: n-m-s (output every s-th page, n-m)\n"); p_quit(); return 1; }
static int GetCommand(char *token) { char **command= commandList; char *cmd; char *now= token; int quitOK= 0; if (!now) return -1; /* Quit has two synonyms, ? is a synonym for help, and f, b, and g are special command forms. */ if (strcmp(token, "exit")==0 || strcmp(token, "end")==0 || strcmp(token, "quit")==0) { /* Quit and its synonyms cannot be abbreviated */ now= "quit"; quitOK= 1; } else if (strcmp(token, "?")==0) now= "help"; else if (strcmp(token, "f")==0) now= "1f"; else if (strcmp(token, "b")==0) now= "1b"; else if (strcmp(token, "g")==0) now= "1g"; else if (strcmp(token, "s")==0) now= "send"; /* Check for nf, nb, ng */ if (*now<='9' && *now>='0') { char *suffix; nPrefix= (int)strtol(now, &suffix, 10); cSuffix= *suffix; if ((cSuffix=='f' || cSuffix=='b' || cSuffix=='g') && *(suffix+1)=='\0') { while (*command) command++; return command-commandList; } } cmd= *command; while (cmd && *now>*cmd) cmd= *(++command); while (cmd && *now==*cmd) { while (*cmd && *now==*cmd) { now++; cmd++; } if (!*now) break; /* token matches cmd */ now= token; cmd= *(++command); } if (!cmd || *now) { p_stderr("gist: Unknown command: "); p_stderr(token); p_stderr("\n Type help for help.\n"); return -1; } if (*cmd) { now= token; cmd= *(command+1); if (cmd && *now++==*cmd++) { while (*cmd && *now==*cmd) { now++; cmd++; } if (!*now) { p_stderr("gist: Ambiguous command: "); p_stderr(token); p_stderr("\n Type help for help.\n"); return -1; } } } if (strcmp(*command, "quit")==0 && !quitOK) { p_stderr("gist: The quit command cannot be abbreviated.\n"); return -1; } return command-commandList; }
void yglTexcell2(long nx, long ny, long nz, double delta[3], unsigned char *tex) { /* The input is a 3D array of RGBA's and a vector of zone sizes. */ long i, j, k, n, nnx, nny, nnz, nh, nv, nhs, nvs, indt, dt, dir; float fracx, fracy, fracz; float x0, y0, z0, x1, y1, z1, dx, dy, dz; float x, y, z; double absx, absy, absz; unsigned char *newTexImage, *subImage; #ifdef DO_TEX_TEST GLint format, redSize, greenSize, blueSize, alphaSize; GLint texWidth, texHeight; #endif if(alpha_pass) return; yglPrepTex2d(); /* Textures must be a power of 2 in size. Find the smallest power of 2 that will hold the input array */ n= nx-1; nnx= 1; if(n) { do { nnx *= 2; } while(n= n/2); } fracx= (float)nx/(float)nnx; n= ny-1; nny= 1; if(n) { do { nny *= 2; } while(n= n/2); } fracy= (float)ny/(float)nny; n= nz-1; nnz= 1; if(n) { do { nnz *= 2; } while(n= n/2); } fracz= (float)nz/(float)nnz; /* There are nx by ny by nz cells to be volume rendered. FOR NOW, assume that the cells are aligned with the axes. */ dx= (float) delta[0]; dy= (float) delta[1]; dz= (float) delta[2]; #ifdef USE_DATA /* find the axis most closely matching the viewing direction */ absx= glCurrWin3d->view[0] < 0 ? -glCurrWin3d->view[0] : glCurrWin3d->view[0]; absy= glCurrWin3d->view[1] < 0 ? -glCurrWin3d->view[1] : glCurrWin3d->view[1]; absz= glCurrWin3d->view[2] < 0 ? -glCurrWin3d->view[2] : glCurrWin3d->view[2]; if(absx < absy) { if(absy < absz) { /* the view direction is most nearly along z */ dir= 3; if(glCurrWin3d->view[2] < 0) dir= -3; nh= nnx; nv= nny; nhs= nx; nvs= ny; } else { /* the view direction is most nearly along y */ dir= 2; if(glCurrWin3d->view[1] < 0) dir= -2; nh= nnz; nv= nnx; nhs= nz; nvs= nx; } } else { if(absx < absz) { /* the view direction is most nearly along z */ dir= 3; if(glCurrWin3d->view[2] < 0) dir= -3; nh= nnx; nv= nny; nhs= nx; nvs= ny; } else { /* the view direction is most nearly along x */ dir= 1; if(glCurrWin3d->view[0] < 0) dir= -1; nh= nny; nv= nnz; nhs= ny; nvs= nz; } } #else nh= nnx; nv= nny; #endif glGenTextures(1, &texName); glBindTexture(GL_TEXTURE_2D, texName); newTexImage= (unsigned char *)p_malloc(sizeof(unsigned char)*4*nh*nv); subImage= (unsigned char *)p_malloc(sizeof(unsigned char)*4*nhs*nvs); { int err; const GLubyte *errstr; err= glGetError(); errstr= gluErrorString(err); err++; } #ifdef DO_TEX_TEST glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGBA, nnx, nny, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &redSize); glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_GREEN_SIZE, &greenSize); glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_BLUE_SIZE, &blueSize); glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE, &alphaSize); glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &texWidth); glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &texHeight); #endif glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); /* glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nh, nv, 0, GL_RGBA, GL_UNSIGNED_BYTE, newTexImage); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); { int err; const GLubyte *errstr; err= glGetError(); errstr= gluErrorString(err); err++; } #ifdef USE_DATA x0= 0.0; x1= x0+(nx-1)*dx; y0= 0.0; y1= y0+(ny-1)*dy; z0= 0.0; z1= z0+(nz-1)*dz; #ifdef DEBUG_PRINT { char msg[100]; sprintf(msg,"direction is %d\n",dir); p_stderr(msg); } #endif switch(dir) { case 1: /* the view direction is most nearly along x */ x= x0; /* draw planes in back to front order */ for(i= 0; i < nx; i++) { /* load the proper texture plane */ for(k= 0; k < nz; k++) { for(j= 0; j < ny; j++) { indt= 4*(j+k*ny); dt= 4*(i+j*nx+k*nx*ny); subImage[indt ]= tex[dt]; subImage[indt+1]= tex[dt+1]; subImage[indt+2]= tex[dt+2]; subImage[indt+3]= tex[dt+3]; } } /* replace the portion of the texture for which there is data */ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, ny, nz, GL_RGBA, GL_UNSIGNED_BYTE, subImage); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y0, z0); glTexCoord2f(fracy, 0.0f); glVertex3f(x, y1, z0); glTexCoord2f(fracy, fracz); glVertex3f(x, y1, z1); glTexCoord2f(0.0f, fracz); glVertex3f(x, y0, z1); glEnd(); x += dx; } break; case -1: /* the view direction is most nearly along negative x */ x= x1; /* draw planes in back to front order */ for(i= nx-1; i >= 0; i--) { /* load the proper texture plane */ for(k= 0; k < nz; k++) { for(j= 0; j < ny; j++) { indt= 4*(j+k*ny); dt= 4*(i+j*nx+k*nx*ny); subImage[indt ]= tex[dt]; subImage[indt+1]= tex[dt+1]; subImage[indt+2]= tex[dt+2]; subImage[indt+3]= tex[dt+3]; } } /* replace the portion of the texture for which there is data */ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, ny, nz, GL_RGBA, GL_UNSIGNED_BYTE, subImage); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y0, z0); glTexCoord2f(0.0f, fracz); glVertex3f(x, y0, z1); glTexCoord2f(fracy, fracz); glVertex3f(x, y1, z1); glTexCoord2f(fracy, 0.0f); glVertex3f(x, y1, z0); glEnd(); x -= dx; } break; case 2: /* the view direction is most nearly along y */ y= y0; /* draw planes in back to front order */ for(j= 0; j < ny; j++) { /* load the poper texture plane */ for(k= 0; k < nz; k++) { for(i= 0; i < nx; i++) { indt= 4*(i+k*nx); dt= 4*(i+j*nx+k*nx*ny); subImage[indt ]= tex[dt]; subImage[indt+1]= tex[dt+1]; subImage[indt+2]= tex[dt+2]; subImage[indt+3]= tex[dt+3]; } } /* replace the portion of the texture for which there is data */ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, nx, nz, GL_RGBA, GL_UNSIGNED_BYTE, subImage); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(x0, y, z0); glTexCoord2f(0.0f, fracz); glVertex3f(x0, y, z1); glTexCoord2f(fracx, fracz); glVertex3f(x1, y, z1); glTexCoord2f(fracx, 0.0f); glVertex3f(x1, y, z0); glEnd(); y += dy; } break; case -2: /* the view direction is most nearly along negative y */ y= y1; /* draw planes in back to front order */ for(j= ny-1; j >=0; j--) { /* load the poper texture plane */ for(k= 0; k < nz; k++) { for(i= 0; i < nx; i++) { indt= 4*(i+k*nx); dt= 4*(i+j*nx+k*nx*ny); subImage[indt ]= tex[dt]; subImage[indt+1]= tex[dt+1]; subImage[indt+2]= tex[dt+2]; subImage[indt+3]= tex[dt+3]; } } /* replace the portion of the texture for which there is data */ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, nx, nz, GL_RGBA, GL_UNSIGNED_BYTE, subImage); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(x0, y, z0); glTexCoord2f(fracx, 0.0f); glVertex3f(x1, y, z0); glTexCoord2f(fracx, fracz); glVertex3f(x1, y, z1); glTexCoord2f(0.0f, fracz); glVertex3f(x0, y, z1); glEnd(); y -= dy; } break; case 3: /* the view direction is most nearly along z */ z= z0; /* draw planes in back to front order */ for(k= 0; k < nz; k++) { /* load the poper texture plane */ for(j= 0; j < ny; j++) { for(i= 0; i < nx; i++) { indt= 4*(i+j*nx); dt= 4*(i+j*nx+k*nx*ny); subImage[indt ]= tex[dt]; subImage[indt+1]= tex[dt+1]; subImage[indt+2]= tex[dt+2]; subImage[indt+3]= tex[dt+3]; } } glBindTexture(GL_TEXTURE_2D, texName); { int err; const GLubyte *errstr; err= glGetError(); errstr= gluErrorString(err); err++; } /* replace the portion of the texture for which there is data */ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, nx, ny, GL_RGBA, GL_UNSIGNED_BYTE, subImage); { int err; const GLubyte *errstr; err= glGetError(); errstr= gluErrorString(err); err++; } glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(x0, y0, z); glTexCoord2f(fracx, 0.0f); glVertex3f(x1, y0, z); glTexCoord2f(fracx, fracy); glVertex3f(x1, y1, z); glTexCoord2f(0.0f, fracy); glVertex3f(x0, y1, z); glEnd(); z += dz; } break; case -3: /* the view direction is most nearly along negative z */ z= z1; /* draw planes in back to front order */ for(k= nz-1; k >= 0; k--) { /* load the poper texture plane */ for(j= 0; j < ny; j++) { for(i= 0; i < nx; i++) { indt= 4*(i+j*nx); dt= 4*(i+j*nx+k*nx*ny); subImage[indt ]= tex[dt]; subImage[indt+1]= tex[dt+1]; subImage[indt+2]= tex[dt+2]; subImage[indt+3]= tex[dt+3]; } } /* replace the portion of the texture for which there is data */ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, nx, ny, GL_RGBA, GL_UNSIGNED_BYTE, subImage); glBindTexture(GL_TEXTURE_2D, texName); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(x0, y0, z); glTexCoord2f(0.0f, fracy); glVertex3f(x0, y1, z); glTexCoord2f(fracx, fracy); glVertex3f(x1, y1, z); glTexCoord2f(fracx, 0.0f); glVertex3f(x1, y0, z); glEnd(); z -= dz; } break; } #else /* the view direction is most nearly along z */ z= 0.0; y0= 0.0; x0= 0.0; y1= y0+(ny-1)*dy; x1= x0+(nx-1)*dx; /* draw planes in back to front order */ for(k= 0; k < nz; k++) { /* load the poper texture plane */ for(j= 0; j < ny; j++) { for(i= 0; i < nx; i++) { subImage[4*(i+j*nnx)]= (int)((i+j+k)*255.0/((nx-1.0)+(ny-1.0))) %255; subImage[4*(i+j*nnx)+1]= (int)((i+j+k)*255.0/((nx-1.0)+(ny-1.0))+80) %255; subImage[4*(i+j*nnx)+2]= (int)((i+j+k)*255.0/((nx-1.0)+(ny-1.0))+160) %255; subImage[4*(i+j*nnx)+3]= 50; } } /* replace the portion of the texture for which there is data */ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, nnx, nny, GL_RGBA, GL_UNSIGNED_BYTE, subImage); glBindTexture(GL_TEXTURE_2D, texName); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(x0, y0, z); glTexCoord2f(0.0f, fracy); glVertex3f(x0, y1, z); glTexCoord2f(fracx, fracy); glVertex3f(x1, y1, z); glTexCoord2f(fracx, 0.0f); glVertex3f(x1, y0, z); glEnd(); z += dz; } #endif glDeleteTextures(1, &texName); p_free(newTexImage); p_free(subImage); yglEndTex2d(); }
static int Send(int help) { int i, n; char *token; if (help) { p_stderr("gist: send command syntax:\n send [page list]\n"); p_stderr( " Copy the page(s) (default current page) from the current CGM input\n"); p_stderr(" to all display output devices.\n"); p_stderr(" By default, these are all X windows.\n"); p_stderr(" Use alternate syntax:\n send to [device#1] ...\n"); p_stderr(" to specify a particular list of devices to be used\n"); p_stderr(" by the send command. Without any device numbers,\n"); p_stderr(" send to restores the default list of devices.\n"); p_stderr(" (Use the info command to describe current device numbers.)\n"); p_stderr(" Page list syntax: group1 [group2 ...]\n"); p_stderr(" Page group syntax: n - just page n\n"); p_stderr(" m-n - pages n thru m\n"); p_stderr(" m-n-s - pages n thru m, step s\n"); return 0; } token= strtok(0, " \t\n"); if (token && strcmp(token, "to")==0) { DrawSend(1, token); return 0; } n= 0; for (i=0 ; i<8 ; i++) { if (!outSend[i]) GpDeactivate(outEngines[i]); if (outSend[i] && !GpActivate(outEngines[i])) n++; } if (n) DrawSend(1, token); else Warning("no devices active for send command", ""); return 0; }
static int Help(int help) { int cmd; if (help) { p_stderr("gist: help command syntax:\n help [command]\n"); p_stderr(" Print help message (for given command).\n"); return 0; } cmd= GetCommand(strtok(0, " \t\n")); if (cmd<0) { int len; char line[80], **command= commandList; p_stderr("gist: Input Syntax:\n command [arg1] [arg2] ...\n"); strcpy(line, " Available commands are: "); len= 27; for (;;) { for (;;) { if (len+strlen(*command) > 72) { strcpy(line+len, "\n"); p_stderr(line); break; } strcpy(line+len, *command); len+= strlen(*command++); if (!*command) { strcpy(line+len, "\n"); p_stderr(line); break; } strcpy(line+len, ", "); len+= 2; } if (!*command) break; strcpy(line, " "); len= 5; } p_stderr(" The quit command has two synonyms: exit, end\n"); p_stderr(" Any command except quit may be abbreviated by\n"); p_stderr(" omitting characters from the right.\n"); p_stderr(" The help command explains specific syntax, e.g.:\n"); p_stderr(" help cgm\n"); p_stderr(" describes the syntax of the cgm command.\n"); p_stderr(" Five commands can be typed to a gist X window:\n"); p_stderr(" nf - forward n pages and draw (default 1)\n"); p_stderr(" nb - backward n pages and draw (default 1)\n"); p_stderr(" ng - go to page n and draw (default 1)\n"); p_stderr(" s - send current page\n"); p_stderr(" q - quit\n"); } else { CommandList[cmd](1); } return 0; }