#include #include #include #include #include "display.h" #include "typedef.h" #define MAX(x, y) (((x) > (y)) ? (x) : (y)) extern unsigned char *cam_data; unsigned char WIDTH = 1; unsigned char HEIGHT = 1; GLubyte pixels[BUF_CAP] = {0}; 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() { WIDTH = MAX(cam_data[0], 1); HEIGHT = MAX(cam_data[1], 1); for(int i = 0; i < HEIGHT; i++) for(int j = 0; j < WIDTH; j++) pixel(j, i, &(cam_data[2])); 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) { glutInit(argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(69, 69); glutCreateWindow(argv[0]); glutDisplayFunc(render); glutMainLoop(); }