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
|
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <GL/glut.h>
#include "display.h"
#include "typedef.h"
unsigned char WIDTH = 1;
unsigned char HEIGHT = 1;
GLubyte pixels[BUF_CAP] = {0};
static int fd;
void pixel(int x, int y, char *buf)
{
int p = (y*WIDTH + x)*3;
int b = ((HEIGHT-1-y)*WIDTH+x)*3;
pixels[p+0] = buf[b+0];
pixels[p+1] = buf[b+1];
pixels[p+2] = buf[b+2];
}
void render()
{
read(fd, &WIDTH, sizeof(WIDTH));
read(fd, &HEIGHT, sizeof(HEIGHT));
char buf[BUF_CAP] = {0};
if(read(fd, buf, sizeof(buf)) != -1)
for(int i = 0; i < HEIGHT; i++)
for(int j = 0; j < WIDTH; j++)
pixel(j, i, buf);
glClear(GL_COLOR_BUFFER_BIT);
glDrawPixels(WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, pixels);
glutSwapBuffers();
glutReshapeWindow(WIDTH, HEIGHT);
glutPostRedisplay();
}
void display(int *argc, char **argv, int readfd)
{
glutInit(argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(69, 69);
glutCreateWindow(argv[0]);
fd = readfd;
glutDisplayFunc(render);
glutMainLoop();
puts("DISPLAY EXIT");
}
|