-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboardEvent.c
61 lines (55 loc) · 1.34 KB
/
keyboardEvent.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
59
60
61
#include <GL/freeglut.h>
#include <GL/gl.h>
#include <stdio.h>
GLfloat r=0.0,g = 0.0,b = 0.0,a =0.0;
void MyKeyboardFunc(unsigned char Key, int x, int y);
void renderFunction()
{
int i=0;
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 1.0);
glPointSize(5) ;
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("OpenGL - First window demo");
//Registering a keyboard event callback.
//MyKeyboardFunc will now get called on any key board button press.
glutKeyboardFunc(MyKeyboardFunc);
glutDisplayFunc(renderFunction);
glutMainLoop();
return 0;
}
void MyKeyboardFunc(unsigned char Key, int x, int y)
{
//Key contains the character we pressed
//x and y contains the coordinates of the button cursor when the keyboard key was pressed
switch(Key)
{
case 'r':
r = 1.0;g = 0.0;b = 0.0;a = 1.0;
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
break;
case 'g':
r = 0.0;g = 1.0;b = 0.0;a = 1.0;
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
break;
case 'y':
r = 1.0;g = 1.0;b = 0.0;a = 1.0;
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
break;
default: break;
};
}