-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewtriangle.cpp
More file actions
67 lines (63 loc) · 983 Bytes
/
newtriangle.cpp
File metadata and controls
67 lines (63 loc) · 983 Bytes
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
#include <GL/glut.h>
GLfloat t,u=1;
void init()
{
glClearColor(0,0,0,0);
glMatrixMode(GL_PROJECTION);
glOrtho(0,500,0,500,0,10);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(t,u,0);
glBegin(GL_TRIANGLES);
glVertex2f(50,50);
glVertex2f(200,50);
glVertex2f(125,250);
glEnd();
glFlush();
}
void key(unsigned char button,int x, int y)
{
if(button=='s','a','d')
{ t=0;
u=1;
}
else if(button=='q','w','e')
{ t=1;
u=0;
}
else{
}
glutPostRedisplay();
}
void mouse(int button,int state,int x, int y)
{
if(button==GLUT_LEFT_BUTTON)
{
t=0;
u=1;
}
else if(button==GLUT_RIGHT_BUTTON)
{
t=1;
u=0;
}
else{
}
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(600, 600);
glutCreateWindow("Triangle Color Change");
init();
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}