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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#include <stdio.h>
#include <string.h>
#include <GLFW/glfw3.h>
#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[];
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];
}
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);
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();
return 0;
}
|