5 static void display(void);
6 static void reshape(int x, int y);
7 static void keyb(unsigned char key, int x, int y);
8 static void mouse(int bn, int st, int x, int y);
9 static void motion(int x, int y);
11 static int win_width, win_height;
12 static float win_aspect;
13 static int reshape_pending;
15 static struct erb_rend *erb;
17 static int mouse_x, mouse_y;
18 static int drag_x, drag_y;
21 static unsigned int fbtex;
23 int main(int argc, char **argv)
25 glutInit(&argc, argv);
26 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
27 glutInitWindowSize(1280, 800);
28 glutCreateWindow("X erebus");
30 glutDisplayFunc(display);
31 glutReshapeFunc(reshape);
32 glutKeyboardFunc(keyb);
34 glutMotionFunc(motion);
36 if(!(erb = erb_create())) {
41 glGenTextures(1, &fbtex);
42 glBindTexture(GL_TEXTURE_2D, fbtex);
43 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
44 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
45 glEnable(GL_TEXTURE_2D);
52 static void display(void)
57 erb_allocframe(erb, win_width, win_height);
60 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, win_width, win_height, 0,
61 GL_RGBA, GL_FLOAT, erb_getframe(erb));
63 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, win_width, win_height,
64 GL_RGBA, GL_FLOAT, erb_getframe(erb));
66 /* TODO: continue with getting notified when a block is done rendering */
69 glClear(GL_COLOR_BUFFER_BIT);
76 glVertex2f(win_width, 0);
78 glVertex2f(win_width, win_height);
80 glVertex2f(0, win_height);
84 glPushAttrib(GL_ENABLE_BIT);
85 glDisable(GL_TEXTURE_2D);
86 glEnable(GL_LOGIC_OP);
89 glBegin(GL_LINE_LOOP);
91 glVertex2f(drag_x, drag_y);
92 glVertex2f(mouse_x, drag_y);
93 glVertex2f(mouse_x, mouse_y);
94 glVertex2f(drag_x, mouse_y);
103 static void reshape(int x, int y)
107 win_aspect = (float)x / (float)y;
109 glViewport(0, 0, x, y);
111 glMatrixMode(GL_PROJECTION);
113 glOrtho(0, x, y, 0, -1, 1);
119 static void keyb(unsigned char key, int x, int y)
127 static void mouse(int bn, int st, int x, int y)
135 if(st == GLUT_DOWN) {
142 rect[0] = x < drag_x ? x : drag_x;
143 rect[1] = y < drag_y ? y : drag_y;
144 rect[2] = abs(x - drag_x);
145 rect[3] = abs(y - drag_y);
147 erb_queue_block(erb, rect[0], rect[1], rect[2], rect[3]);
148 printf("rect: %d,%d %dx%d\n", rect[0], rect[1], rect[2], rect[3]);
155 static void motion(int x, int y)