sgl

annotate 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
rev   line source
nuclear@40 1 #include <stdio.h>
nuclear@40 2 #include <ctype.h>
nuclear@40 3 #include "sgl.h"
nuclear@40 4
nuclear@40 5 void disp(void);
nuclear@40 6 void reshape(int x, int y);
nuclear@40 7 void keyb(int key, int state);
nuclear@40 8 void mouse(int pidx, int bn, int state, int x, int y);
nuclear@40 9 void motion(int pidx, int x, int y);
nuclear@40 10
nuclear@40 11
nuclear@40 12 int main(void)
nuclear@40 13 {
nuclear@40 14 if(sgl_init() == -1) {
nuclear@40 15 return 1;
nuclear@40 16 }
nuclear@40 17
nuclear@40 18 sgl_create_window(640, 480, SGL_DOUBLE | SGL_DEPTH);
nuclear@40 19
nuclear@40 20 sgl_display_callback(disp);
nuclear@40 21 sgl_reshape_callback(reshape);
nuclear@40 22 sgl_keyboard_callback(keyb);
nuclear@40 23 sgl_mouse_callback(mouse);
nuclear@40 24 sgl_motion_callback(motion);
nuclear@40 25
nuclear@40 26 sgl_event_loop();
nuclear@40 27 sgl_quit();
nuclear@40 28 return 0;
nuclear@40 29 }
nuclear@40 30
nuclear@40 31
nuclear@40 32 void disp(void)
nuclear@40 33 {
nuclear@40 34 sgl_log("redisplay\n");
nuclear@40 35
nuclear@40 36 glClearColor(0.2, 0.2, 0.2, 1);
nuclear@40 37 glClear(GL_COLOR_BUFFER_BIT);
nuclear@40 38
nuclear@40 39 #ifndef GL_ES_VERSION_2_0
nuclear@40 40 glBegin(GL_QUADS);
nuclear@40 41 glColor3f(1, 0, 0);
nuclear@40 42 glVertex2f(-1, -1);
nuclear@40 43 glColor3f(0, 1, 0);
nuclear@40 44 glVertex2f(1, -1);
nuclear@40 45 glColor3f(0, 0, 1);
nuclear@40 46 glVertex2f(1, 1);
nuclear@40 47 glColor3f(1, 1, 0);
nuclear@40 48 glVertex2f(-1, 1);
nuclear@40 49 glEnd();
nuclear@40 50 #endif
nuclear@40 51
nuclear@40 52 sgl_swap_buffers();
nuclear@40 53 }
nuclear@40 54
nuclear@40 55 void reshape(int x, int y)
nuclear@40 56 {
nuclear@40 57 printf("reshape: %dx%d\n", x, y);
nuclear@40 58 glViewport(0, 0, x, y);
nuclear@40 59 }
nuclear@40 60
nuclear@40 61 void keyb(int key, int state)
nuclear@40 62 {
nuclear@40 63 char *ststr = state ? "pressed" : "released";
nuclear@40 64
nuclear@40 65 if(key < 0xff && isprint(key)) {
nuclear@40 66 sgl_log("keyboard: '%c' %s\n", (char)key, ststr);
nuclear@40 67 } else {
nuclear@40 68 sgl_log("keyboard: %x %s\n", key, ststr);
nuclear@40 69 }
nuclear@40 70
nuclear@40 71 if(key == 27) {
nuclear@40 72 sgl_quit();
nuclear@40 73 }
nuclear@40 74 }
nuclear@40 75
nuclear@40 76 void mouse(int pidx, int bn, int state, int x, int y)
nuclear@40 77 {
nuclear@40 78 printf("mouse: button%d %s (ptr: %d %d)\n", bn, state ? "pressed" : "released", x, y);
nuclear@40 79 }
nuclear@40 80
nuclear@40 81 void motion(int pidx, int x, int y)
nuclear@40 82 {
nuclear@40 83 printf("mouse dragged to: (%d %d)\n", x, y);
nuclear@40 84 }