title: Create contour plot in opengl using grid data and a 1D texture map
body: <p>I have a set of X,Y,Z values on a regular spaced grid from which I need to create a color-filled contour plot using C++.  I've been googling on this for days and the consensus appears to be that this is achievable using a 1D texture map in openGL.  However I have not found a single example of how to actually do this and I'm not getting anywhere just reading the openGL documentation.  My confusion comes down to one core question:</p>
  
  <p>My data does not contain an X,Y value for every pixel - it's a regularly spaced grid with data every 4 units on the X and Y axis, with a positive integer Z value.</p>
  
  <p>For example:  (0, 0, 1), (4, 0, 1), (8, 0, 2), (0, 4, 2), (0, 8, 4), (4, 4, 3), etc.</p>
  
  <p><strong>Since the contours would be based on the Z value and there are gaps between data points, how does applying a 1D texture achieve contouring this data (i.e. how does applying a 1D texture interpolate between grid points?)</strong></p>
  
  <p>The closest I've come to finding an example of this is in the online version of the Redbook (http://fly.cc.fer.hr/~unreal/theredbook/chapter09.html) in the teapot example but I'm assuming that teapot model has data for every pixel and therefore no interpolation between data points is needed.</p>
  
  <p>If anyone can shed light on my question or better yet point to a concrete example of working with a 1D texture map in this way I'd be forever grateful as I've burned 2 days on this project with little to show for it.</p>
  
  <p>EDIT:</p>
  
  <p>The following code is what I'm using and while it does display the points in the correct location there is no interpolation or contouring happening - the points are just displayed as, well, points.</p>
  
  <pre><code>//Create a 1D image - for this example it's just a red line
  int stripeImageWidth = 32;
  GLubyte   stripeImage[3*stripeImageWidth];
  for (int j = 0; j &lt; stripeImageWidth; j++) {
      stripeImage[3*j] = j &lt; 2 ? 0 : 255;
      stripeImage[3*j+1] = 255;
      stripeImage[3*j+2] = 255;
  }
  glDisable(GL_TEXTURE_2D);
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  glTexImage1D(GL_TEXTURE_1D, 0, 3, stripeImageWidth, 0, GL_RGB, GL_UNSIGNED_BYTE, stripeImage);
  glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  
  glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR );
  float s[4] = { 0,1,0,0 };
  glTexGenfv( GL_S, GL_OBJECT_PLANE, s );
  glEnable( GL_TEXTURE_GEN_S );
  glEnable( GL_TEXTURE_1D );
  glBegin(GL_POINTS);
  
  //_coords contains X,Y,Z data - Z is the value that I'm trying to contour
  for (int x = 0; x &lt; _coords.size(); ++x)
  {
      glTexCoord1f(static_cast&lt;ValueCoord*&gt;(_coords[x])-&gt;GetValue());
      glVertex3f(_coords[x]-&gt;GetX(), _coords[x]-&gt;GetY(), zIndex);
  }
  glEnd();
  </code></pre>