int main(int argc, char **argv) { GLint ctx = 0; GLint myFont = 0; glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(640, 400); glutCreateWindow("Test12"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glEnable(GL_TEXTURE_2D); /* Set up and initialize GLC */ ctx = glcGenContext(); glcContext(ctx); glcDisable(GLC_GL_OBJECTS); /* Create a font "Palatino Bold" */ myFont = glcGenFontID(); #ifdef __WIN32__ glcNewFontFromFamily(myFont, "Times New Roman"); glcFontFace(myFont, "Regular"); #else glcNewFontFromFamily(myFont, "DejaVu Serif"); glcFontFace(myFont, "Book"); #endif glcFont(myFont); glcRenderStyle(GLC_BITMAP); glutMainLoop(); return 0; }
// Set up and initialize GLC void testApp::setupQuesoGlc() { ofSetVerticalSync(true); //ofSetFrameRate(60); //ofEnableAlphaBlending(); //ofEnableSmoothing(); //ofBackground(0, 0, 0); ctx = glcGenContext(); glcContext(ctx); // glcAppendCatalog(ofToDataPath("font").c_str()); glcAppendCatalog("/System/Library/Fonts"); font = glcGenFontID(); glcNewFontFromFamily(font, "Hiragino Mincho ProN"); glcFontFace(font, "W6"); glcFont(font); glcRenderStyle(GLC_TEXTURE); glcEnable(GLC_GL_OBJECTS); glcEnable(GLC_MIPMAP); glcEnable(GLC_HINTING_QSO); glcStringType(GLC_UTF8_QSO); }
int main(int argc, char **argv) { GLint ctx = 0; GLint myFont = 0; glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(640, 230); glutCreateWindow("Tutorial 2"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); /* Set up and initialize GLC */ ctx = glcGenContext(); glcContext(ctx); glcAppendCatalog("/usr/lib/X11/fonts/Type1"); /* Create a font "Palatino Bold" */ myFont = glcGenFontID(); #ifdef __WIN32__ glcNewFontFromFamily(myFont, "Palatino Linotype"); #else glcNewFontFromFamily(myFont, "Palatino"); #endif glcFontFace(myFont, "Bold"); glcFont(myFont); /* Render the text at a size of 100 points */ glcScale(100.f, 100.f); glcRotate(10.f); glutMainLoop(); return 0; }
/* Attempt to set the current face of the font identified by fontnum to the * face identified by the string style. If the font does not support this * face, then do nothing and return GL_FALSE. If fontnum is zero, then * do this for all fonts, and return GL_FALSE iff no fonts were changed. */ GLboolean glcFontFace(GLint fontnum, const char *style) { int fontface, j; if(currentGlcContext == 0) { last_error = GLC_STATE_ERROR; return FALSE; } if(!strcasecmp(style, "Bold")) { fontface = GLC_STYLE_BOLD; } else if(!strcasecmp(style, "Normal")) { fontface = GLC_STYLE_NORMAL; } else if(!strcasecmp(style, "Italic")) { fontface = GLC_STYLE_ITALIC; } else if(!strcasecmp(style, "Bold Italic")) { fontface = GLC_STYLE_BOLD_ITALIC; } else { last_error = GLC_PARAMETER_ERROR; return FALSE; } /* If fontnum is zero, iterate through all the fonts in the current * font list. */ if(fontnum == 0) { GLboolean change = FALSE; for(j = 0; j < g->num_current_fonts; j++) { if(glcFontFace(j, style)) change = TRUE; } return change; } if(g->fonts[fontnum][fontface].isFont) { g->font_faces[fontnum] = fontface; if(g->current_font_list[0] == fontnum) { g->reload_font = TRUE; g->scale_change = TRUE; } #ifdef DEBUG fprintf(stderr, "Switching font %d to face %s (%d)\n", fontnum, style, fontface); #endif return TRUE; } else { #ifdef DEBUG fprintf(stderr, "Not switching font %d to face %s\n", fontnum, style); #endif return FALSE; } }
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)"); } } } }