-
Notifications
You must be signed in to change notification settings - Fork 0
/
gl.c
104 lines (88 loc) · 1.58 KB
/
gl.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
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
98
99
100
101
102
103
#include <string.h>
#include <GL/glut.h>
#include <stdio.h>
#include <unistd.h>
#define COUNT (20 * 1024 * 1024)
unsigned char b[COUNT];
#define SCREEN 1920
int cpos = 0;
int zoom = 1;
void
tick(void)
{
glutPostRedisplay();
}
void
display(void)
{
int i = 0;
glClear(GL_COLOR_BUFFER_BIT);
glLineWidth(1.0);
glPointSize(1.0f);
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINE_STRIP);
glVertex3f(0.0, 540, 0.0);
for (i = 0; i < 2 * SCREEN; i += 2) {
glVertex3f(i / 2, (1000 - b[cpos + i * zoom] * 3), 0);
}
glEnd();
glutSwapBuffers();
}
void
reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, w, h, 0);
glMatrixMode(GL_MODELVIEW);
}
void
keyPressed (unsigned char key, int x, int y) {
if (key == '>') {
cpos += SCREEN * zoom;
if (cpos > COUNT - SCREEN * 2) {
cpos = COUNT - SCREEN * 2;
}
glutPostRedisplay();
}
if (key == '<') {
cpos -= SCREEN * zoom;
if (cpos < 0) {
cpos = 0;
}
glutPostRedisplay();
}
if (key == '+') {
zoom ++;
glutPostRedisplay();
}
if (key == '-') {
if (zoom > 1) {
zoom --;
}
glutPostRedisplay();
}
}
void
read_bytes()
{
int count = read(0, b, COUNT);
printf("read bytes: %d\n", count);
}
int
main(int argc, char **argv)
{
read_bytes();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(500, 150);
glutCreateWindow("GLUT DSO");
glClearColor(0.0, 0.0, 0.0, 1.0);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyPressed);
glutIdleFunc(tick);
glutMainLoop();
return 0;
}