TinyGL 0.4.1 for MinGW
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
nanox.c
Go to the documentation of this file.
1/*
2 * Demonstration program for Nano-X graphics.
3 */
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#define MWINCLUDECOLORS
8#include <microwin/nano-X.h>
9#include <GL/gl.h>
10#include <GL/nglx.h>
11#include "ui.h"
12
13static GR_WINDOW_ID w1; /* id for large window */
14static GR_GC_ID gc1; /* graphics context for text */
15
16void errorcatcher(); /* routine to handle errors */
17
18void tkSwapBuffers(void)
19{
21}
22
23int
24ui_loop(int argc,char **argv, const char *name)
25{
26 GR_EVENT event; /* current event */
27 GR_IMAGE_ID id = 0;
29 int width, height, k;
30
31 if (GrOpen() < 0) {
32 fprintf(stderr, "cannot open graphics\n");
33 exit(1);
34 }
35
36 width = 400;
37 height = 300;
38
39 GrSetErrorHandler(errorcatcher);
40
41 w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 10, 10, width, height, 4, BLACK, WHITE);
42
43 GrSelectEvents(w1, GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_KEY_DOWN);
44
45 GrMapWindow(w1);
46
47 gc1 = GrNewGC();
48
49 GrSetGCForeground(gc1, WHITE);
50
51 cx = nglXCreateContext(NULL, 0);
53
54 init();
55 reshape(width, height);
56
57 while (1) {
58 GrCheckNextEvent(&event);
59 switch(event.type) {
60 case GR_EVENT_TYPE_CLOSE_REQ:
61 GrFreeImage(id);
62 GrClose();
63 exit(0);
64 case GR_EVENT_TYPE_EXPOSURE:
65 break;
66 case GR_EVENT_TYPE_KEY_DOWN:
67 {
68 GR_EVENT_KEYSTROKE *kp = &event.keystroke;
69 /* XXX: nanoX special keys are totally bugged ! */
70 switch(kp->ch) {
71 case 81:
72 k = KEY_LEFT;
73 break;
74 case 83:
75 k = KEY_RIGHT;
76 break;
77 case 82:
78 k = KEY_UP;
79 break;
80 case 84:
81 k = KEY_DOWN;
82 break;
83 default:
84 k = kp->ch;
85 break;
86 }
87 key(k, 0);
88 }
89 break;
90 default:
91 idle();
92 break;
93 }
94 }
95
96 return 0;
97}
98
99
100/*
101 * Here on an unrecoverable error.
102 */
103void
104errorcatcher(code, name, id)
105 GR_ERROR code; /* error code */
106 GR_FUNC_NAME name; /* function name which failed */
107 GR_ID id; /* resource id */
108{
109 GrClose();
110 fprintf(stderr, "DEMO ERROR: code %d, function %s, resource id %d\n",
111 code, name, id);
112 exit(1);
113}
void idle(void)
Definition: gears.c:203
GLenum key(int k, GLenum mask)
Definition: gears.c:212
void init(void)
Definition: gears.c:257
void reshape(int width, int height)
Definition: gears.c:242
GDIContext cx
Definition: mingw32.c:38
void errorcatcher()
int ui_loop(int argc, char **argv, const char *name)
Definition: nanox.c:24
void tkSwapBuffers(void)
Definition: nanox.c:18
int nglXMakeCurrent(NGLXDrawable drawable, NGLXContext ctx)
Definition: nglx.c:71
void * NGLXContext
Definition: nglx.h:11
NGLXContext nglXCreateContext(NGLXContext shareList, int flags)
Definition: nglx.c:15
void nglXSwapBuffers(NGLXDrawable drawable)
Definition: nglx.c:115
#define KEY_RIGHT
Definition: ui.h:15
#define KEY_DOWN
Definition: ui.h:13
#define KEY_LEFT
Definition: ui.h:14
#define KEY_UP
Definition: ui.h:12