Example #1
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);

}
Example #2
0
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;
}
Example #3
0
int main(int argc, char **argv)
{
  GLint ctx = 0;
  GLint myFont = 0;

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowSize(640, 180);
  glutCreateWindow("Test14");
  glutDisplayFunc(display);
  glutReshapeFunc(reshape);
  glutKeyboardFunc(keyboard);

  glEnable(GL_TEXTURE_2D);

  /* Set up and initialize GLC */
  ctx = glcGenContext();
  glcContext(ctx);

  /* Create a font "Palatino Bold" */
  myFont = glcGenFontID();
#ifdef __WIN32__
  glcNewFontFromFamily(myFont, "Arial");
#else
  glcNewFontFromFamily(myFont, "DejaVu Sans");
#endif
  glcFont(myFont);
  glcRenderStyle(GLC_TEXTURE);
  glcDisable(GLC_GL_OBJECTS);

  glutMainLoop();
  return 0;
}
Example #4
0
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);
#ifdef __WIN32__
  glutAddMenuEntry("Arial", 1);
  glutAddMenuEntry("Courier New", 2);
  glutAddMenuEntry("Times New Roman", 3);
#else
  glutAddMenuEntry("Helvetica", 1);
  glutAddMenuEntry("Courier", 2);
  glutAddMenuEntry("Times", 3);
#endif
  glutAddSubMenu("Messages", submenu);
  glutAttachMenu(GLUT_RIGHT_BUTTON);
  glcContext(glcGenContext());
  glcScale(30, 30);
#ifdef __WIN32__
  glcNewFontFromFamily(1, "Arial");
  glcNewFontFromFamily(2, "Courier New");
  glcNewFontFromFamily(3, "Times New Roman");
#else
  glcNewFontFromFamily(1, "Helvetica");
  glcNewFontFromFamily(2, "Courier");
  glcNewFontFromFamily(3, "Times");
#endif
  glcFont(font);
  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}
