1.1LineSegment

 1 #include <windows.h>
 2 #include <gl/glew.h>
 3 #include <gl/glut.h>
 4 #include <cstdio>
 5 #include <cstdlib>
 6 #include <cmath>
 7
 8 void Init(void)
 9 {
10     glClearColor(1.0, 1.0, 1.0, 0.0);  // Set display-window color to white
11     // Drawing two-dimensional graphics is a special case of rendering 3D graphics
12     // The two dimensional matrix of the world coordinate system is projected onto the screen.
13     glMatrixMode(GL_PROJECTION);
14     gluOrtho2D(0.0, 200.0, 0.0, 150.0);
15
16 }
17
18 void lineSegment(void)
19 {
20     // glClearColor() does not allow the display window appears on the screen
21     // GlClear function allows assignment of the window to appear on the screen
22     glClear(GL_COLOR_BUFFER_BIT);    // Clear displaye window
23
24     glColor3f(1.0, 0.0, 0.0);        // Display the color of the window object
25     glBegin(GL_LINES);
26     glVertex2i(180, 15);             // Specify line_segment geometry
27     glVertex2i(10, 145);
28     glEnd();
29
30     glFlush();                       // Process all OpenGL rountines as quickly as possible
31 }
32
33 int main(int argc, char* argv[])
34 {
35     glutInit(&argc, argv);                 // Initialize GLUT
36                                            // Set the cache and color model of the display window, and so on
37     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
38     glutInitWindowPosition(50, 100);  // Display the location of the specified pixel
39     glutInitWindowSize(400, 300);     // Set the initial width and height of the display window
40     glutCreateWindow("An Example OpenGL Program");      // Title
41
42     Init();
43     // LineSegment for the creation of the graph,
44     // passed to the function, and the graph is assigned to the display window
45     glutDisplayFunc(lineSegment);  // Display callback function
46     // The original display window has not yet appeared on the screen,
47     // glutMainLoop () will display the window and its content activation, and must be the last function
48     glutMainLoop();
49     return 0;
50 }

时间: 2024-11-15 06:21:53

1.1LineSegment的相关文章