Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /examples/vr-demo/main.c
ViewVC logotype

Diff of /examples/vr-demo/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2062, Wed Oct 31 17:59:30 2012 UTC revision 2063, Wed Oct 31 18:36:09 2012 UTC
# Line 12  Line 12 
12    
13  #include "GL/glfw.h"  #include "GL/glfw.h"
14  #include "util.h"  #include "util.h"
15  #include "vr-lite.h"  #include "vr.h"
16  #include <unistd.h>  #include <unistd.h>
17    
18  /* minimum and maximum values from */  /* minimum and maximum values from */
# Line 54  Line 54 
54  Nrrd            *Diderot;       // input image nrrd  Nrrd            *Diderot;       // input image nrrd
55  unsigned int    Width;          // view window width  unsigned int    Width;          // view window width
56  unsigned int    Height;         // view window height  unsigned int    Height;         // view window height
57  GLuint          ImageTexture;   // Texture ID of background image  bool            NeedsRedraw;
58    bool            NeedsRecompute;
59    
60    
61    
# Line 99  Line 100 
100          0.0, 0.0, 0.0,          0.0, 0.0, 0.0,
101          0.0, 1.0, 0.0);          0.0, 1.0, 0.0);
102    
     // Send the new window size to AntTweakBar  
     TwWindowSize(width, height);  
   
103    // remember width and height    // remember width and height
104      Width = width;      Width = width;
105      Height = height;      Height = height;
106    
107  }  }
108    
109  // initialize a texture from a grayscale Nrrd file  void GetData (VR_World_t *wrld, Nrrd *nRGB)
 void InitTexture ()  
 {  
     Image2D_t *img = LoadImage ("data/ddro-tx.png", true, GRAY_IMAGE);  
     if (img == 0) {  
         fprintf (stderr, "unable to load texture file\n");  
         exit (1);  
     }  
   
   // generate the TeXID  
     GLuint texId;  
     glGenTextures (1, &texId);  
   
   // load the texture data  
     glBindTexture (GL_TEXTURE_2D, texId);  
     int sts = TexImage (img);  
     if (sts != GL_NO_ERROR) {  
         fprintf(stderr, "error loading texture\n");  
         exit (1);  
     }  
     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);  
     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);  
   
     FreeImage (img);  
   
     ImageTexture = texId;  
 }  
   
 void TW_CALL StartButtonCB (void *data)  
 {  
     State_t *st = (State_t *)data;  
   
     if (st->running == 0) {  
         st->running = 1;  
         TwSetParam (st->ctls, "StartButton", "label", TW_PARAM_CSTRING, 1, "Stop");  
     }  
     else {  
         st->running = 0;  
         TwSetParam (st->ctls, "StartButton", "label", TW_PARAM_CSTRING, 1, "Start");  
     }  
 }  
   
 void GetData (VR_World_t *wrld, Nrrd *nData)  
110  {  {
111    // get snapshot of state      if (VR_OutputGet_outRGBA (wrld, nRGB)) {
     if (VR_Snapshot_pos (wrld, nData)) {  
112        // error        // error
113          fprintf(stderr, "Error getting nrrd data\n");          fprintf(stderr, "Error getting nrrd data\n");
114          exit(1);          exit(1);
# Line 182  Line 137 
137    
138    // Set GLFW event callbacks    // Set GLFW event callbacks
139      glfwSetWindowSizeCallback (WindowSizeCB);      glfwSetWindowSizeCallback (WindowSizeCB);
140      glfwSetKeyCallback ((GLFWkeyfun)TwEventKeyGLFW);  /* FIXME: set up key callback */
   
   // load Diderot image for background texture  
     InitTexture ();  
   
   // setup the world coords.  
   // FIXME: we should get these from the nrrd file, but for now I'm hard coding them  
     WrldOrigin[0] = -0.0184375;  
     WrldOrigin[1] = -0.0184375;  
     WrldDim[0] = 0.013125 * 80.0;  
     WrldDim[1] = 0.013125 * 80.0;  
141    
142    // initialize the Diderot program    // initialize the Diderot program
143      VR_World_t *wrld = VR_Init ();      VR_World_t *wrld = VR_Init ();
# Line 201  Line 146 
146      Nrrd *nRGB = nrrdNew();      Nrrd *nRGB = nrrdNew();
147    
148    // get and render initial state    // get and render initial state
149      GetData (wrld, nData);      GetData (wrld, nRGB);
150      Draw (nData);      Draw (nRGB);
151    
152    // Main loop (repeated while window is not closed and [ESC] is not pressed)    // Main loop (repeated while window is not closed and [ESC] is not pressed)
153      NeedsRecompute = true;      NeedsRecompute = true;
# Line 217  Line 162 
162                  fprintf(stderr, "Error getting nrrd data\n");                  fprintf(stderr, "Error getting nrrd data\n");
163                  exit(1);                  exit(1);
164              }              }
165                NeedsRedraw = true;
166          }          }
167          if (NeedsRedraw) {          if (NeedsRedraw) {
168                Draw (nRGB);
169                NeedsRedraw = false;
170          }          }
171          glfwWaitEvents();          glfwWaitEvents();
172      }      }
# Line 226  Line 174 
174    // shutdown the world    // shutdown the world
175      VR_Shutdown (wrld);      VR_Shutdown (wrld);
176    
177    // Terminate AntTweakBar and GLFW    // Terminate GLFW
     TwTerminate();  
178      glfwTerminate();      glfwTerminate();
179    
180      return 0;      return 0;

Legend:
Removed from v.2062  
changed lines
  Added in v.2063

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0