-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLab-2.cpp
More file actions
97 lines (86 loc) · 2.2 KB
/
Lab-2.cpp
File metadata and controls
97 lines (86 loc) · 2.2 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <GL/gl.h>
#include <GL/glut.h>
void display(void)
{
/* clear all pixels */
glClear(GL_COLOR_BUFFER_BIT);
/* draw white polygon (rectangle) with corners at
* (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)
*/
glColor3f(0.0, 0.25, 1.0);
glBegin(GL_POLYGON);
glVertex2i(300, 500);
glVertex2i(350, 600);
glVertex2i(400, 500);
glVertex2i(500, 450);
glVertex2i(400, 400);
glVertex2i(350, 300);
glVertex2i(300, 400);
glVertex2i(200, 450);
glEnd();
glColor3f(1.0, 0.21, 0.0);
glBegin(GL_POLYGON);
glVertex2i(450, 650);
glVertex2i(500, 750);
glVertex2i(550, 650);
glVertex2i(650, 600);
glVertex2i(550, 550);
glVertex2i(500, 450);
glVertex2i(450, 550);
glVertex2i(350, 600);
glEnd();
glColor3f(1.0, 0.0, 1.0);
glBegin(GL_POLYGON);
glVertex2i(600, 500);
glVertex2i(650, 600);
glVertex2i(700, 500);
glVertex2i(800, 450);
glVertex2i(700, 400);
glVertex2i(650, 300);
glVertex2i(600, 400);
glVertex2i(500, 450);
glEnd();
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex2i(450, 350);
glVertex2i(500, 450);
glVertex2i(550, 350);
glVertex2i(650, 300);
glVertex2i(550, 250);
glVertex2i(500, 150);
glVertex2i(450, 250);
glVertex2i(350, 300);
glEnd();
/* don't wait!
* start processing buffered OpenGL routines
*/
glFlush();
}
void init(void)
{
/* select clearing (background) color */
glClearColor(0.0, 0.0, 0.0, 0.0);
/* initialize viewing values */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 900, 0.0, 900);
}
/*
* Declare initial window size, position, and display mode
* (single buffer and RGBA). Open window with "hello"
* in its title bar. Call initialization routines.
* Register callback function to display graphics.
* Enter main loop and process events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("hello");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ISO C requires main to return int. */
}