aboutsummaryrefslogtreecommitdiff
path: root/src/display.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2022-08-31 12:31:38 +0300
committerkartofen <mladenovnasko0@gmail.com>2022-08-31 12:31:38 +0300
commit675ded0d66b9fd60777d3037ded1446a3f9ef986 (patch)
tree6db3f0524437304f9e5a7b90175e3f6b043d4d49 /src/display.c
Big Bang
Diffstat (limited to 'src/display.c')
-rw-r--r--src/display.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/display.c b/src/display.c
new file mode 100644
index 0000000..33131ef
--- /dev/null
+++ b/src/display.c
@@ -0,0 +1,53 @@
+#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();
+}