sgl
view isimple/isimple.c @ 40:f7de32814f34
sortof made the ios backend to compile and run ... sortof
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 28 Jun 2012 03:42:26 +0300 |
parents | |
children |
line source
1 #include <stdio.h>
2 #include <ctype.h>
3 #include "sgl.h"
5 void disp(void);
6 void reshape(int x, int y);
7 void keyb(int key, int state);
8 void mouse(int pidx, int bn, int state, int x, int y);
9 void motion(int pidx, int x, int y);
12 int main(void)
13 {
14 if(sgl_init() == -1) {
15 return 1;
16 }
18 sgl_create_window(640, 480, SGL_DOUBLE | SGL_DEPTH);
20 sgl_display_callback(disp);
21 sgl_reshape_callback(reshape);
22 sgl_keyboard_callback(keyb);
23 sgl_mouse_callback(mouse);
24 sgl_motion_callback(motion);
26 sgl_event_loop();
27 sgl_quit();
28 return 0;
29 }
32 void disp(void)
33 {
34 sgl_log("redisplay\n");
36 glClearColor(0.2, 0.2, 0.2, 1);
37 glClear(GL_COLOR_BUFFER_BIT);
39 #ifndef GL_ES_VERSION_2_0
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();
50 #endif
52 sgl_swap_buffers();
53 }
55 void reshape(int x, int y)
56 {
57 printf("reshape: %dx%d\n", x, y);
58 glViewport(0, 0, x, y);
59 }
61 void keyb(int key, int state)
62 {
63 char *ststr = state ? "pressed" : "released";
65 if(key < 0xff && isprint(key)) {
66 sgl_log("keyboard: '%c' %s\n", (char)key, ststr);
67 } else {
68 sgl_log("keyboard: %x %s\n", key, ststr);
69 }
71 if(key == 27) {
72 sgl_quit();
73 }
74 }
76 void mouse(int pidx, int bn, int state, int x, int y)
77 {
78 printf("mouse: button%d %s (ptr: %d %d)\n", bn, state ? "pressed" : "released", x, y);
79 }
81 void motion(int pidx, int x, int y)
82 {
83 printf("mouse dragged to: (%d %d)\n", x, y);
84 }