sgl

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/isimple/isimple.c	Thu Jun 28 03:42:26 2012 +0300
     1.3 @@ -0,0 +1,84 @@
     1.4 +#include <stdio.h>
     1.5 +#include <ctype.h>
     1.6 +#include "sgl.h"
     1.7 +
     1.8 +void disp(void);
     1.9 +void reshape(int x, int y);
    1.10 +void keyb(int key, int state);
    1.11 +void mouse(int pidx, int bn, int state, int x, int y);
    1.12 +void motion(int pidx, int x, int y);
    1.13 +
    1.14 +
    1.15 +int main(void)
    1.16 +{
    1.17 +	if(sgl_init() == -1) {
    1.18 +		return 1;
    1.19 +	}
    1.20 +	
    1.21 +	sgl_create_window(640, 480, SGL_DOUBLE | SGL_DEPTH);
    1.22 +	
    1.23 +	sgl_display_callback(disp);
    1.24 +	sgl_reshape_callback(reshape);
    1.25 +	sgl_keyboard_callback(keyb);
    1.26 +	sgl_mouse_callback(mouse);
    1.27 +	sgl_motion_callback(motion);
    1.28 +	
    1.29 +	sgl_event_loop();
    1.30 +	sgl_quit();
    1.31 +	return 0;
    1.32 +}
    1.33 +
    1.34 +
    1.35 +void disp(void)
    1.36 +{
    1.37 +	sgl_log("redisplay\n");
    1.38 +	
    1.39 +	glClearColor(0.2, 0.2, 0.2, 1);
    1.40 +	glClear(GL_COLOR_BUFFER_BIT);
    1.41 +	
    1.42 +#ifndef GL_ES_VERSION_2_0
    1.43 +	glBegin(GL_QUADS);
    1.44 +	glColor3f(1, 0, 0);
    1.45 +	glVertex2f(-1, -1);
    1.46 +	glColor3f(0, 1, 0);
    1.47 +	glVertex2f(1, -1);
    1.48 +	glColor3f(0, 0, 1);
    1.49 +	glVertex2f(1, 1);
    1.50 +	glColor3f(1, 1, 0);
    1.51 +	glVertex2f(-1, 1);
    1.52 +	glEnd();
    1.53 +#endif
    1.54 +	
    1.55 +	sgl_swap_buffers();
    1.56 +}
    1.57 +
    1.58 +void reshape(int x, int y)
    1.59 +{
    1.60 +	printf("reshape: %dx%d\n", x, y);
    1.61 +	glViewport(0, 0, x, y);
    1.62 +}
    1.63 +
    1.64 +void keyb(int key, int state)
    1.65 +{
    1.66 +	char *ststr = state ? "pressed" : "released";
    1.67 +	
    1.68 +	if(key < 0xff && isprint(key)) {
    1.69 +		sgl_log("keyboard: '%c' %s\n", (char)key, ststr);
    1.70 +	} else {
    1.71 +		sgl_log("keyboard: %x %s\n", key, ststr);
    1.72 +	}
    1.73 +	
    1.74 +	if(key == 27) {
    1.75 +		sgl_quit();
    1.76 +	}
    1.77 +}
    1.78 +
    1.79 +void mouse(int pidx, int bn, int state, int x, int y)
    1.80 +{
    1.81 +	printf("mouse: button%d %s (ptr: %d %d)\n", bn, state ? "pressed" : "released", x, y);
    1.82 +}
    1.83 +
    1.84 +void motion(int pidx, int x, int y)
    1.85 +{
    1.86 +	printf("mouse dragged to: (%d %d)\n", x, y);
    1.87 +}