nuclear@40: #include nuclear@40: #include nuclear@40: #include "sgl.h" nuclear@40: nuclear@40: void disp(void); nuclear@40: void reshape(int x, int y); nuclear@40: void keyb(int key, int state); nuclear@40: void mouse(int pidx, int bn, int state, int x, int y); nuclear@40: void motion(int pidx, int x, int y); nuclear@40: nuclear@40: nuclear@40: int main(void) nuclear@40: { nuclear@40: if(sgl_init() == -1) { nuclear@40: return 1; nuclear@40: } nuclear@40: nuclear@40: sgl_create_window(640, 480, SGL_DOUBLE | SGL_DEPTH); nuclear@40: nuclear@40: sgl_display_callback(disp); nuclear@40: sgl_reshape_callback(reshape); nuclear@40: sgl_keyboard_callback(keyb); nuclear@40: sgl_mouse_callback(mouse); nuclear@40: sgl_motion_callback(motion); nuclear@40: nuclear@40: sgl_event_loop(); nuclear@40: sgl_quit(); nuclear@40: return 0; nuclear@40: } nuclear@40: nuclear@40: nuclear@40: void disp(void) nuclear@40: { nuclear@40: sgl_log("redisplay\n"); nuclear@40: nuclear@40: glClearColor(0.2, 0.2, 0.2, 1); nuclear@40: glClear(GL_COLOR_BUFFER_BIT); nuclear@40: nuclear@40: #ifndef GL_ES_VERSION_2_0 nuclear@40: glBegin(GL_QUADS); nuclear@40: glColor3f(1, 0, 0); nuclear@40: glVertex2f(-1, -1); nuclear@40: glColor3f(0, 1, 0); nuclear@40: glVertex2f(1, -1); nuclear@40: glColor3f(0, 0, 1); nuclear@40: glVertex2f(1, 1); nuclear@40: glColor3f(1, 1, 0); nuclear@40: glVertex2f(-1, 1); nuclear@40: glEnd(); nuclear@40: #endif nuclear@40: nuclear@40: sgl_swap_buffers(); nuclear@40: } nuclear@40: nuclear@40: void reshape(int x, int y) nuclear@40: { nuclear@40: printf("reshape: %dx%d\n", x, y); nuclear@40: glViewport(0, 0, x, y); nuclear@40: } nuclear@40: nuclear@40: void keyb(int key, int state) nuclear@40: { nuclear@40: char *ststr = state ? "pressed" : "released"; nuclear@40: nuclear@40: if(key < 0xff && isprint(key)) { nuclear@40: sgl_log("keyboard: '%c' %s\n", (char)key, ststr); nuclear@40: } else { nuclear@40: sgl_log("keyboard: %x %s\n", key, ststr); nuclear@40: } nuclear@40: nuclear@40: if(key == 27) { nuclear@40: sgl_quit(); nuclear@40: } nuclear@40: } nuclear@40: nuclear@40: void mouse(int pidx, int bn, int state, int x, int y) nuclear@40: { nuclear@40: printf("mouse: button%d %s (ptr: %d %d)\n", bn, state ? "pressed" : "released", x, y); nuclear@40: } nuclear@40: nuclear@40: void motion(int pidx, int x, int y) nuclear@40: { nuclear@40: printf("mouse dragged to: (%d %d)\n", x, y); nuclear@40: }