home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / GLX / texvol / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.4 KB  |  180 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*----------------------------------------------------------------------------
  18.  *
  19.  * file   : main.c for texVol (volume rendering with 2d or 3d textures)
  20.  *
  21.  * Author : Yusuf Attarwala
  22.  * Date   : Sep 93
  23.  *
  24.  *---------------------------------------------------------------------------*/
  25. #include <sys/types.h>
  26. #include <malloc.h>
  27. #include <sys/stat.h>
  28. #include <fcntl.h>
  29. #include <math.h>
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include <stdlib.h>
  33.  
  34. #define DEFINE_VOL_GLOBALS 1
  35. #include "globals_vol.h"
  36. #undef DEFINE_VOL_GLOBALS
  37. #include <Xm/Protocols.h>
  38. #include <X11/StringDefs.h>
  39.  
  40. typedef struct _cmdLine {
  41.     String  modelName;           /* model name */
  42.     String  textureMode;         /* texture mode */
  43. } CmdLine, *CmdLinePtr;
  44.  
  45. CmdLine commandLine;
  46.  
  47. static XtResource resources[] = {
  48.     {"modelName",    "ModelName",   XtRString,  sizeof(String),
  49.       XtOffset(CmdLinePtr,modelName), XtRString, "Untitled",},
  50.     {"textureMode",   "TextureMode",XtRString, sizeof(String),
  51.       XtOffset(CmdLinePtr,textureMode), XtRString, "2"},
  52. };
  53.  
  54. static XrmOptionDescRec options[] = {
  55.     {"-f",      "modelName",  XrmoptionSepArg, NULL},
  56.     {"-tex",    "textureMode",XrmoptionSepArg, NULL},
  57. };
  58.  
  59. static String fallbackResources[] = {
  60.     "*background:                  grey",
  61.     "*XmSeparator.traversalOn:     False",
  62.     "*XmLabel.traversalOn:         False",
  63.     "*fillOnSelect:                True",
  64.     "*selectColor:                 yellow",
  65.     "*ui*fontList:            -adobe-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*",
  66.     "*message*fontList:            -adobe-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*",
  67.     "*gizmo*fontList:              -adobe-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*",
  68.     NULL
  69. };
  70.  
  71. /* function declaration */
  72. void main();
  73. void readAndInitData();
  74.  
  75.  
  76. void
  77. printDescription()
  78. {
  79.     printf("\n Volume rendering using 2D Textures \n\n");
  80.     printf(" This demo maintains three orthogonal sets of planes\n");
  81.     printf(" on which 2d textures are mapped. Depending upon the\n");
  82.     printf(" direction of view, one set is selected and the textures\n");
  83.     printf(" from these planes are composited using blendfunction.\n\n");
  84.     printf(" The data set is 128 x 128 x 64 slices of 8 bit data.\n");
  85.     printf(" 2 component textures (alpha + intensity) are used for\n");
  86.     printf(" this demo\n\n");
  87.     printf(" Author : Yusuf Attarwala  x 3-3342 (SGI - Applications)\n\n");
  88.     printf(" Please refer to the following cheat sheet for keyboard\n");
  89.     printf(" commands\n\n");
  90. }
  91. extern Boolean prepare2DTexture(),
  92.                prepare3DTexture();
  93.  
  94. void
  95. main(argc,argv)
  96. int argc;
  97. char **argv;
  98. {
  99.     Atom xaWmDeleteWindow;
  100.     void doExit();
  101.  
  102.     toplevel = XtAppInitialize(&appContext,"TexVol",
  103.                                options,XtNumber(options),
  104.                                &argc,argv,
  105.                                fallbackResources,
  106.                                (ArgList)NULL, 0);
  107.  
  108.  
  109.     display  = XtDisplay(toplevel);
  110.     screen   = XDefaultScreen(display);
  111.     XtGetApplicationResources(toplevel,&commandLine,
  112.                               resources,XtNumber(resources),
  113.                               NULL,0);
  114.  
  115.  
  116.     if (strcmp(commandLine.textureMode,"2") == 0) {
  117.     textureMode = TEXTURE_2D;
  118.         if (!getgdesc(GD_TEXTURE)) {
  119.             printf("This machine does not support textures..., aborting\n");
  120.             exit(0);
  121.         }
  122.         XtVaSetValues(toplevel,XmNtitle,"2D VolRender UI",
  123.                            XmNiconName,"TexVol",
  124.                            XmNdeleteResponse, XmDO_NOTHING,
  125.                            NULL);
  126.  
  127.     }
  128.     else {
  129.        textureMode = TEXTURE_3D;
  130.         if (!getgdesc(GD_TEXTURE_3D)) {
  131.             printf("This machine does not support 3d textures..., aborting\n");
  132.             printf("Try running in 2d texture mode (default)\n");
  133.             exit(0);
  134.         }
  135.         XtVaSetValues(toplevel,XmNtitle,"3D VolRender UI",
  136.                            XmNiconName,"TexVol",
  137.                            XmNdeleteResponse, XmDO_NOTHING,
  138.                            NULL);
  139.  
  140.     }
  141.     xaWmDeleteWindow = XmInternAtom(display,"WM_DELETE_WINDOW",TRUE);
  142.     XmAddWMProtocolCallback(toplevel,xaWmDeleteWindow,doExit,0);
  143.  
  144.  
  145.  
  146.     if (strcmp(commandLine.modelName,"Untitled") != 0)  {
  147.         readAndInitData(commandLine.modelName,128,128,64,0);
  148.     }
  149.     else {
  150.         readAndInitData("clamped.bin",128,128,64,0);
  151.     }
  152.  
  153.     initGlobals();
  154.     createMenus(toplevel);
  155.     computeBoundingBox();
  156.     computeProjectionView();
  157.     XtRealizeWidget(toplevel);
  158.  
  159.     createGraphics(toplevel);
  160.     drawScene();
  161.     XFlush(display);
  162.  
  163.     if (textureMode == TEXTURE_2D) {
  164.     prepare2DTexture();
  165.     }
  166.     else {
  167.     prepare3DTexture();
  168.     }
  169.     drawScene();
  170.  
  171.     XtAppMainLoop(appContext);
  172. }
  173.  
  174. void
  175. doExit()
  176. {
  177.     exit(0);
  178. }
  179.  
  180.