gluOrtho2D?

nothing display on my screen…why?
what gluOrtho2D for?

#include <GL/glut.h>

void init (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0); //Set display-window color //or can use glClearIndex (index);
glMatrixMode (GL_PROJECTION);
gluOrtho2D (0.0, 200.0, 0.0, 150.0);
}

void lineSegment (void)
{
glClear (GL_COLOR_BUFFER_BIT);

glColor3f (0.0, 1.0, 0.0);

glBegin(GL_QUADS); // Draw A Quad

glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left

glEnd(); // Done Drawing The Quad

glFlush ();
}

void main (int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition (50, 100);
glutInitWindowSize (400, 300);
glutCreateWindow (“An example OpenGL Program”);

init ();
glutDisplayFunc (lineSegment);
glutMainLoop ();
}

You’re drawing your quad on the near clipping plane. Try -1 for your Z position.

Also, your far clipping plane (150.0) should have a value less than your near clipping plane.

He’s using gluOrtho2D, so the near and far clip planes are at -1 and 1, respectively.

As for the problem, you’re drawing a a quad from (-1, -1) to (1, 1), but the screen ranges from (0, 0) to (200, 150), so you should see the quad as a tiny dot in the lower left corner.