rev |
line source |
nuclear@5
|
1 #include <stdio.h>
|
nuclear@5
|
2 #include <ctype.h>
|
nuclear@5
|
3 #include <GL/gl.h>
|
nuclear@5
|
4 #include "sgl.h"
|
nuclear@5
|
5
|
nuclear@5
|
6 void disp(void);
|
nuclear@5
|
7 void reshape(int x, int y);
|
nuclear@5
|
8 void keyb(int key, int state);
|
nuclear@6
|
9 void mouse(int pidx, int bn, int state, int x, int y);
|
nuclear@6
|
10 void motion(int pidx, int x, int y);
|
nuclear@5
|
11
|
nuclear@5
|
12
|
nuclear@5
|
13 int main(void)
|
nuclear@5
|
14 {
|
nuclear@5
|
15 if(sgl_init() == -1) {
|
nuclear@5
|
16 return 1;
|
nuclear@5
|
17 }
|
nuclear@5
|
18
|
nuclear@5
|
19 sgl_create_window(640, 480, SGL_DOUBLE | SGL_DEPTH);
|
nuclear@5
|
20
|
nuclear@6
|
21 sgl_display_callback(disp);
|
nuclear@6
|
22 sgl_reshape_callback(reshape);
|
nuclear@6
|
23 sgl_keyboard_callback(keyb);
|
nuclear@6
|
24 sgl_mouse_callback(mouse);
|
nuclear@6
|
25 sgl_motion_callback(motion);
|
nuclear@5
|
26
|
nuclear@5
|
27 sgl_event_loop();
|
nuclear@5
|
28 sgl_quit();
|
nuclear@5
|
29 return 0;
|
nuclear@5
|
30 }
|
nuclear@5
|
31
|
nuclear@5
|
32
|
nuclear@5
|
33 void disp(void)
|
nuclear@5
|
34 {
|
nuclear@5
|
35 printf("redisplay\n");
|
nuclear@5
|
36
|
nuclear@5
|
37 glClearColor(0.2, 0.2, 0.2, 1);
|
nuclear@5
|
38 glClear(GL_COLOR_BUFFER_BIT);
|
nuclear@5
|
39
|
nuclear@5
|
40 glBegin(GL_QUADS);
|
nuclear@5
|
41 glColor3f(1, 0, 0);
|
nuclear@5
|
42 glVertex2f(-1, -1);
|
nuclear@5
|
43 glColor3f(0, 1, 0);
|
nuclear@5
|
44 glVertex2f(1, -1);
|
nuclear@5
|
45 glColor3f(0, 0, 1);
|
nuclear@5
|
46 glVertex2f(1, 1);
|
nuclear@5
|
47 glColor3f(1, 1, 0);
|
nuclear@5
|
48 glVertex2f(-1, 1);
|
nuclear@5
|
49 glEnd();
|
nuclear@5
|
50
|
nuclear@5
|
51 sgl_swap_buffers();
|
nuclear@5
|
52 }
|
nuclear@5
|
53
|
nuclear@5
|
54 void reshape(int x, int y)
|
nuclear@5
|
55 {
|
nuclear@5
|
56 printf("reshape: %dx%d\n", x, y);
|
nuclear@5
|
57 glViewport(0, 0, x, y);
|
nuclear@5
|
58 }
|
nuclear@5
|
59
|
nuclear@5
|
60 void keyb(int key, int state)
|
nuclear@5
|
61 {
|
nuclear@5
|
62 char *ststr = state ? "pressed" : "released";
|
nuclear@5
|
63
|
nuclear@5
|
64 if(key < 0xff && isprint(key)) {
|
nuclear@5
|
65 printf("keyboard: '%c' %s\n", (char)key, ststr);
|
nuclear@5
|
66 } else {
|
nuclear@5
|
67 printf("keyboard: %x %s\n", key, ststr);
|
nuclear@5
|
68 }
|
nuclear@5
|
69
|
nuclear@5
|
70 if(key == 27) {
|
nuclear@5
|
71 sgl_quit();
|
nuclear@5
|
72 }
|
nuclear@5
|
73 }
|
nuclear@5
|
74
|
nuclear@6
|
75 void mouse(int pidx, int bn, int state, int x, int y)
|
nuclear@5
|
76 {
|
nuclear@5
|
77 printf("mouse: button%d %s (ptr: %d %d)\n", bn, state ? "pressed" : "released", x, y);
|
nuclear@5
|
78 }
|
nuclear@5
|
79
|
nuclear@6
|
80 void motion(int pidx, int x, int y)
|
nuclear@5
|
81 {
|
nuclear@5
|
82 printf("mouse dragged to: (%d %d)\n", x, y);
|
nuclear@5
|
83 }
|