#include #include #include #include "typedef.h" #define MAX(x, y) (((x) > (y)) ? (x) : (y)) 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[]; extern unsigned int WIDTH; extern unsigned int HEIGHT; GLubyte pixels[BUF_CAP] = {0}; void pixel(int x, int y) { // for rotating the screen int p = (y*WIDTH + x)*3; int b = ((HEIGHT-1-y)*WIDTH+x)*3; pixels[p+0] = cam_data[b+0]; pixels[p+1] = cam_data[b+1]; pixels[p+2] = cam_data[b+2]; } int display(void) { GLFWwindow* window; glfwSetErrorCallback(error_callback); if (!glfwInit()) { return 1; } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); window = glfwCreateWindow(WIDTH, HEIGHT, "Client", NULL, NULL); if (!window) { glfwTerminate(); return 1; } glfwSetKeyCallback(window, key_callback); glfwMakeContextCurrent(window); glfwSwapInterval(1); while (!glfwWindowShouldClose(window)) { glfwSetWindowSize(window, WIDTH, HEIGHT); for(int i = 0; i < HEIGHT; i++) for(int j = 0; j < WIDTH; j++) pixel(j, i); glClear(GL_COLOR_BUFFER_BIT); glDrawPixels(WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, pixels); glfwSwapBuffers(window); glfwPollEvents(); } glfwDestroyWindow(window); glfwTerminate(); return 0; }