sgl
view tests/simple/simple.c @ 9:5efd62ff354a
- configure now also heeds mac-framework: options in modules
- cleaned up the generated module.c a bit
author | John Tsiombikas <nuclear@siggraph.org> |
---|---|
date | Sat, 14 May 2011 08:58:49 +0300 |
parents | 0570e27e5ebc |
children | bf34fa677960 |
line source
1 #include <stdio.h>
2 #include <ctype.h>
3 #include <GL/gl.h>
4 #include "sgl.h"
6 void disp(void);
7 void reshape(int x, int y);
8 void keyb(int key, int state);
9 void mouse(int pidx, int bn, int state, int x, int y);
10 void motion(int pidx, int x, int y);
13 int main(void)
14 {
15 if(sgl_init() == -1) {
16 return 1;
17 }
19 sgl_create_window(640, 480, SGL_DOUBLE | SGL_DEPTH);
21 sgl_display_callback(disp);
22 sgl_reshape_callback(reshape);
23 sgl_keyboard_callback(keyb);
24 sgl_mouse_callback(mouse);
25 sgl_motion_callback(motion);
27 sgl_event_loop();
28 sgl_quit();
29 return 0;
30 }
33 void disp(void)
34 {
35 printf("redisplay\n");
37 glClearColor(0.2, 0.2, 0.2, 1);
38 glClear(GL_COLOR_BUFFER_BIT);
40 glBegin(GL_QUADS);
41 glColor3f(1, 0, 0);
42 glVertex2f(-1, -1);
43 glColor3f(0, 1, 0);
44 glVertex2f(1, -1);
45 glColor3f(0, 0, 1);
46 glVertex2f(1, 1);
47 glColor3f(1, 1, 0);
48 glVertex2f(-1, 1);
49 glEnd();
51 sgl_swap_buffers();
52 }
54 void reshape(int x, int y)
55 {
56 printf("reshape: %dx%d\n", x, y);
57 glViewport(0, 0, x, y);
58 }
60 void keyb(int key, int state)
61 {
62 char *ststr = state ? "pressed" : "released";
64 if(key < 0xff && isprint(key)) {
65 printf("keyboard: '%c' %s\n", (char)key, ststr);
66 } else {
67 printf("keyboard: %x %s\n", key, ststr);
68 }
70 if(key == 27) {
71 sgl_quit();
72 }
73 }
75 void mouse(int pidx, int bn, int state, int x, int y)
76 {
77 printf("mouse: button%d %s (ptr: %d %d)\n", bn, state ? "pressed" : "released", x, y);
78 }
80 void motion(int pidx, int x, int y)
81 {
82 printf("mouse dragged to: (%d %d)\n", x, y);
83 }