/* * lines2.c * This program demonstrates geometric primitives and * their attributes. */ #ifdef __APPLE__ #include #else #include #endif #include #define drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES); \ glVertex2f ((x1),(y1)); glVertex2f ((x2),(y2)); glEnd(); void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_FLAT); } void display(void) { int i; glClear (GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); drawOneLine (50.0, 125.0, 150.0, 125.0); glColor3f(1.0, 1., 0.); glPushMatrix(); glTranslatef(50., 125., 0.); glRotatef(-45, 0, 0, 1); glTranslatef(-50., -125., 0.); drawOneLine (0.0, 0.0, 150.0, 125.0); glPopMatrix(); glColor3f(1.0, 0., 0.); glPushMatrix(); glRotatef(-45, 0, 0, 1); drawOneLine (50.0, 125.0, 150.0, 125.0); glPopMatrix(); glFlush(); } 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); } /* ARGSUSED1 */ void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; } } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (400, 400); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); init (); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }