[vox-tech] opengl: lines and points

Peter Jay Salzman p at dirac.org
Sun Jan 30 07:05:42 PST 2005


On Sat 29 Jan 05, 10:38 PM, Ken Bloom <kabloom at ucdavis.edu> said:
> On Sun, 30 Jan 2005 00:49:56 -0500
> p at dirac.org (Peter Jay Salzman) wrote:
 
[original code snipped - reposted below]

> I'm not sure why it shows up for you when you deleted one of the lines,
> but when I ran your code as written, the lines were outside the
> (-1.0,-1.0) to (1.0,1.0) clipping box, so they weren't getting drawn.
> Changing the coordinates helped, and they were both drawn.

Wait -- what clipping box?  I request an 800x600 window.  The camera should
be positioned at the origin, facing down the -z axis, and have coordinates
800 by 600.

In fact, this function displays a big "X" on the screen, which extends
nearly, but not quite, the length of the window's diagonals.  It works as
expected:

   void xDisplay(void)
   {
      glClear (GL_COLOR_BUFFER_BIT);
      glColor3f( 1.0, 1.0, 1.0 );

      glBegin( GL_LINES );
         glVertex2f( 10.0f, 10.0f );    // lower left
         glVertex2f( 790.0f, 590.0f );  // upper right
         glVertex2f( 10.0f, 590.0f );   // upper left
         glVertex2f( 790.0f, 10.0f );   // lower right
      glEnd();

      glFlush();
   }

This function displays nothing but blankness for me:

   void tDisplay(void)
   {
      glClear (GL_COLOR_BUFFER_BIT);
      glColor3f( 1.0, 1.0, 1.0 );

      glBegin( GL_LINES );
         glVertex2f( 10.0f, 300.0f );   // hoizontal line
         glVertex2f( 790.0f, 300.0f );  // hoizontal line
         glVertex2f( 400.0f, 10.0f );   // vertical line
         glVertex2f( 400.0f, 590.0f );  // vertical line
      glEnd();

      glFlush();
   }

And this is the rest of the program:

   void reshape (int w, int h)
   {
      glViewport (0, 0, (GLsizei) w, (GLsizei) h);
      glMatrixMode (GL_PROJECTION);
      glLoadIdentity ();
      gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
   }

   int main(int argc, char *argv[])
   {
      glutInit(&argc, argv);
      glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
      glutInitWindowSize (800, 600); 
      glutInitWindowPosition (100, 100);
      glutCreateWindow (argv[0]);

      glClearColor(0.0, 0.0, 0.0, 0.0);
      glShadeModel (GL_FLAT);

      glutDisplayFunc(tDisplay);  // xDisplay works.  tDisplay doesn't.
      glutReshapeFunc(reshape);

      glutMainLoop();

      return 0;
   }

Do you not get the same results as I am?

Pete

-- 
The mathematics of physics has become ever more abstract, rather than more
complicated.  The mind of God appears to be abstract but not complicated.
He also appears to like group theory.  --  Tony Zee's "Fearful Symmetry"

GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E  70A9 A3B9 1945 67EA 951D


More information about the vox-tech mailing list