6 static void display(void);
7 static void reshape(int x, int y);
8 static void keypress(unsigned char key, int x, int y);
9 static void keyrelease(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 gfx_newcol(int r, int g, int b);
14 static void gfx_color(int c);
15 static void gfx_fillrect(struct wt_rect *r);
16 static void gfx_line(int x0, int y0, int x1, int y1);
18 static struct wt_graphics gfx = {
20 gfx_newcol, gfx_color,
25 int main(int argc, char **argv)
27 glutInit(&argc, argv);
28 glutInitWindowSize(800, 600);
29 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
30 glutCreateWindow("windtk example");
32 glutDisplayFunc(display);
33 glutReshapeFunc(reshape);
34 glutKeyboardFunc(keypress);
35 glutKeyboardUpFunc(keyrelease);
37 glutMotionFunc(motion);
38 glutPassiveMotionFunc(motion);
40 glClearColor(0.6, 0.6, 0.6, 1);
42 if(wt_init(800, 600, &gfx) == -1) {
45 wt_window(0, "foo", WT_WS_DEFAULT, 100, 100, 200, 200);
51 static void display(void)
53 glClear(GL_COLOR_BUFFER_BIT);
60 static void reshape(int x, int y)
62 glViewport(0, 0, x, y);
63 glMatrixMode(GL_PROJECTION);
65 glOrtho(0, x, y, 0, -1, 1);
67 wt_viewport(0, 0, x, y);
70 static void keypress(unsigned char key, int x, int y)
72 if(key == 27) exit(0);
77 static void keyrelease(unsigned char key, int x, int y)
82 static void mouse(int bn, int st, int x, int y)
84 wt_inp_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
87 static void motion(int x, int y)
92 /* ------ graphics callbacks -------- */
93 static unsigned char colors[32][3];
96 static int gfx_newcol(int r, int g, int b)
100 for(i=0; i<maxcol; i++) {
101 if(colors[i][0] == r && colors[i][1] == g && colors[i][2] == b) {
106 if(maxcol >= 32) return -1;
108 colors[maxcol][0] = r;
109 colors[maxcol][1] = g;
110 colors[maxcol][2] = b;
114 static void gfx_color(int c)
116 glColor3ubv(colors[c]);
119 static void gfx_fillrect(struct wt_rect *r)
122 glVertex2f(r->x, r->y);
123 glVertex2f(r->x + r->w, r->y);
124 glVertex2f(r->x + r->w, r->y + r->h);
125 glVertex2f(r->x, r->y + r->h);
129 static void gfx_line(int x0, int y0, int x1, int y1)