Exemple #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);

}
Exemple #2
0
void display(void)
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glColor3f(1.f, 0.f, 0.f);
  glLoadIdentity();
  glScalef(20.f, 20.f, 1.f);
  glTranslatef(2.f, 2.f, 0.f);
  glcDisable(GLC_HINTING_QSO);
  glcRenderString("lili without hinting (rendered at integer coordinates)");

  glLoadIdentity();
  glScalef(20.f, 20.f, 1.f);
  glTranslatef(2.025f, 3.f, 0.f);
  glcDisable(GLC_HINTING_QSO);
  glcRenderString("lili without hinting (rendered at non-integer coordinates)");

  glLoadIdentity();
  glScalef(20.f, 20.f, 1.f);
  glTranslatef(2.f, 4.f, 0.f);
  glcEnable(GLC_HINTING_QSO);
  glcRenderString("lili with hinting (rendered at integer coordinates)");

  glLoadIdentity();
  glScalef(20.f, 20.f, 1.f);
  glTranslatef(2.025f, 5.f, 0.f);
  glcEnable(GLC_HINTING_QSO);
  glcRenderString("lili with hinting (rendered at non-integer coordinates)");

  glFlush();
}
Exemple #3
0
static inline void iV_printFontList(void)
{
	unsigned int i;
	unsigned int font_count = glcGeti(GLC_CURRENT_FONT_COUNT);
	debug(LOG_NEVER, "GLC_CURRENT_FONT_COUNT = %d", font_count);

	if (font_count == 0)
	{
		debug(LOG_ERROR, "The required font (%s) isn't loaded", font_family);

		// Fall back to unselected fonts since the requested font apparently
		// isn't available.
		glcEnable(GLC_AUTO_FONT);
	}

	for (i = 0; i < font_count; ++i)
	{
		GLint font = glcGetListi(GLC_CURRENT_FONT_LIST, i);
		/* The output of the family name and the face is printed using 2 steps
		 * because glcGetFontc and glcGetFontFace return their result in the
		 * same buffer (according to GLC specs).
		 */
		char prBuffer[1024];
		snprintf(prBuffer, sizeof(prBuffer), "Font #%d : %s ", (int)font, (const char *)glcGetFontc(font, GLC_FAMILY));
		prBuffer[sizeof(prBuffer) - 1] = 0;
		sstrcat(prBuffer, (char const *)glcGetFontFace(font));
		debug(LOG_NEVER, "%s", prBuffer);
	}
}
Exemple #4
0
void display(void)
{
  int i = 0;
  GLfloat bbox[8] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
  GLfloat bbox2[8] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
  char string[20];

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  /* Render GLC_BITMAP without kerning */
  glLoadIdentity();
  glColor3f(1.f, 0.f, 0.f);
  glRasterPos2f(50.f, 50.f);
  glcDisable(GLC_KERNING_QSO);
  glcRenderStyle(GLC_BITMAP);
  glcLoadIdentity();
  glcScale(100.f, 100.f);
  glcRenderString("VAV");
  glcMeasureString(GL_FALSE, "VAV");
  glcGetStringMetric(GLC_BOUNDS, bbox);
  glColor3f(0.f, 1.f, 1.f);
  glTranslatef(50.f, 50.f, 0.f);
  glBegin(GL_LINE_LOOP);
  for (i = 0; i < 4; i++)
    glVertex2fv(&bbox[2*i]);
  glEnd();
  /* Display the dimensions */
  snprintf(string, 20, "%f", bbox[2] - bbox[0]);
  glcEnable(GLC_HINTING_QSO);
  glcScale(0.15f, 0.15f);
  glcMeasureString(GL_FALSE, string);
  glcGetStringMetric(GLC_BOUNDS, bbox2);
  glColor3f(1.f, 1.f, 1.f);
  glBegin(GL_LINE);
  glVertex2fv(bbox);
  glVertex2f(bbox[0], bbox[1] - 40.f);
  glVertex2fv(&bbox[2]);
  glVertex2f(bbox[2], bbox[3] - 40.f);
  glVertex2f(bbox[0], bbox[1] - 30.f);
  glVertex2f(bbox[2], bbox[3] - 30.f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[0] + 5.f, bbox[1] - 25.f);
  glVertex2f(bbox[0], bbox[1] - 30.f);
  glVertex2f(bbox[0] + 5.f, bbox[1] - 35.f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[2] - 5.f, bbox[1] - 25.f);
  glVertex2f(bbox[2], bbox[1] - 30.f);
  glVertex2f(bbox[2] - 5.f, bbox[1] - 35.f);
  glEnd();
  glLoadIdentity();
  glRasterPos2f(floor((bbox[2] - bbox[0]
		       - (bbox2[2] - bbox2[0])) * 50.f) / 100.f + 50.f,
		floorf((bbox[1] + 23.f) * 100.f) / 100.f);
  glcRenderString(string);
  glcDisable(GLC_HINTING_QSO);

  /* Render GLC_TEXTURE without kerning */
  glLoadIdentity();
  glcRenderStyle(GLC_TEXTURE);
  glColor3f(1.f, 0.f, 0.f);
  glScalef(100.f, 100.f, 1.f);
  glTranslatef(3.f, 0.5f, 0.f);
  glPushMatrix();
  /* In order to reproduce the conditions of bug #1987563, GLC_GL_OBJECTS must
   * be disabled when rendering GLC_TEXTURE w/o kerning.
   */
  glcRenderString("VAV");
  glPopMatrix();
  glcMeasureString(GL_TRUE, "VAV");
  glcGetStringCharMetric(1, GLC_BOUNDS, bbox);
  glColor3f(0.f, 1.f, 0.f);
  glBegin(GL_LINE_LOOP);
  for (i = 0; i < 4; i++)
    glVertex2fv(&bbox[2*i]);
  glEnd();
  glcGetStringMetric(GLC_BOUNDS, bbox);
  glColor3f(0.f, 1.f, 1.f);
  glBegin(GL_LINE_LOOP);
  for (i = 0; i < 4; i++)
    glVertex2fv(&bbox[2*i]);
  glEnd();
  /* Display the dimensions */
  snprintf(string, 20, "%f", (bbox[2] - bbox[0]) * 100.f);
  glcEnable(GLC_HINTING_QSO);
  glcMeasureString(GL_FALSE, string);
  glcGetStringMetric(GLC_BOUNDS, bbox2);
  glColor3f(1.f, 1.f, 1.f);
  glBegin(GL_LINE);
  glVertex2fv(bbox);
  glVertex2f(bbox[0], bbox[1] - 0.4f);
  glVertex2fv(&bbox[2]);
  glVertex2f(bbox[2], bbox[3] - 0.4f);
  glVertex2f(bbox[0], bbox[1] - 0.3f);
  glVertex2f(bbox[2], bbox[3] - 0.3f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[0] + 0.05f, bbox[1] - 0.25f);
  glVertex2f(bbox[0], bbox[1] - 0.3f);
  glVertex2f(bbox[0] + 0.05f, bbox[1] - 0.35f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[2] - 0.05f, bbox[1] - 0.25f);
  glVertex2f(bbox[2], bbox[1] - 0.3f);
  glVertex2f(bbox[2] - 0.05f, bbox[1] - 0.35f);
  glEnd();
  /* When hinting is enabled, characters must be rendered at integer positions
   * otherwise hinting is compromised and characters look fuzzy.
   */
  glTranslatef(floorf((bbox[2] - bbox[0]
		       - (bbox2[2] - bbox2[0]) * 0.15f) * 50.f) / 100.f,
	       floorf((bbox[1] - 0.27f) * 100.f) / 100.f, 0.f);
  glScalef(0.15f, 0.15f, 1.f);
  glcRenderString(string);
  glcDisable(GLC_HINTING_QSO);

  /* Render GLC_BITMAP with kerning */
  glColor3f(1.f, 0.f, 0.f);
  glcEnable(GLC_KERNING_QSO);
  glcRenderStyle(GLC_BITMAP);
  glcLoadIdentity();
  glcScale(100.f, 100.f);
  glLoadIdentity();
  glRasterPos2f(50.f, 150.f);
  glcRenderString("VAV");
  glcMeasureString(GL_FALSE, "VAV");
  glcGetStringMetric(GLC_BOUNDS, bbox);
  glColor3f(0.f, 1.f, 1.f);
  glTranslatef(50.f, 150.f, 0.f);
  glBegin(GL_LINE_LOOP);
  for (i = 0; i < 4; i++)
    glVertex2fv(&bbox[2*i]);
  glEnd();
  /* Display the dimensions */
  snprintf(string, 20, "%f", bbox[4] - bbox[6]);
  glcEnable(GLC_HINTING_QSO);
  glcScale(0.15f, 0.15f);
  glcMeasureString(GL_FALSE, string);
  glcGetStringMetric(GLC_BOUNDS, bbox2);
  glColor3f(1.f, 1.f, 1.f);
  glBegin(GL_LINE);
  glVertex2fv(&bbox[4]);
  glVertex2f(bbox[4], bbox[5] + 40.f);
  glVertex2fv(&bbox[6]);
  glVertex2f(bbox[6], bbox[7] + 40.f);
  glVertex2f(bbox[4], bbox[5] + 30.f);
  glVertex2f(bbox[6], bbox[7] + 30.f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[4] - 5.f, bbox[5] + 25.f);
  glVertex2f(bbox[4], bbox[5] + 30.f);
  glVertex2f(bbox[4] - 5.f, bbox[5] + 35.f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[6] + 5.f, bbox[7] + 25.f);
  glVertex2f(bbox[6], bbox[7] + 30.f);
  glVertex2f(bbox[6] + 5.f, bbox[7] + 35.f);
  glEnd();
  glLoadIdentity();
  glRasterPos2f(floorf((bbox[4] - bbox[6]
			- (bbox2[4] - bbox2[6])) * 50.f) / 100.f + 50.f,
		bbox[7] + 183.f);
  glcRenderString(string);
  glcScale(2.f, 2.f);
  glcMeasureString(GL_FALSE, "GL_BITMAP");
  glcGetStringMetric(GLC_BOUNDS, bbox2);
  glRasterPos2f(floorf((bbox[2] - bbox[0]
			- (bbox2[2] - bbox2[0])) * 50.f) / 100.f + 50.f,
		300.f);
  glcRenderString("GL_BITMAP");
  glcDisable(GLC_HINTING_QSO);

  /* Render GLC_TEXTURE with kerning */
  glLoadIdentity();
  glcRenderStyle(GLC_TEXTURE);
  glColor3f(1.f, 0.f, 0.f);
  glScalef(100.f, 100.f, 1.f);
  glTranslatef(3.f, 1.5f, 0.f);
  glPushMatrix();
  glcRenderString("VAV");
  glPopMatrix();
  glcMeasureString(GL_TRUE, "VAV");
  glcGetStringCharMetric(1, GLC_BOUNDS, bbox);
  glColor3f(0.f, 1.f, 0.f);
  glBegin(GL_LINE_LOOP);
  for (i = 0; i < 4; i++)
    glVertex2fv(&bbox[2*i]);
  glEnd();
  glcGetStringMetric(GLC_BOUNDS, bbox);
  glColor3f(0.f, 1.f, 1.f);
  glBegin(GL_LINE_LOOP);
  for (i = 0; i < 4; i++)
    glVertex2fv(&bbox[2*i]);
  glEnd();
  /* Display the dimensions */
  snprintf(string, 20, "%f", (bbox[4] - bbox[6]) * 100.f);
  glcEnable(GLC_HINTING_QSO);
  glcMeasureString(GL_FALSE, string);
  glcGetStringMetric(GLC_BOUNDS, bbox2);
  glColor3f(1.f, 1.f, 1.f);
  glBegin(GL_LINE);
  glVertex2fv(&bbox[4]);
  glVertex2f(bbox[4], bbox[5] + 0.4f);
  glVertex2fv(&bbox[6]);
  glVertex2f(bbox[6], bbox[7] + 0.4f);
  glVertex2f(bbox[4], bbox[5] + 0.3f);
  glVertex2f(bbox[6], bbox[7] + 0.3f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[6] + 0.05f, bbox[7] + 0.25f);
  glVertex2f(bbox[6], bbox[7] + 0.3f);
  glVertex2f(bbox[6] + 0.05f, bbox[7] + 0.35f);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex2f(bbox[4] - 0.05f, bbox[5] + 0.25f);
  glVertex2f(bbox[4], bbox[5] + 0.3f);
  glVertex2f(bbox[4] - 0.05f, bbox[5] + 0.35f);
  glEnd();
  glPushMatrix();
  glTranslatef(floorf((bbox[4] - bbox[6]
		       - (bbox2[4] - bbox2[6]) * 0.15f) *50.f) / 100.f,
	       floorf((bbox[5] + 0.33f) * 100.f) / 100.f, 0.f);
  glScalef(0.15f, 0.15f, 1.f);
  glcRenderString(string);
  glPopMatrix();
  glcMeasureString(GL_FALSE, "GL_TEXTURE");
  glcGetStringMetric(GLC_BOUNDS, bbox2);
  glTranslatef(floorf((bbox[2] - bbox[0]
		       - (bbox2[2] - bbox2[0]) * 0.3f) * 50.f)  / 100.f,
	       1.5f, 0.f);
  glScalef(0.3f, 0.3f, 1.f);
  glcRenderString("GL_TEXTURE");
  glcDisable(GLC_HINTING_QSO);

  glFlush();
}
Exemple #5
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");
}
Exemple #6
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)");
         }
      }
   }
}