#include #include #include #include "main.h" void error(const char *file, int line) { fprintf(stderr, "%s %d\n", file, line); exit(1); } void init(void) { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glClearColor(0.0, 0.0, 0.5, 1.0); } void grid(int x, int y, int w, int h, int m, int n) { int i; glBegin(GL_LINES); for (i = 0; i <= n; ++i) { glVertex2d(x, 0.5 + y + i * h); glVertex2d(1.0 + x + m * w, 0.5 + y + i * h); } for (i = 0; i <= m; ++i) { glVertex2d(0.5 + x + i * w, y); glVertex2d(0.5 + x + i * w, 1.0 + y + n * h); } glEnd(); } void rect(int x, int y, int w, int h) { glBegin(GL_QUADS); glVertex2i(x, y); glVertex2i(x, y + h); glVertex2i(x + w, y + h); glVertex2i(x + w, y); glEnd(); } static int row = 0; void display(void) { int i; const unsigned char *p; glClear(GL_COLOR_BUFFER_BIT); glColor3d(0.0, 1.0, 0.0); grid(0, 0, 16, 16, 16, 6); grid(0, 100, 16, 16, 16, 6); if (row) { glColor3d(0.7, 0.0, 0.0); rect((row - 0xa0) % 16 * 16 + 1, (row - 0xa0) / 16 * 16 + 1, 15, 15); } glColor3d(1.0, 1.0, 1.0); glRasterPos2i(16, 0); for (i = 0x21; i < 0x7f; ++i) { if (!(i & 0xf)) { glRasterPos2i(0, 16 * (i / 16 - 2)); } glBitmap(7, 14, -1.0, 15.0, 16.0, 0.0, ascii(i)); } if (row) { glRasterPos2i(16, 100); for (i = 0xa1; i < 0xff; ++i) { if (!(i & 0xf)) { glRasterPos2i(0, 100 + 16 * (i / 16 - 10)); } if ((p = kanji(row, i)) != NULL) { glBitmap(14, 14, -1.0, 15.0, 16.0, 0.0, p); } else { unsigned char c = 0; glBitmap(1, 1, 0.0, 0.0, 16.0, 0.0, &c); } } } glFlush(); } void mouse(int button, int state, int x, int y) { if (button == GLUT_RIGHT_BUTTON && state == GLUT_UP) { exit(0); } else if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { x /= 16; y /= 16; if (x == 0 && y == 0) { row = 0; glutPostRedisplay(); } else if (!(x == 15 && y == 5) && x < 16 && y < 6) { row = y * 16 + x + 0xa0; glutPostRedisplay(); } } }