+
+static void jobdone(unsigned int job, struct erb_rect *rect, void *cls)
+{
+ write(pfd[1], rect, sizeof *rect);
+}
+
+static void display(void)
+{
+ if(reshape_pending) {
+ reshape_pending = 0;
+
+ erb_allocframe(erb, win_width, win_height);
+ erb_begin(erb);
+
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, win_width);
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, win_width, win_height, 0,
+ GL_RGBA, GL_FLOAT, erb_getframe(erb));
+ }
+
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glUseProgram(sdr);
+
+ glBegin(GL_QUADS);
+ glColor3f(1, 1, 1);
+ glTexCoord2f(0, 0);
+ glVertex2f(0, 0);
+ glTexCoord2f(1, 0);
+ glVertex2f(win_width, 0);
+ glTexCoord2f(1, 1);
+ glVertex2f(win_width, win_height);
+ glTexCoord2f(0, 1);
+ glVertex2f(0, win_height);
+ glEnd();
+
+ if(drag) {
+ glUseProgram(0);
+
+ glEnable(GL_LOGIC_OP);
+ glLogicOp(GL_XOR);
+
+ glBegin(GL_LINE_LOOP);
+ glColor3f(1, 1, 1);
+ glVertex2f(drag_x, drag_y);
+ glVertex2f(mouse_x, drag_y);
+ glVertex2f(mouse_x, mouse_y);
+ glVertex2f(drag_x, mouse_y);
+ glEnd();
+
+ glDisable(GL_LOGIC_OP);
+ }
+
+ glutSwapBuffers();
+}
+
+static void reshape(int x, int y)
+{
+ win_width = x;
+ win_height = y;
+ win_aspect = (float)x / (float)y;
+
+ glViewport(0, 0, x, y);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0, x, y, 0, -1, 1);
+
+ reshape_pending = 1;
+ post_redisplay();
+}
+
+static void keyb(unsigned char key, int x, int y)
+{
+ if(key == 27) {
+ glutExit();
+ quit = 1;
+ }
+ post_redisplay();
+}
+
+static void mouse(int bn, int st, int x, int y)
+{
+ int rect[4];
+
+ mouse_x = x;
+ mouse_y = y;
+
+ if(bn == 0) {
+ if(st == GLUT_DOWN) {
+ drag = 1;
+ drag_x = x;
+ drag_y = y;
+ } else {
+ if(drag) {
+ drag = 0;
+
+ rect[0] = x < drag_x ? x : drag_x;
+ rect[1] = y < drag_y ? y : drag_y;
+ rect[2] = abs(x - drag_x);
+ rect[3] = abs(y - drag_y);
+
+ erb_queue_block(erb, 0, rect[0], rect[1], rect[2], rect[3]);
+ printf("rect: %d,%d %dx%d\n", rect[0], rect[1], rect[2], rect[3]);
+ }
+ }
+
+ post_redisplay();
+ }
+ if(bn == 2 && st == GLUT_DOWN) {
+ drag = 0;
+ post_redisplay();
+ }
+}
+
+static void motion(int x, int y)
+{
+ mouse_x = x;
+ mouse_y = y;
+
+ post_redisplay();
+}