[SOLVED] Wrong setup, black screen

Started by Keith, November 11, 2010, 21:13:40

Previous topic - Next topic

Keith

I have been able to get the demos to work. Now I am trying to draw some contour lines and I can not see them. The center is at 1407.4397, 1248.7677
    lowest elevation is 650.0 highest elevation is 1100.0
    min  X=740.291432, Y=842.416942
    max  X=2074.58807, Y=1655.118549
So I am trying to look at the site from the center pointing down at the site (xy plane on the screen).

I am creating the contour lines in a display list using the "natural" coordinates within the bounds above.

GL11.glNewList(1, GL11.GL_COMPILE);

GL11.glLineWidth(1.0f); 
for (SiteElement contour: contourLines)  {
        GL11.glBegin(GL11.GL_LINE_LOOP);
        GL11.glColor3f(1.0f, 1.0f, 1.0f);
        for (Point p: contourLine.getPointList()) {
          GL11.glVertex3d(p.getX().doubleValue(), 
                          p.getY().doubleValue(),
                          p.getZ().doubleValue());
        }
        GL11.glEnd();
} // end for each contour line
GL11.glEndList();


This is how I setup the display (x, y, and z are the current desired viewpoint and are initialized
to the center, highest elevation):

private void viewWholeSurface(boolean initialize)
  {
   
    /*
    The following is from a posting by Dave Shreiner on setting up a basic viewing 
    system:
        First, compute a bounding sphere for all objects in your scene. 
        This should provide you with two bits of information: the center of the 
        sphere (let ( c.x, c.y, c.z ) be that point) and its diameter (call it "diam").

        Next, choose a value for the zNear clipping plane. General guidelines 
        are to choose something larger than, but close to 1.0. So, let's say you set
     */
    Point min = contour.getMinMax()[0].clone(),
          max = contour.getMinMax()[1].clone();
    float diam = (float) maxZ.subtract(minZ)
                         .max(max.getX().subtract(min.getX()))
                         .max(max.getY().subtract(min.getY()))
                         .doubleValue(); 


    if (initialize)
    {
      /*
      Structure your matrix calls in this order (for an Orthographic projection):
       */
      float zNear = 1.0f,
            zFar = zNear + diam;
      
      
      /*
      This approach should center your objects in the middle of the window 
      and stretch them to fit (i.e., its assuming that you're using a window 
      with aspect ratio = 1.0). If your window isn't square, compute left, right, 
      bottom, and top, as above, and put in the following logic 
      before the call to glOrtho():
       */
      
      double aspect = 1.0; 
      
      if (mode.getWidth() != mode.getHeight())
      {
        aspect = (double) mode.getWidth() / (double) mode.getHeight(); 
      }


      GL11.glMatrixMode(GL11.GL_PROJECTION); 
      GL11.glLoadIdentity(); 
      GLU.gluPerspective(45f, (float)aspect, zNear, zFar);
    }

 
    /*
      The above code should position the objects in your scene appropriately. 
      If you intend to manipulate (i.e. rotate, etc.), you need to add a viewing 
      transform to it.

      A typical viewing transform will go on the ModelView matrix and might look 
      like this:
    */
    GL11.glMatrixMode(GL11.GL_MODELVIEW); 
    GL11.glLoadIdentity(); 
    GL11.glViewport(0, 0, mode.getWidth(), mode.getHeight()); 
    GL11.glShadeModel(GL11.GL_FLAT);
    
    GLU.gluLookAt (x, y, z, x, y, 0f, 0f, 1f, 0f); 
  }


I setup the display by:

   Display.setDisplayMode(mode);
   Display.setTitle("CityView");
   Display.create();

    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    GL11.glClearDepth(1.0);

    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
    viewWholeSurface(true);


To draw the contour lines, in the rendering loop, I:

   viewWholeSurface(false);
   GL11.glColor3f(1.0f, 1.0f, 1.0f);
   GL11.glCallList(1);


So what am I doing wrong?

Keith

What I was doing wrong was thinking about this incorrectly. As is stated clearly in the documentation, the view point is always at (0, 0, 0) so you need to move the site in an opposite transformation from the one you want. What I did was remove the call to 
   GLU.gluLookAt (x, y, z, x, y, 0f, 0f, 1f, 0f); 

and instead during initialization set (note the negative values)
   xOffset = -sitecenter.x; yOffset = -sitecenter.y; zOffset = -(min elevation); 

then before drawing made a call to
   GL11.glTranslated(xOffset, yOffset, zOffset); 

which moved the site so it was visible from 0, 0, 0. I also adjusted (and am still adjusting) xFar to get a better value.

This is exactly the opposite of the way I normally think about drawing graphics and it makes my head hurt. So far, performance is good on my crappy display card.