Example #5
0
int main(int argc, char **argv)
{
  int ctx = 0;
  int numMasters = 0;
  int numFaces = 0;
  int numCatalogs = 0;
  int i = 0;
  int j = 0;

  /* Needed to initialize an OpenGL context */
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutCreateWindow("testfont");

  ctx = glcGenContext();
  glcContext(ctx);

  numCatalogs = glcGeti(GLC_CATALOG_COUNT);
  printf("Catalogs : %d\n", numCatalogs);
  
  for (i = 0; i < numCatalogs; i++)
    printf("Catalog #%d : %s\n", i,
	   (const char *)glcGetListc(GLC_CATALOG_LIST, i));

  numMasters = glcGeti(GLC_MASTER_COUNT);
  printf("Masters : %d\n", numMasters);

  for (i = 0; i < numMasters; i++) {
    numFaces = glcGetMasteri(i, GLC_FACE_COUNT);
    printf("Master #%d\n", i);
    printf("- Vendor : %s\n", (char*)glcGetMasterc(i, GLC_VENDOR));
    printf("- Format : %s\n", (char*)glcGetMasterc(i, GLC_MASTER_FORMAT));
    printf("- Face count : %d\n", numFaces);
    printf("- Family : %s\n", (char*)glcGetMasterc(i, GLC_FAMILY));
    printf("- Version : %s\n", (char*)glcGetMasterc(i, GLC_VERSION));
    printf("- Is Fixed Pitch : %s\n", glcGetMasteri(i, GLC_IS_FIXED_PITCH) ?
	   "YES" : "NO");
    for (j = 0; j < numFaces; j++)
      printf("- Face #%d : %s\n", j, 
	     (char *)glcGetMasterListc(i, GLC_FACE_LIST, j));
    printf("- Master #%d maps 0x%X to %s\n", i, 65 + i,
	   (char *)glcGetMasterMap(i, 65 + i));
  }

  glcDeleteContext(ctx);
  return 0;
}
Example #6
0
void iV_TextShutdown()
{
	if (_glcFont_Regular)
	{
		glcDeleteFont(_glcFont_Regular);
	}

	if (_glcFont_Bold)
	{
		glcDeleteFont(_glcFont_Bold);
	}

	glcContext(0);

	if (_glcContext)
	{
		glcDeleteContext(_glcContext);
	}
}
Example #7
0
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 ();
}
Example #8
0
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");
}
Example #9
0
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)");
         }
      }
   }
}
Example #10
0
int main(int argc, char **argv) {
  GLint ctx;
  GLCenum err;
  GLint length = 0;
  GLint i, j, n;
  GLint font = 0;
  GLfloat baseline1[4], baseline2[4];
  GLfloat boundingBox1[8], boundingBox2[8];
  GLfloat v1, v2, norm, area;

  /* Needed to initialize an OpenGL context */
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutCreateWindow("test7");

  ctx = glcGenContext();
  CheckError();

  glcContext(ctx);
  CheckError();

  length = glcMeasureCountedString(GL_TRUE, strlen(string)-1, string);
  CheckError();

  if ((!length) || (length != (strlen(string)-1))) {
    printf("glcMeasureString() failed to measure %d characters"
	   " (%d measured instead)\n", (int)strlen(string), length);
    return -1;
  }

  n = glcGeti(GLC_MEASURED_CHAR_COUNT);
  CheckError();

  if (length != n) {
    printf("glcGeti(GLC_MEASURED_CHAR_COUNT) == %d is not consistent with the"
	   " value returned by glcMeasureString() == %d\n", n, length);
    return -1;
  }

  length = glcMeasureString(GL_TRUE, string);
  CheckError();

  if ((!length) || (length != strlen(string))) {
    printf("glcMeasureString() failed to measure %d characters"
	   " (%d measured instead)\n", (int)strlen(string), length);
    return -1;
  }

  n = glcGeti(GLC_MEASURED_CHAR_COUNT);
  CheckError();

  if (length != n) {
    printf("glcGeti(GLC_MEASURED_CHAR_COUNT) == %d is not consistent with the"
	   " value returned by glcMeasureString() == %d\n", n, length);
    return -1;
  }

  for (i = 0; i < strlen(string); i++) {
    if (!glcGetCharMetric(string[i], GLC_BASELINE, baseline1)) {
      printf("Failed to measure the baseline of the character %c\n",
	     string[i]);
      return -1;
    }

    CheckError();

    if (!glcGetStringCharMetric(i, GLC_BASELINE, baseline2)) {
      printf("Failed to get the baseline of the %dth character of the string"
	     " %s\n", i, string);
      return -1;
    }

    CheckError();

    for (j = 0; j < 2; j++) {
      v1 = fabs(baseline1[j + 2] - baseline1[j]);
      v2 = fabs(baseline2[j + 2] - baseline2[j]);
      norm = v1 > v2 ? v1 : v2;

      if (fabs(v1 - v2) > EPSILON * norm) {
	printf("Baseline values differ [rank %d char %d] %f (char),"
	       " %f (string)\n", j, i, v1, v2);
	return -1;
      }
    }

    if (!glcGetCharMetric(string[i], GLC_BOUNDS, boundingBox1)) {
      printf("Failed to measure the bounding box of the character %c\n",
	     string[i]);
      return -1;
    }

    CheckError();

    if (!glcGetStringCharMetric(i, GLC_BOUNDS, boundingBox2)) {
      printf("Failed to get the bounding box of the %dth character of the"
	     " string %s\n", i, string);
      return -1;
    }

    CheckError();

    for (j = 0; j < 6; j++) {
      v1 = fabs(boundingBox1[j + 2] - boundingBox1[j]);
      v2 = fabs(boundingBox2[j + 2] - boundingBox2[j]);
      norm = v1 > v2 ? v1 : v2;

      if (fabs(v1 - v2) > EPSILON * norm) {
	printf("Bounding Box values differ [rank %d char %d] %f (char),"
	       " %f (string)", j, i, v1, v2);
	return -1;
      }
    }
  }

  if (!glcGeti(GLC_FONT_COUNT)) {
    printf("GLC_FONT_LIST is empty\n");
    return -1;
  }

  CheckError();

  if (!glcGeti(GLC_CURRENT_FONT_COUNT)) {
    printf("GLC_CURRENT_FONT_LIST is empty\n");
    return -1;
  }

  CheckError();

  if (!glcGetMaxCharMetric(GLC_BASELINE, baseline1)) {
    printf("Failed to get the max baseline of the current fonts\n");
    return -1;
  }

  CheckError();

  v1 = fabs(baseline1[1]);
  v2 = fabs(baseline1[3]);
  norm = v1 > v2 ? v1 : v2;

  if (fabs(v1 - v2) < EPSILON * norm) {
    v1 = fabs(baseline1[0]);
    v2 = fabs(baseline1[2]);
    norm = v1 > v2 ? v1 : v2;
    if ((fabs(v1 - v2) < EPSILON * norm) || (baseline1[2] < baseline1[0])) {
      printf("Right and left side of the max baseline are swapped\n");
      printf("%f %f %f %f\n", baseline1[0], baseline1[1], baseline1[2],
	     baseline1[3]);
      font = glcGetListi(GLC_FONT_LIST, 0);
      printf("Family : %s\n", (char*)glcGetFontc(font, GLC_FAMILY));
      printf("Face : %s\n", (char*)glcGetFontFace(font));
      return -1;
    }
  }

  if (!glcGetMaxCharMetric(GLC_BOUNDS, boundingBox1)) {
    printf("Failed to get the max bounding box of the current fonts\n");
    return -1;
  }

  CheckError();

  area = 0.;
  for (i = 0; i < 3; i++) {
    area += boundingBox1[2*i] * boundingBox1[2*(i+1)+1] 
      - boundingBox1[2*(i+1)] * boundingBox1[2*i+1];
  }

  if (fabs(area * .5) < EPSILON) {
    printf("Max area of the characters is null\n");
    return -1;
  }

  /* Regression test for bug #1821219 (glcGetCharMetric randomly crashes when
   * requesting measurement for the space character).
   */

  for (i = 0; i < glcGeti(GLC_MASTER_COUNT); i++) {
    GLint font = glcGenFontID();

    if (!glcNewFontFromMaster(font, i)) {
      printf("Can not get a font from master %s\n",
             (char*)glcGetMasterc(i, GLC_FAMILY));
      return -1;
    }

    CheckError();

    glcFont(font);

    CheckError();

    if (!glcGetFontMap(font, ' ')) {
      printf("INFO : Family %s %s has no space character\n",
	     (char*)glcGetFontc(font, GLC_FAMILY), (char*)glcGetFontFace(font));
      continue;
    }

    if (!glcGetCharMetric(' ', GLC_BOUNDS, boundingBox1)) {
      printf("Failed to get the bounding box of the space character\n");
      printf("Family : %s\n", (char*)glcGetFontc(font, GLC_FAMILY));
      printf("Face : %s\n", (char*)glcGetFontFace(font));
      return -1;
    }

    CheckError();

    if (!glcGetCharMetric(' ', GLC_BASELINE, baseline1)) {
      printf("Failed to get the baseline of the space character\n");
      printf("Family : %s\n", (char*)glcGetFontc(font, GLC_FAMILY));
      printf("Face : %s\n", (char*)glcGetFontFace(font));
      return -1;
    }

    CheckError();

    v1 = fabs(baseline1[1]);
    v2 = fabs(baseline1[3]);
    norm = v1 > v2 ? v1 : v2;

    if (fabs(v1 - v2) < EPSILON * norm) {
      v1 = fabs(baseline1[0]);
      v2 = fabs(baseline1[2]);
      norm = v1 > v2 ? v1 : v2;
      if ((fabs(v1 - v2) < EPSILON * norm) || (baseline1[2] < baseline1[0])) {
        printf("Right and left side of the baseline are swapped\n");
        printf("%f %f %f %f\n", baseline1[0], baseline1[1], baseline1[2],
               baseline1[3]);
	printf("Family : %s\n", (char*)glcGetFontc(font, GLC_FAMILY));
	printf("Face : %s\n", (char*)glcGetFontFace(font));
        return -1;
      }
    }
  }

  glcDeleteContext(ctx);
  glcContext(0);

  printf("Tests successful\n");
  return 0;
}