sgl

view tests/simple/simple.c @ 30:6242b03e7191

merged with win32 branch
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 28 Jun 2011 13:52:02 +0300
parents bf34fa677960
children 124195562f7e
line source
1 #include <stdio.h>
2 #include <ctype.h>
3 #ifdef WIN32
4 #include <windows.h>
5 #endif /* WIN32 */
6 #ifndef __APPLE__
7 #include <GL/gl.h>
8 #else
9 #include <OpenGL/gl.h>
10 #endif
11 #include "sgl.h"
13 void disp(void);
14 void reshape(int x, int y);
15 void keyb(int key, int state);
16 void mouse(int pidx, int bn, int state, int x, int y);
17 void motion(int pidx, int x, int y);
20 int main(void)
21 {
22 if(sgl_init() == -1) {
23 return 1;
24 }
26 sgl_create_window(640, 480, SGL_DOUBLE | SGL_DEPTH);
28 sgl_display_callback(disp);
29 sgl_reshape_callback(reshape);
30 sgl_keyboard_callback(keyb);
31 sgl_mouse_callback(mouse);
32 sgl_motion_callback(motion);
34 sgl_event_loop();
35 sgl_quit();
36 return 0;
37 }
40 void disp(void)
41 {
42 printf("redisplay\n");
44 glClearColor(0.2, 0.2, 0.2, 1);
45 glClear(GL_COLOR_BUFFER_BIT);
47 glBegin(GL_QUADS);
48 glColor3f(1, 0, 0);
49 glVertex2f(-1, -1);
50 glColor3f(0, 1, 0);
51 glVertex2f(1, -1);
52 glColor3f(0, 0, 1);
53 glVertex2f(1, 1);
54 glColor3f(1, 1, 0);
55 glVertex2f(-1, 1);
56 glEnd();
58 sgl_swap_buffers();
59 }
61 void reshape(int x, int y)
62 {
63 printf("reshape: %dx%d\n", x, y);
64 glViewport(0, 0, x, y);
65 }
67 void keyb(int key, int state)
68 {
69 char *ststr = state ? "pressed" : "released";
71 if(key < 0xff && isprint(key)) {
72 printf("keyboard: '%c' %s\n", (char)key, ststr);
73 } else {
74 printf("keyboard: %x %s\n", key, ststr);
75 }
77 if(key == 27) {
78 sgl_quit();
79 }
80 }
82 void mouse(int pidx, int bn, int state, int x, int y)
83 {
84 printf("mouse: button%d %s (ptr: %d %d)\n", bn, state ? "pressed" : "released", x, y);
85 }
87 void motion(int pidx, int x, int y)
88 {
89 printf("mouse dragged to: (%d %d)\n", x, y);
90 }