sgl

annotate tests/simple/simple.c @ 26:e4c79d2c7f78

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