sgl

view tests/simple/simple.c @ 12:bf34fa677960

- fixed mac issues.
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 May 2011 12:02:22 +0300
parents 0cb438c86b98
children 25de96fb1526
line source
1 #include <stdio.h>
2 #include <ctype.h>
3 #ifndef __APPLE__
4 #include <GL/gl.h>
5 #else
6 #include <OpenGL/gl.h>
7 #endif
8 #include "sgl.h"
10 void disp(void);
11 void reshape(int x, int y);
12 void keyb(int key, int state);
13 void mouse(int pidx, int bn, int state, int x, int y);
14 void motion(int pidx, int x, int y);
17 int main(void)
18 {
19 if(sgl_init() == -1) {
20 return 1;
21 }
23 sgl_create_window(640, 480, SGL_DOUBLE | SGL_DEPTH);
25 sgl_display_callback(disp);
26 sgl_reshape_callback(reshape);
27 sgl_keyboard_callback(keyb);
28 sgl_mouse_callback(mouse);
29 sgl_motion_callback(motion);
31 sgl_event_loop();
32 sgl_quit();
33 return 0;
34 }
37 void disp(void)
38 {
39 printf("redisplay\n");
41 glClearColor(0.2, 0.2, 0.2, 1);
42 glClear(GL_COLOR_BUFFER_BIT);
44 glBegin(GL_QUADS);
45 glColor3f(1, 0, 0);
46 glVertex2f(-1, -1);
47 glColor3f(0, 1, 0);
48 glVertex2f(1, -1);
49 glColor3f(0, 0, 1);
50 glVertex2f(1, 1);
51 glColor3f(1, 1, 0);
52 glVertex2f(-1, 1);
53 glEnd();
55 sgl_swap_buffers();
56 }
58 void reshape(int x, int y)
59 {
60 printf("reshape: %dx%d\n", x, y);
61 glViewport(0, 0, x, y);
62 }
64 void keyb(int key, int state)
65 {
66 char *ststr = state ? "pressed" : "released";
68 if(key < 0xff && isprint(key)) {
69 printf("keyboard: '%c' %s\n", (char)key, ststr);
70 } else {
71 printf("keyboard: %x %s\n", key, ststr);
72 }
74 if(key == 27) {
75 sgl_quit();
76 }
77 }
79 void mouse(int pidx, int bn, int state, int x, int y)
80 {
81 printf("mouse: button%d %s (ptr: %d %d)\n", bn, state ? "pressed" : "released", x, y);
82 }
84 void motion(int pidx, int x, int y)
85 {
86 printf("mouse dragged to: (%d %d)\n", x, y);
87 }