sgl
view tests/simple/simple.c @ 5:0570e27e5ebc
pretty much done with the basic functionality and GLX shit
author | John Tsiombikas <nuclear@siggraph.org> |
---|---|
date | Fri, 13 May 2011 07:49:47 +0300 |
parents | |
children | 0cb438c86b98 |
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 bn, int state, int x, int y);
10 void motion(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_set_callback(SGL_DISPLAY, disp);
22 sgl_set_callback(SGL_RESHAPE, reshape);
23 sgl_set_callback(SGL_KEYBOARD, keyb);
24 sgl_set_callback(SGL_MOUSE, mouse);
25 sgl_set_callback(SGL_MOTION, 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 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 x, int y)
81 {
82 printf("mouse dragged to: (%d %d)\n", x, y);
83 }