sgl

annotate tests/simple/simple.c @ 39:e1a27aa24956

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