1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #include<stdlib.h> #include<stdio.h> #include<time.h> #include<GL/glut.h> void init ( void ){ glClearColor ( 1.0, 1.0, 1.0, 0.0 ); glMatrixMode ( GL_PROJECTION ); gluOrtho2D ( 0.0, 100.0, 0.0, 150.0 ); } void DrawPOLYGON (void) { glClear (GL_COLOR_BUFFER_BIT); glColor3f (0.0, 0.0, 1.0); glBegin(GL_POLYGON); glVertex2i (10,10); glVertex2i (50,10); glVertex2i (50,80); glVertex2i (10,80); glEnd ( ); glLineWidth(2.0f); glColor3f (1.0, 0.0, 0.0); glBegin ( GL_LINES ); glVertex2i ( 10, 10 ); glVertex2i ( 50, 10 ); glVertex2i ( 50, 80 ); glVertex2i ( 10, 80 ); glVertex2i ( 50, 10 ); glVertex2i ( 50, 80 ); glVertex2i ( 10, 80 ); glVertex2i ( 10, 10 ); glEnd (); glFlush ( ); } void lineSegment ( void ){ glClear ( GL_COLOR_BUFFER_BIT ); glColor3f ( 1.0, 0.0, 0.0 ); glBegin ( GL_LINES ); glVertex2i ( 10, 10 ); glVertex2i ( 50, 10 ); glVertex2i ( 50, 40 ); glVertex2i ( 10, 40 ); glVertex2i ( 50, 10 ); glVertex2i ( 50, 40 ); glVertex2i ( 10, 40 ); glVertex2i ( 10, 10 ); glEnd (); glFlush (); } int main ( int argc, char**argv ){ glutInit ( &argc, argv ); glutInitWindowSize(400,300); glutInitWindowPosition(50,100); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB ); glutCreateWindow("B0329029"); init (); glutDisplayFunc ( lineSegment ); glutDisplayFunc (DrawPOLYGON); glutMainLoop (); } |
Direct link: https://paste.plurk.com/show/foAJT2JnnOChSc7qyUlH