aboutsummaryrefslogtreecommitdiff
path: root/src/display.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/display.c')
-rw-r--r--src/display.c81
1 files changed, 56 insertions, 25 deletions
diff --git a/src/display.c b/src/display.c
index 6d4c55a..a09cc46 100644
--- a/src/display.c
+++ b/src/display.c
@@ -1,15 +1,24 @@
#include <stdio.h>
-#include <unistd.h>
#include <string.h>
-#include <GL/glut.h>
-#include "display.h"
+#include <GLFW/glfw3.h>
#include "typedef.h"
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
-extern unsigned char *cam_data;
+static void error_callback(int error, const char* description)
+{
+ err("display: %s\n", description);
+}
+
+static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
+{
+ if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
+ glfwSetWindowShouldClose(window, GLFW_TRUE);
+}
+
+extern unsigned char cam_data[];
-unsigned char WIDTH = 1;
+unsigned char WIDTH = 1;
unsigned char HEIGHT = 1;
GLubyte pixels[BUF_CAP] = {0};
@@ -22,30 +31,52 @@ void pixel(int x, int y, char *buf)
pixels[p+2] = buf[b+2];
}
-void render()
+int display(void)
{
- WIDTH = MAX(cam_data[0], 1);
- HEIGHT = MAX(cam_data[1], 1);
+ GLFWwindow* window;
+ glfwSetErrorCallback(error_callback);
- for(int i = 0; i < HEIGHT; i++)
- for(int j = 0; j < WIDTH; j++)
- pixel(j, i, &(cam_data[2]));
+ if (!glfwInit()) {
+ return 1;
+ }
- glClear(GL_COLOR_BUFFER_BIT);
- glDrawPixels(WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, pixels);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
- glutSwapBuffers();
- glutReshapeWindow(WIDTH, HEIGHT);
- glutPostRedisplay();
-}
+ window = glfwCreateWindow(WIDTH, HEIGHT, "Client", NULL, NULL);
+ if (!window) {
+ glfwTerminate();
+ return 1;
+ }
-void display(int *argc, char **argv)
-{
- glutInit(argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(69, 69);
- glutCreateWindow(argv[0]);
+ glfwSetKeyCallback(window, key_callback);
+ glfwMakeContextCurrent(window);
+ glfwSwapInterval(1);
+
+
+ unsigned char *copy_cam_data;
+ while (!glfwWindowShouldClose(window))
+ {
+ // memcpy(copy_cam_data, cam_data, BUF_CAP);
+ copy_cam_data = cam_data;
+
+ WIDTH = MAX(copy_cam_data[0], 1);
+ HEIGHT = MAX(copy_cam_data[1], 1);
+ glfwSetWindowSize(window, WIDTH, HEIGHT);
+
+ for(int i = 0; i < HEIGHT; i++)
+ for(int j = 0; j < WIDTH; j++)
+ pixel(j, i, &(copy_cam_data[2]));
+
+ glClear(GL_COLOR_BUFFER_BIT);
+ glDrawPixels(WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, pixels);
+
+ glfwSwapBuffers(window);
+ glfwPollEvents();
+ }
+
+ glfwDestroyWindow(window);
+ glfwTerminate();
- glutDisplayFunc(render);
- glutMainLoop();
+ return 0;
}