sgl
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tests/simple/simple.c Fri May 13 07:49:47 2011 +0300 1.3 @@ -0,0 +1,83 @@ 1.4 +#include <stdio.h> 1.5 +#include <ctype.h> 1.6 +#include <GL/gl.h> 1.7 +#include "sgl.h" 1.8 + 1.9 +void disp(void); 1.10 +void reshape(int x, int y); 1.11 +void keyb(int key, int state); 1.12 +void mouse(int bn, int state, int x, int y); 1.13 +void motion(int x, int y); 1.14 + 1.15 + 1.16 +int main(void) 1.17 +{ 1.18 + if(sgl_init() == -1) { 1.19 + return 1; 1.20 + } 1.21 + 1.22 + sgl_create_window(640, 480, SGL_DOUBLE | SGL_DEPTH); 1.23 + 1.24 + sgl_set_callback(SGL_DISPLAY, disp); 1.25 + sgl_set_callback(SGL_RESHAPE, reshape); 1.26 + sgl_set_callback(SGL_KEYBOARD, keyb); 1.27 + sgl_set_callback(SGL_MOUSE, mouse); 1.28 + sgl_set_callback(SGL_MOTION, motion); 1.29 + 1.30 + sgl_event_loop(); 1.31 + sgl_quit(); 1.32 + return 0; 1.33 +} 1.34 + 1.35 + 1.36 +void disp(void) 1.37 +{ 1.38 + printf("redisplay\n"); 1.39 + 1.40 + glClearColor(0.2, 0.2, 0.2, 1); 1.41 + glClear(GL_COLOR_BUFFER_BIT); 1.42 + 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 + 1.54 + sgl_swap_buffers(); 1.55 +} 1.56 + 1.57 +void reshape(int x, int y) 1.58 +{ 1.59 + printf("reshape: %dx%d\n", x, y); 1.60 + glViewport(0, 0, x, y); 1.61 +} 1.62 + 1.63 +void keyb(int key, int state) 1.64 +{ 1.65 + char *ststr = state ? "pressed" : "released"; 1.66 + 1.67 + if(key < 0xff && isprint(key)) { 1.68 + printf("keyboard: '%c' %s\n", (char)key, ststr); 1.69 + } else { 1.70 + printf("keyboard: %x %s\n", key, ststr); 1.71 + } 1.72 + 1.73 + if(key == 27) { 1.74 + sgl_quit(); 1.75 + } 1.76 +} 1.77 + 1.78 +void mouse(int bn, int state, int x, int y) 1.79 +{ 1.80 + printf("mouse: button%d %s (ptr: %d %d)\n", bn, state ? "pressed" : "released", x, y); 1.81 +} 1.82 + 1.83 +void motion(int x, int y) 1.84 +{ 1.85 + printf("mouse dragged to: (%d %d)\n", x, y); 1.86 +}