7 static void display(void);
8 static void reshape(int x, int y);
9 static void keyb(unsigned char key, int x, int y);
10 static void mouse(int bn, int st, int x, int y);
11 static void motion(int x, int y);
13 static int win_width, win_height;
14 static float win_aspect;
15 static int reshape_pending;
17 static struct erb_rend *erb;
19 static int mouse_x, mouse_y;
20 static int drag_x, drag_y;
23 static float disp_gamma = 2.2f;
25 static unsigned int fbtex;
26 static unsigned int sdr;
28 static const char *vs_src =
31 " gl_Position = ftransform();\n"
32 " gl_TexCoord[0] = gl_MultiTexCoord0;\n"
35 static const char *ps_src =
36 "uniform sampler2D tex;\n"
37 "uniform float inv_gamma;\n"
41 " vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n"
42 " gl_FragColor.rgb = pow(texel.xyz / texel.w, vec3(inv_gamma));\n"
43 " gl_FragColor.a = 1.0;\n"
47 int main(int argc, char **argv)
51 glutInit(&argc, argv);
52 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
53 glutInitWindowSize(1280, 800);
54 glutCreateWindow("X erebus");
56 glutDisplayFunc(display);
57 glutReshapeFunc(reshape);
58 glutKeyboardFunc(keyb);
60 glutMotionFunc(motion);
62 if(!(vs = create_vertex_shader(vs_src))) {
65 if(!(ps = create_pixel_shader(ps_src))) {
68 if(!(sdr = create_program_link(vs, ps, 0))) {
71 set_uniform_float(sdr, "inv_gamma", 1.0f / disp_gamma);
73 if(!(erb = erb_create())) {
78 glGenTextures(1, &fbtex);
79 glBindTexture(GL_TEXTURE_2D, fbtex);
80 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
81 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
88 static void display(void)
93 erb_allocframe(erb, win_width, win_height);
96 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, win_width, win_height, 0,
97 GL_RGBA, GL_FLOAT, erb_getframe(erb));
99 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, win_width, win_height,
100 GL_RGBA, GL_FLOAT, erb_getframe(erb));
102 /* TODO: continue with getting notified when a block is done rendering */
105 glClear(GL_COLOR_BUFFER_BIT);
114 glVertex2f(win_width, 0);
116 glVertex2f(win_width, win_height);
118 glVertex2f(0, win_height);
124 glEnable(GL_LOGIC_OP);
127 glBegin(GL_LINE_LOOP);
129 glVertex2f(drag_x, drag_y);
130 glVertex2f(mouse_x, drag_y);
131 glVertex2f(mouse_x, mouse_y);
132 glVertex2f(drag_x, mouse_y);
135 glDisable(GL_LOGIC_OP);
141 static void reshape(int x, int y)
145 win_aspect = (float)x / (float)y;
147 glViewport(0, 0, x, y);
149 glMatrixMode(GL_PROJECTION);
151 glOrtho(0, x, y, 0, -1, 1);
157 static void keyb(unsigned char key, int x, int y)
165 static void mouse(int bn, int st, int x, int y)
173 if(st == GLUT_DOWN) {
180 rect[0] = x < drag_x ? x : drag_x;
181 rect[1] = y < drag_y ? y : drag_y;
182 rect[2] = abs(x - drag_x);
183 rect[3] = abs(y - drag_y);
185 erb_queue_block(erb, rect[0], rect[1], rect[2], rect[3]);
186 printf("rect: %d,%d %dx%d\n", rect[0], rect[1], rect[2], rect[3]);
193 static void motion(int x, int y)