-
Notifications
You must be signed in to change notification settings - Fork 0
/
arrowKeyTriangle.c
58 lines (47 loc) · 962 Bytes
/
arrowKeyTriangle.c
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
#include<GL/glut.h>
#include<stdio.h>
GLfloat angle = 0.0f;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0,0.4, 0);
glRotatef(angle, 0, 0, 1);
glTranslatef(0, -0.4, 0);
glBegin(GL_POLYGON);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.4, 0.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glEnd();
glutSwapBuffers();
}
void handleKeyPress(int key, int x, int y)
{
switch(key){
case GLUT_KEY_LEFT:
angle -= 5.0f;
break;
case GLUT_KEY_RIGHT:
angle += 5.0f;
break;
}
glutPostRedisplay();
}
void CustomInit()
{
glClearColor(0, 0, 0, 1);
}
int main(int argc, char * argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB| GLUT_DOUBLE);
glutInitWindowPosition(50, 50);
glutInitWindowSize(600, 600);
glutCreateWindow("Rotating Triangle with arrow keys");
CustomInit();
glutDisplayFunc(display);
glutSpecialFunc(handleKeyPress);
glutMainLoop();
return 0;
}