From 3b21507274aa4f98644382903ae529c1fc2c7bd4 Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 20 Aug 2014 01:36:33 +1000 Subject: GL3D GWIN window + demo --- 3rdparty/tinygl-0.4-ugfx/examples/nanox.c | 113 ++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 3rdparty/tinygl-0.4-ugfx/examples/nanox.c (limited to '3rdparty/tinygl-0.4-ugfx/examples/nanox.c') diff --git a/3rdparty/tinygl-0.4-ugfx/examples/nanox.c b/3rdparty/tinygl-0.4-ugfx/examples/nanox.c new file mode 100644 index 00000000..14e5d4f1 --- /dev/null +++ b/3rdparty/tinygl-0.4-ugfx/examples/nanox.c @@ -0,0 +1,113 @@ +/* + * Demonstration program for Nano-X graphics. + */ +#include +#include +#include +#define MWINCLUDECOLORS +#include +#include +#include +#include "ui.h" + +static GR_WINDOW_ID w1; /* id for large window */ +static GR_GC_ID gc1; /* graphics context for text */ + +void errorcatcher(); /* routine to handle errors */ + +void tkSwapBuffers(void) +{ + nglXSwapBuffers(w1); +} + +int +ui_loop(int argc,char **argv, const char *name) +{ + GR_EVENT event; /* current event */ + GR_IMAGE_ID id = 0; + NGLXContext cx; + int width, height, k; + + if (GrOpen() < 0) { + fprintf(stderr, "cannot open graphics\n"); + exit(1); + } + + width = 400; + height = 300; + + GrSetErrorHandler(errorcatcher); + + w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 10, 10, width, height, 4, BLACK, WHITE); + + GrSelectEvents(w1, GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_KEY_DOWN); + + GrMapWindow(w1); + + gc1 = GrNewGC(); + + GrSetGCForeground(gc1, WHITE); + + cx = nglXCreateContext(NULL, 0); + nglXMakeCurrent(w1, cx); + + init(); + reshape(width, height); + + while (1) { + GrCheckNextEvent(&event); + switch(event.type) { + case GR_EVENT_TYPE_CLOSE_REQ: + GrFreeImage(id); + GrClose(); + exit(0); + case GR_EVENT_TYPE_EXPOSURE: + break; + case GR_EVENT_TYPE_KEY_DOWN: + { + GR_EVENT_KEYSTROKE *kp = &event.keystroke; + /* XXX: nanoX special keys are totally bugged ! */ + switch(kp->ch) { + case 81: + k = KEY_LEFT; + break; + case 83: + k = KEY_RIGHT; + break; + case 82: + k = KEY_UP; + break; + case 84: + k = KEY_DOWN; + break; + default: + k = kp->ch; + break; + } + key(k, 0); + } + break; + default: + idle(); + break; + } + } + + return 0; +} + + +/* + * Here on an unrecoverable error. + */ +void +errorcatcher(code, name, id) + GR_ERROR code; /* error code */ + GR_FUNC_NAME name; /* function name which failed */ + GR_ID id; /* resource id */ +{ + GrClose(); + fprintf(stderr, "DEMO ERROR: code %d, function %s, resource id %d\n", + code, name, id); + exit(1); +} -- cgit v1.2.3