int main(int argc, char **argv) { int submenu; glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(600, 600); glutCreateWindow("GLC font library demo"); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, 2000, 0, 2000); glMatrixMode(GL_MODELVIEW); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glLineWidth(3.0); glTranslatef(1000, 1000, 0); glClearColor(0.0, 0.0, 0.0, 1.0); glColor3f(1.0, 1.0, 1.0); glutDisplayFunc(display); glutIdleFunc(tick); submenu = glutCreateMenu(selectMessage); glutAddMenuEntry("abc", 1); glutAddMenuEntry("ABC", 2); glutCreateMenu(selectFont); glutAddMenuEntry("Helvetica", 1); glutAddMenuEntry("Courier", 2); glutAddMenuEntry("Times", 3); glutAddSubMenu("Messages", submenu); glutAttachMenu(GLUT_RIGHT_BUTTON); glcContext(glcGenContext()); glcScale(30, 30); glcNewFontFromFamily(1, "Helvetica"); glcNewFontFromFamily(2, "Courier"); glcNewFontFromFamily(3, "Times"); glcFont(font); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
void hack_init (xstuff_t * XStuff) { //Load the fonts for printing debug info to the window. #ifdef HAVE_GLC glc_ctx = glcGenContext (); glcContext (glc_ctx); for (unsigned int ii = 0; ii < FONT_COUNT; ii++) { fonts[ii].id = glcGenFontID(); if (glcNewFontFromFamily(fonts[ii].id, fonts[ii].name) != fonts[ii].id) { printf("%s\n", fonts[ii].name); glcDeleteFont(fonts[ii].id); fonts[ii].id = 0; } } glcScale (FONT_SIZE, FONT_SIZE); #endif hack_reshape (XStuff); TextureInit (); WorldInit (); }
static void iV_initializeGLC(void) { if (_glcContext) { return; } _glcContext = glcGenContext(); if (!_glcContext) { debug(LOG_ERROR, "Failed to initialize"); } else { debug(LOG_NEVER, "Successfully initialized. _glcContext = %d", (int)_glcContext); } glcContext(_glcContext); glcEnable(GLC_AUTO_FONT); // We *do* want font fall-backs glcRenderStyle(GLC_TEXTURE); glcStringType(GLC_UTF8_QSO); // Set GLC's string type to UTF-8 FIXME should be UCS4 to avoid conversions #ifdef WZ_OS_MAC { char resourcePath[PATH_MAX]; CFURLRef resourceURL = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); if (CFURLGetFileSystemRepresentation(resourceURL, true, (UInt8 *) resourcePath, PATH_MAX)) { sstrcat(resourcePath, "/Fonts"); glcAppendCatalog(resourcePath); } else { debug(LOG_ERROR, "Could not change to resources directory."); } if (resourceURL != NULL) { CFRelease(resourceURL); } } #endif _glcFont_Regular = glcGenFontID(); _glcFont_Bold = glcGenFontID(); if (!glcNewFontFromFamily(_glcFont_Regular, font_family)) { debug(LOG_ERROR, "Failed to select font family %s as regular font", font_family); } else { debug(LOG_NEVER, "Successfully selected font family %s as regular font", font_family); } if (!glcFontFace(_glcFont_Regular, font_face_regular)) { debug(LOG_WARNING, "Failed to select the \"%s\" font face of font family %s", font_face_regular, font_family); } else { debug(LOG_NEVER, "Successfully selected the \"%s\" font face of font family %s", font_face_regular, font_family); } if (!glcNewFontFromFamily(_glcFont_Bold, font_family)) { debug(LOG_ERROR, "iV_initializeGLC: Failed to select font family %s for the bold font", font_family); } else { debug(LOG_NEVER, "Successfully selected font family %s for the bold font", font_family); } if (!glcFontFace(_glcFont_Bold, font_face_bold)) { debug(LOG_WARNING, "Failed to select the \"%s\" font face of font family %s", font_face_bold, font_family); } else { debug(LOG_NEVER, "Successfully selected the \"%s\" font face of font family %s", font_face_bold, font_family); } debug(LOG_NEVER, "Finished initializing GLC"); }
static void access_font() { /* This routine contains all the necessary steps to setup a */ /* font master and a face. Subsequent glcRenderChar() and */ /* glcRenderString() calls will draw the characters in the */ /* specified font/face. */ static GLboolean have_context = GL_FALSE; GLint glc_context; GLint master_count; #ifdef _WIN32_ const char* master_name = "Times New Roman"; #else const char* master_name = "Times"; #endif GLint master; GLint face_count; const char* face_name = "Bold"; static GLint glc_font_id; GLint result; unsigned int i, j; if (have_context == GL_FALSE) { /* Only get a context once. */ /* When using SGI's implementation of GLC, don't call glcGetError() */ /* after this glcGenContext() call because it always returns */ /* GLC_STATE_ERROR. That's probably a bug in SGI's GLC. This behavior */ /* doesn't occur in QuesoGLC. */ /* So, in order to let glclogo run with both implementations, just */ /* validate the context. If it's OK, then go for it. */ glc_context = glcGenContext(); if (!glcIsContext(glc_context)) { fprintf(stderr, "Error - glcGenContext() failed. Exiting.\n"); exit(-1); } else { /* Context is valid. Make it the current context. */ glcContext(glc_context); check_glc_error("glcContext()"); have_context = GL_TRUE; /* Get a unique font ID. */ glc_font_id = glcGenFontID(); /* Choose a master and a face. */ master_count = glcGeti(GLC_MASTER_COUNT); master = 0; for (i = 0; i < master_count; i++) { if (!strcmp((const char*)glcGetMasterc(i, GLC_FAMILY), master_name)) { face_count = glcGetMasteri(i, GLC_FACE_COUNT); for (j = 0; j < face_count; j++) { if (!strcmp((const char*)glcGetMasterListc(i, GLC_FACE_LIST, j), face_name)) { master = i; } } } } /* Access the font family. */ result = glcNewFontFromFamily(glc_font_id, glcGetMasterc(master, GLC_FAMILY)); check_glc_error("glcNewFontFromFamily()"); if (result != glc_font_id) { fprintf(stderr, "Error - glcNewFontFromFamily() failed. Exiting.\n"); exit(-1); } else { /* Use the font. */ glcFont(glc_font_id); check_glc_error("glcFont()"); /* Use the face. */ glcFontFace(glc_font_id, face_name); check_glc_error("glcFontFace()"); #if 0 /* This only speeds up immediate mode rendering. */ /* Don't do this when compiling your own display list because */ /* the polygons will go into the GLC internal display lists */ /* rather than the display list you are trying to construct. */ glcEnable(GLC_GL_OBJECTS); check_glc_error("glcEnable(GLC_GL_OBJECTS)"); #else glcDisable(GLC_GL_OBJECTS); check_glc_error("glcDisable(GLC_GL_OBJECTS)"); #endif /* Draw as polygons for smooth rotation & zoom. */ glcRenderStyle(GLC_TRIANGLE); check_glc_error("glcRenderStyle(GLC_TRIANGLE)"); } } } }