Example #1
0
File: glc.c Project: cout/mglc
/* Mark for deletion GLC context c.
 * FIX ME!! If no client is using the GLC context, then we should delete the 
 * context immediately.  This requires adding thread support.
 */
void glcDeleteContext(GLint c) {
	int i, j;

	if(!glcIsContext(c)) {
		last_error = GLC_PARAMETER_ERROR;
		return;
	}

	/* Find this context in the list */
	for(j = 0; glcContextList[j] != 0; j++)
		if(glcContextList[j] == c) break;

	/* Delete all fonts in this context */
	for(i = glcContexts[c].num_fonts-1; i > 0; i--)
		glcDeleteFont(i);

	/* Delete the GL lists we are using */
	glDeleteLists(g->list_base, 256);

	/* Mark this context as unused */
	glcContexts[j].isContext = FALSE;

	/* Delete this context from the list */
	for(; glcContextList[j] != 0; j++)
		glcContextList[j] = glcContextList[j + 1];
}
Example #2
0
File: glc.c Project: cout/mglc
/* Assign the value c to the current thread's GLC context ID variable.
 * FIX ME!!  Because we use static globals to keep track of the GLC context
 * ID, this code is not thread-safe!  Additionally, we should return
 * GLC_STATE_ERROR if the requested context does not belong to the thread
 * that requested the context.
 */
void glcContext(GLint c){
	if(!glcIsContext(c) || c == 0) {
		last_error = GLC_PARAMETER_ERROR;
	} else {
		currentGlcContext = c;
		g = &glcContexts[currentGlcContext];
	}
}
Example #3
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)");
         }
      }
   }
}