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

SCM Repository

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

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

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

revision 1883, Sat May 19 14:43:02 2012 UTC revision 1884, Sun May 20 15:07:04 2012 UTC
# Line 15  Line 15 
15  #ifdef DIDEROT_CODE  #ifdef DIDEROT_CODE
16  #include "vr-lite-cam.h"  #include "vr-lite-cam.h"
17  #endif  #endif
18  #include "teem/nrrd.h"  #include "util.h"
19  #include "teem/biff.h"  #include "load-png.h"
20    
21  /* pixel dimensions of output */  /* pixel dimensions of output */
22  #define WIDTH   512  #define WIDTH   512
23  #define HEIGHT  512  #define HEIGHT  512
24    
25    static inline void CheckError ()
26    {
27        GLenum errCode;
28        if ((errCode = glGetError()) != GL_NO_ERROR) {
29            fprintf(stderr, "OpenGL error: %s\n", gluErrorString(errCode));
30            exit (1);
31        }
32    }
33    
34  /***** Globals for viewing, etc. *****/  /***** Globals for viewing, etc. *****/
35    
36  Nrrd            *Diderot;       // input image nrrd  Nrrd            *Diderot;       // input image nrrd
# Line 47  Line 56 
56    // Draw background    // Draw background
57      float       halfWid = 0.5 * (float)Width;      float       halfWid = 0.5 * (float)Width;
58      float       halfHt = 0.5 * (float)Height;      float       halfHt = 0.5 * (float)Height;
59        glEnable (GL_TEXTURE_2D);
60        glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
61      glBindTexture (GL_TEXTURE_2D, ImageTexture);      glBindTexture (GL_TEXTURE_2D, ImageTexture);
62      glBegin (GL_QUADS);      glBegin (GL_QUADS);
63            glColor3f (0.1, 0.1, 0.1);
64          glTexCoord2f (0.0, 0.0);          glTexCoord2f (0.0, 0.0);
65          glVertex2f (-halfWid, -halfHt);          glVertex2f (-halfWid, -halfHt);
66          glTexCoord2f (1.0, 0.0);          glTexCoord2f (1.0, 0.0);
# Line 58  Line 70 
70          glTexCoord2f (0.0, 1.0);          glTexCoord2f (0.0, 1.0);
71          glVertex2f (-halfWid, halfHt);          glVertex2f (-halfWid, halfHt);
72      glEnd();      glEnd();
73        glDisable (GL_TEXTURE_2D);
74        CheckError ();
75    
76    // Draw current render state    // Draw current render state
77    
# Line 97  Line 111 
111  }  }
112    
113  // initialize a texture from a grayscale Nrrd file  // initialize a texture from a grayscale Nrrd file
114  void InitTexture (Nrrd *nin)  void InitTexture ()
115  {  {
116      if ((nin->dim != 2)      Image2D_t *img = LoadImage ("data/ddro-tx.png", false, GRAY_IMAGE);
117      ||  (nin->axis[0].kind != nrrdKindSpace)      if (img == 0) {
118      ||  (nin->axis[1].kind != nrrdKindSpace)) {          fprintf (stderr, "unable to load texture file\n");
         fprintf (stderr, "unable to handle nrrd file\n");  
         exit (1);  
     }  
   
   // determine the pixel format for the texture  
     GLenum type;  
     switch (nin->type) {  
       case nrrdTypeUChar: type = GL_UNSIGNED_BYTE; break;  
       case nrrdTypeFloat: type = GL_FLOAT; break;  
       default:  
         fprintf (stderr, "unable to handle nrdd file type %d\n", nin->type);  
119          exit (1);          exit (1);
120      }      }
121    
# Line 122  Line 125 
125    
126    // load the texture data    // load the texture data
127      glBindTexture (GL_TEXTURE_2D, texId);      glBindTexture (GL_TEXTURE_2D, texId);
128      glTexImage2D (GL_TEXTURE_2D,  /* or GL_TEXTURE_RECTANGLE ? */      int sts = TexImage (img);
129          0,      if (sts != GL_NO_ERROR) {
130          GL_RED,          fprintf(stderr, "error loading texture\n");
131          nin->axis[0].size, nin->axis[1].size, 0,          exit (1);
132          GL_RED, type,      }
133          nin->data);  
134  /* check for error */      FreeImage (img);
135    
136      ImageTexture = texId;      ImageTexture = texId;
137  }  }
# Line 188  Line 191 
191      glfwSetKeyCallback ((GLFWkeyfun)TwEventKeyGLFW);  // redirect to AntTweakBar      glfwSetKeyCallback ((GLFWkeyfun)TwEventKeyGLFW);  // redirect to AntTweakBar
192      glfwSetCharCallback ((GLFWcharfun)TwEventCharGLFW);  // redirect to AntTweakBar      glfwSetCharCallback ((GLFWcharfun)TwEventCharGLFW);  // redirect to AntTweakBar
193    
194    // load Diderot image as nrrd file    // load Diderot image for background texture
195      Diderot = nrrdNew();      InitTexture ();
     if (nrrdLoad(Diderot, "data/ddro-tx.nrrd", 0) != 0) {  
         char *msg = biffGetDone(NRRD);  
         fprintf (stderr, "Error loading nrrd file: %s", msg);  
         free (msg);  
         return 0;  
     }  
   
     InitTexture (Diderot);  
196    
197    // 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)
198      while (glfwGetWindowParam(GLFW_OPENED) && !glfwGetKey(GLFW_KEY_ESC)) {      while (glfwGetWindowParam(GLFW_OPENED) && !glfwGetKey(GLFW_KEY_ESC)) {

Legend:
Removed from v.1883  
changed lines
  Added in v.1884

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