예제 #1
0
파일: OGLwin.c 프로젝트: alown/chromium
static int MakeFont(Display * xdisplay, char *fn)
{
    XFontStruct *fontInfo;
    Font id;
    unsigned int first, last;
    GLuint fontBase;

    fontInfo = XLoadQueryFont(xdisplay, fn);
    if (fontInfo == NULL) {
	printf("no font found\n'%s'\n", fn);
	exit(0);
    }

    id = fontInfo->fid;
    first = fontInfo->min_char_or_byte2;
    last = fontInfo->max_char_or_byte2;

    fontBase = glGenLists((GLuint) last + 1);
    if (fontBase == 0) {
	printf("out of display lists\n");
	exit(0);
    }
    glXUseXFont(id, first, last - first + 1, fontBase + first);

    return (fontBase);
}
예제 #2
0
		void GUIWindow::MakeRasterFont(std::string font)
		{
			XFontStruct *fontInfo;
			Font id;
			unsigned int first, last;
			//let user choose font to avoid hardcoding a font they may not have!
			fontInfo = XLoadQueryFont(display, font.c_str());


			if (fontInfo == NULL) 
			{
			    std::cout << "Font not found" << std::endl;
			}

			id = fontInfo->fid;
			first = fontInfo->min_char_or_byte2;
			last = fontInfo->max_char_or_byte2;

			base = glGenLists(last+1);

			if (!base) 
			{
			    std::cout << "out of display lists" << std::endl;
			}

			glXUseXFont(id, first, last-first+1, base+first);	
		}
예제 #3
0
JNIEXPORT void JNICALL GLX_NATIVE(glXUseXFont)
	(JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2, jint arg3)
{
	GLX_NATIVE_ENTER(env, that, glXUseXFont_FUNC);
	glXUseXFont(arg0, arg1, arg2, arg3);
	GLX_NATIVE_EXIT(env, that, glXUseXFont_FUNC);
}
// load fonts to display the node names
void init_font(GLuint base, const char* f)
{
	Display* display;
	XFontStruct* font_info;
	int first;
	int last;

	display = XOpenDisplay(0);
	if (display == 0)
	{
		fprintf(stderr, "XOpenDisplay() failed.  Exiting.\n");
		exit(-1);
	}
	else
	{
		font_info = XLoadQueryFont(display, f);
		if (!font_info)
		{
			fprintf(stderr, "XLoadQueryFont() failed - Exiting.\n");
			exit(-1);
		}
		else
		{
			first = font_info->min_char_or_byte2;
			last  = font_info->max_char_or_byte2;
			glXUseXFont(font_info->fid, first, last-first+1, base+first);
		}
		XCloseDisplay(display);
		display = 0;
	}
}
예제 #5
0
파일: glxspheres.c 프로젝트: stroyan/vogl
void buildfont()
{
#ifdef __linux__
    Display *dpy = XOpenDisplay(NULL);

    if (dpy)
    {
        XFontStruct *fontinfo = XLoadQueryFont(dpy, "fixed");
        if (fontinfo)
        {
            int minchar = fontinfo->min_char_or_byte2;
            int maxchar = fontinfo->max_char_or_byte2;

            fontlistbase = glGenLists(maxchar + 1);
            glXUseXFont(fontinfo->fid, minchar, maxchar - minchar + 1, fontlistbase + minchar);

            XFreeFont(dpy, fontinfo);
        }
    }

    XCloseDisplay(dpy);
#else
    HDC hdc = wglGetCurrentDC();

    SelectObject(hdc, GetStockObject(SYSTEM_FONT));
    wglUseFontBitmaps(hdc, 0, 255, fontlistbase);
#endif
}
예제 #6
0
파일: Ddx.cpp 프로젝트: AspireONE/berusky2
/*
 * This code was created by Jeff Molofee '99 
 * (ported to Linux/SDL by Ti Leggett '01)
 *
 * If you've found this code useful, please let me know.
 *
 * Visit Jeff at http://nehe.gamedev.net/
 * 
 * or for port-specific comments, questions, bugreports etc. 
 * email to [email protected]
 */
void BuildFont(void)            // Build Our Bitmap Font
{
  Display *dpy;                 /* Our current X display */
  XFontStruct *fontInfo;        /* Our font info */

  /* Sotrage for 96 characters */
  hwconf.font_baze = glGenLists(96);

  /* Get our current display long enough to get the fonts */
  dpy = XOpenDisplay(NULL);

  /* Get the font information */
  fontInfo =
    XLoadQueryFont(dpy,
    "-adobe-helvetica-medium-r-normal--18-*-*-*-p-*-iso8859-1");

  /* If the above font didn't exist try one that should */
  if (fontInfo == NULL) {
    fontInfo = XLoadQueryFont(dpy, "fixed");
    /* If that font doesn't exist, something is wrong */
    if (fontInfo == NULL) {
      fprintf(stderr, "no X font available?\n");
      return;
    }
  }

  /* generate the list */
  glXUseXFont(fontInfo->fid, 32, 96, hwconf.font_baze);

  /* Recover some memory */
  XFreeFont(dpy, fontInfo);

  /* close the display now that we're done with it */
  XCloseDisplay(dpy);
}
예제 #7
0
void glfntInit(void)
{

  Display *dpy;
  
  XFontStruct *fontInfo;
  Font id;
  unsigned int first;

  if (LettersDL!=0) return;
#ifdef SGI_CC
  dpy=glXGetCurrentDisplayEXT();
#else  
  dpy=glXGetCurrentDisplay();
#endif  
   if (dpy==NULL) return;
  fontInfo = XLoadQueryFont(dpy,
        "-adobe-times-medium-r-normal--17-120-100-100-p-88-iso8859-1");    
  if (fontInfo == NULL) return;

  id = fontInfo->fid;
  first = fontInfo->min_char_or_byte2;
  last = fontInfo->max_char_or_byte2;
  if (first<32) first=32;
  if (last>127) last=127;

  LettersDL=glGenLists(last+1);
  if (LettersDL==0) return;
  glXUseXFont(id, first, last-first+1, LettersDL+first);
  
}
예제 #8
0
파일: glc.c 프로젝트: cout/mglc
/* Create a new GLC context and return its ID */
GLint glcGenContext() {
	GLCcontext *c;
	int i, j;

	/* If this is the first call, initialize our data */
	if(numGlcContexts==0) {
		memset(glcContextList, 0, sizeof(glcContextList));
		memset(glcContexts, 0, sizeof(glcContexts));
	}
	isFirstCall = FALSE;

	/* Find context that is not in use */
	for(j = 1; j < MAX_GLC_CONTEXTS; j++)
		if(!glcContexts[j].isContext) break;
	if(j == MAX_GLC_CONTEXTS) return 0;

	/* Add this context to the list */
	glcContextList[numGlcContexts++] = j;
	glcContextList[numGlcContexts] = 0;

	/* Initialize this context */
	c = &glcContexts[j];
	c->isContext = TRUE;
	c->display = (Display*)glXGetCurrentDisplay();
	c->bitmap_matrix[0] = 1.0;
	c->bitmap_matrix[1] = 0.0;
	c->bitmap_matrix[2] = 0.0;
	c->bitmap_matrix[3] = 1.0;
	c->bitmap_scale[0] = 1.0;
	c->bitmap_scale[1] = 1.0;
	last_error = GLC_NONE;
	c->data_pointer = 0;
	c->num_fonts = 0;
	c->list_base = glGenLists(256);
	c->reload_font = TRUE;
	c->scale_change = TRUE;
	memcpy(c->bitmap_matrix, identity_matrix_2_by_2, sizeof(c->bitmap_matrix));

	/* Turn on synchronization.  This does not affear to affect performance,
	 * and seems to keep my X server from crashing.  Still, this should
	 * not be necessary, and an alternative solution would probably be
	 * preferable.
	 */
	XSynchronize(c->display, TRUE);

	/* Load a default font */
	memset(c->font_list, 0, sizeof(c->font_list));
	c->fonts[0][GLC_STYLE_NORMAL].xfontinfo = XLoadQueryFont(c->display, "variable");
	c->fonts[0][GLC_STYLE_NORMAL].xfont = c->fonts[0][GLC_STYLE_NORMAL].xfontinfo->fid;
	c->fonts[0][GLC_STYLE_NORMAL].name = strdup("base");
	c->fonts[0][GLC_STYLE_NORMAL].xfontprefix =
	c->fonts[0][GLC_STYLE_NORMAL].xfontsuffix = strdup("");
	c->fonts[0][GLC_STYLE_NORMAL].isFont = TRUE;
	glXUseXFont(c->fonts[0][GLC_STYLE_NORMAL].xfont, 0, 256, c->list_base);
	for(i = 1; i < NUM_GLC_STYLES; i++) c->fonts[0][i].isFont = FALSE;

	return j;
}
예제 #9
0
static PangoFont *
gdk_gl_font_use_pango_font_common (PangoFontMap               *font_map,
                                   const PangoFontDescription *font_desc,
                                   int                         first,
                                   int                         count,
                                   int                         list_base)
{
  PangoFont *font = NULL;
  gchar *charset = NULL;
  PangoXSubfont subfont_id;
  gchar *xlfd = NULL;
  PangoXFontCache *font_cache;
  XFontStruct *fs;

  GDK_GL_NOTE_FUNC_PRIVATE ();

  font = pango_font_map_load_font (font_map, NULL, font_desc);
  if (font == NULL)
    {
      g_warning ("cannot load PangoFont");
      goto FAIL;
    }

  charset = gdk_gl_font_charset_for_locale ();
  if (!pango_x_find_first_subfont (font, &charset, 1, &subfont_id))
    {
      g_warning ("cannot find PangoXSubfont");
      font = NULL;
      goto FAIL;
    }

  xlfd = pango_x_font_subfont_xlfd (font, subfont_id);
  if (xlfd == NULL)
    {
      g_warning ("cannot get XLFD");
      font = NULL;
      goto FAIL;
    }

  font_cache = pango_x_font_map_get_font_cache (font_map);

  fs = pango_x_font_cache_load (font_cache, xlfd);

  glXUseXFont (fs->fid, first, count, list_base);

  pango_x_font_cache_unload (font_cache, fs);

 FAIL:

  if (charset != NULL)
    g_free (charset);

  if (xlfd != NULL)
    g_free (xlfd);

  return font;
}
예제 #10
0
파일: HGUglText.c 프로젝트: ma-tech/HGUX
/*!
* \ingroup	HGU_GL
* \brief	Creates an HGUgl text font instance using the given X11
* 		font.
* \param	xFont			Given X11 font.
*/
HGUglTextFont	*HGUglTextFontCreate(Font xFont)
{
  HGUglTextFont	*newFnt;

  newFnt = (HGUglTextFont *)malloc(sizeof(HGUglTextFont));
  if(newFnt)
  {
    newFnt->xFont = xFont;
    newFnt->bitmapBase = glGenLists(256);
    glXUseXFont(xFont, 0, 256, newFnt->bitmapBase);
  }
  return(newFnt);
}
예제 #11
0
파일: x11gui.cpp 프로젝트: jefferis/rgl
// ---------------------------------------------------------------------------
void X11WindowImpl::initGLFont()
{
  if (beginGL()) {
    font.nglyph     = GL_BITMAP_FONT_COUNT;
    font.firstGlyph = GL_BITMAP_FONT_FIRST_GLYPH;
    GLuint listBase = glGenLists(font.nglyph);
    font.listBase   = listBase - font.firstGlyph;
    glXUseXFont(factory->xfont, font.firstGlyph, font.nglyph, listBase);

    font.widths = new unsigned int[font.nglyph];

    for(unsigned int i=0;i<font.nglyph;i++)
      font.widths[i] = 9;
    endGL();  // Should this be added?
  }
}
예제 #12
0
파일: glc.c 프로젝트: cout/mglc
/* reloadFont() is a local function that deletes the current display list
 * and re-creates it using the font specified in current_font_list[0].
 * FIX ME!!  We should not use display lists for texture-mapped fonts (which
 * aren't supported yet anyway), and if we are to support font maps, then
 * we should be able to load more than one font at a time into the font
 * list.  As is, we can load more than one font, but we will only use the
 * first font loaded.
 */
static void reloadFont() {
	char fontbuf[2048], matbuf[256];
	int i = g->current_font_list[0], j;
	GLCfont *f = &g->fonts[i][g->font_faces[i]];

	/* If we changed scale (or changed font faces), then we need to
	 * reload the xfontinfo structure, which keeps track of the size
	 * of the current font.
	 */
	if(g->scale_change) {
		if(f->can_transform) {
			snprintf(matbuf, sizeof(matbuf), "[%f %f %f %f]",
				g->bitmap_scale[0], 0.0,
				0.0, g->bitmap_scale[1]);
			for(j = 0; matbuf[j] != 0; j++) if(matbuf[j] == '-') matbuf[j] = '~';
			snprintf(fontbuf, sizeof(fontbuf), "%s-%s-%s",
				f->xfontprefix, matbuf, f->xfontsuffix);
		} else {
			snprintf(fontbuf, sizeof(fontbuf), "%s-%d-%s",
				f->xfontprefix, (int)g->bitmap_scale[0], f->xfontsuffix);
		}
		if(f->xfontinfo) XFreeFont(g->display, f->xfontinfo);
		f->xfontinfo = XLoadQueryFont(g->display, fontbuf);
#ifdef DEBUG
		fprintf(stderr, "Reloading font info for %s\n", fontbuf);
#endif
		g->scale_change = FALSE;
	}

	/* We ALWAYS need to reload the display list (unless we are using
	 * texture-mapped fonts)
	 */
	if(f->can_transform) {
		snprintf(matbuf, sizeof(matbuf), "[%f %f %f %f]",
			g->bitmap_matrix[0], g->bitmap_matrix[1],
			g->bitmap_matrix[2], g->bitmap_matrix[3]);
		for(j = 0; matbuf[j] != 0; j++) if(matbuf[j] == '-') matbuf[j] = '~';
		snprintf(fontbuf, sizeof(fontbuf), "%s-%s-%s",
			f->xfontprefix, matbuf, f->xfontsuffix);
	}
	if(f->xfont) XUnloadFont(g->display, f->xfont);
	f->xfont = XLoadFont(g->display, fontbuf);
	glXUseXFont(f->xfont, 0, 256, g->list_base);
	g->reload_font = FALSE;

}
예제 #13
0
static void GLW_GenDefaultLists() {
	// keep going, we'll probably just leak some stuff
	if ( fontbase_init ) {
		common->DPrintf( "ERROR: GLW_GenDefaultLists: font base is already marked initialized\n" );
	}

	XFontStruct* fontInfo = XLoadQueryFont( dpy, "-*-helvetica-medium-r-normal-*-12-*-*-*-p-*-*-*" );
	if ( fontInfo == NULL ) {
		// try to load other fonts
		fontInfo = XLoadQueryFont( dpy, "-*-helvetica-*-*-*-*-*-*-*-*-*-*-*-*" );

		// any font will do !
		if ( fontInfo == NULL ) {
			fontInfo = XLoadQueryFont( dpy, "-*-*-*-*-*-*-*-*-*-*-*-*-*-*" );
		}

		if ( fontInfo == NULL ) {
			common->Printf( "ERROR: couldn't create font (XLoadQueryFont)\n" );
			return;
		}
	}

	unsigned int first = fontInfo->min_char_or_byte2;
	unsigned int last = fontInfo->max_char_or_byte2;
	unsigned int firstrow = fontInfo->min_byte1;
	unsigned int lastrow = fontInfo->max_byte1;
	//	How many chars in the charset
	int maxchars = 256 * lastrow + last;
	gl_NormalFontBase = glGenLists( maxchars + 1 );
	if ( gl_NormalFontBase == 0 ) {
		common->Printf( "ERROR: couldn't create font (glGenLists)\n" );
		return;
	}

	//	Get offset to first char in the charset
	int firstbitmap = 256 * firstrow + first;

	//	for each row of chars, call glXUseXFont to build the bitmaps.
	for ( int i = firstrow; i <= ( int )lastrow; i++ ) {
		// http://www.atomised.org/docs/XFree86-4.2.1/lib_2GL_2glx_2glxcmds_8c-source.html#l00373
		glXUseXFont( fontInfo->fid, firstbitmap, last - first + 1, gl_NormalFontBase + firstbitmap );
		firstbitmap += 256;
	}

	fontbase_init = true;
}
예제 #14
0
GLuint Sys_LoadBmpFont(const char *fontname) {
    XFontStruct *font;
    GLuint base = glGenLists(96);

    font = XLoadQueryFont(g_Window.display, fontname);
    if (font == NULL) {
        font = XLoadQueryFont(g_Window.display, "fixed");
        if (font == NULL) {
            fprintf(stderr, "Can't load font\n");
            exit(1);
        }
    }

    glXUseXFont(font->fid, 32, 96, base);

    /* free the font since it's been loaded into a display list */
    XFreeFont(g_Window.display, font);
    return base;
}
예제 #15
0
void QGLContext::generateFontDisplayLists(const QFont & fnt, int listBase)
{
    QFont f(fnt);
    QFontEngine *engine = f.d->engineForScript(QUnicodeTables::Common);

    if (engine->type() == QFontEngine::Multi)
        engine = static_cast<QFontEngineMulti *>(engine)->engine(0);
#ifndef QT_NO_FONTCONFIG
    if(engine->type() == QFontEngine::Freetype) {
        qgl_use_font(static_cast<QFontEngineFT *>(engine), 0, 256, listBase);
        return;
    }
#endif
    // glXUseXFont() only works with XLFD font structures and a few GL
    // drivers crash if 0 is passed as the font handle
    f.setStyleStrategy(QFont::OpenGLCompatible);
    if (f.handle() && engine->type() == QFontEngine::XLFD)
        glXUseXFont(static_cast<Font>(f.handle()), 0, 256, listBase);
}
예제 #16
0
파일: qgl_x11.cpp 프로젝트: aroraujjwal/qt3
void QGLContext::generateFontDisplayLists( const QFont & fnt, int listBase )
{
    QFont f(fnt);
    QFontEngine *engine = f.d->engineForScript(QFont::Latin);

#ifndef QT_NO_XFTFREETYPE
    if(engine->type() == QFontEngine::Xft) {
	qgl_use_font((QFontEngineXft *) engine, 0, 256, listBase);
	return;
    }
#endif
    // glXUseXFont() only works with XLFD font structures and a few GL
    // drivers crash if 0 is passed as the font handle
    f.setStyleStrategy(QFont::OpenGLCompatible);
    if (f.handle() && (engine->type() == QFontEngine::XLFD
		       || engine->type() == QFontEngine::LatinXLFD)) {
 	glXUseXFont((Font) f.handle(), 0, 256, listBase);
    }
}
예제 #17
0
void gl_font(Fl_Font font, float size)
{
    fl_font(font, size);         // necessary so fl_measure() works
    size = fl_size();            // get the rounded value
    if (!current || current->font != font || current->size != size)
    {
        FontSize** p = &root;
        while (*p)
        {
            if (font < (*p)->font) p = &((*p)->left);
            else if (font > (*p)->font) p = &((*p)->right);
            else if (size < (*p)->size) p = &((*p)->left);
            else if (size > (*p)->size) p = &((*p)->right);
            else {current = *p; goto GOTIT;}
        }
        *p = current = new FontSize;
        current->font = font;
        current->size = size;
        current->left = current->right = 0;
        current->listbase = glGenLists(256);
#ifdef _WIN32
        int base = fl_textmetric()->tmFirstChar;
        int size = fl_textmetric()->tmLastChar - base + 1;
        HDC hdc = GetDC(0);
        HFONT oldFid = (HFONT)SelectObject(hdc, fl_xfont());
        wglUseFontBitmaps(hdc, base, size, current->listbase+base);
        SelectObject(hdc, oldFid);
#else
        XFontStruct* xfont = fl_xfont();
#if USE_XFT
        current->xfont = xfont;
#endif
        int base = xfont->min_char_or_byte2;
        int size = xfont->max_char_or_byte2-base+1;
        glXUseXFont(xfont->fid, base, size, current->listbase+base);
#endif
    }
GOTIT:
    glListBase(current->listbase);
}
예제 #18
0
unsigned int SingleOpenGLWindowImplT::GetSystemFontDisplayList(int Height, const char* Name)
{
    GLuint FontDisplayList=glGenLists(256);

#ifdef _WIN32
    HFONT Font=CreateFont(-Height,                          // Height of font (character height)
                          0,                                // Width of font
                          0,                                // Angle of escapement
                          0,                                // Orientation angle
                          FW_BOLD,                          // Font weight
                          false, false, false,              // Italic, Underline, Strikeout
                          ANSI_CHARSET,                     // Character set identifier
                          OUT_TT_PRECIS,                    // Output Precision
                          CLIP_DEFAULT_PRECIS,              // Clipping Precision
                          ANTIALIASED_QUALITY,              // Output Quality
                          FF_DONTCARE | DEFAULT_PITCH,      // Family and Pitch
                          Name);                            // Font name

    if (!FontDisplayList) return 0;
    if (!Font) return 0;

    SelectObject(hDC, Font);
    wglUseFontBitmaps(hDC, 0, 256, FontDisplayList);
#else
    // See xfontsel for more information about X Logical Font Descriptions.
    static char XLFD[256];

    // "-adobe-times-medium-r-normal--17-120-100-100-p-88-iso8859-1"
    sprintf(XLFD, "-*-%s-*-r-*-*-%i-*-*-*-*-*-*-*", Name, Height);
    XFontStruct* FontInfo=XLoadQueryFont(DisplayPtr, XLFD);

    if (!FontDisplayList) return 0;
    if (!FontInfo) return 0;

    glXUseXFont(FontInfo->fid, 0, 256, FontDisplayList);
    XFreeFont(DisplayPtr, FontInfo);
#endif

    return FontDisplayList;
}
예제 #19
0
//--------------------------INITIALIZATION------------------
void initGL(Display * dpy, Window win, GLuint pHandle
#ifdef SHOW_TEXT
, XFontStruct * font
#endif
) {
	gla.position = glGetAttribLocation(pHandle, "position");
	gla.color = glGetAttribLocation(pHandle, "color");

#ifdef SHOW_TEXT
	int first = font->min_char_or_byte2;
	int last = font->max_char_or_byte2;
	gla.font_base = glGenLists(last + 1);
	glXUseXFont(font->fid, first, last - first + 1, gla.font_base + first);

	gla.font_width = font->max_bounds.width;
	gla.font_height = font->max_bounds.ascent - font->max_bounds.descent;
#endif

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glGenBuffers(1, &gla.array_buffer);
}
예제 #20
0
static Bool
load_font (ModeInfo *mi, char *res, XFontStruct **fontP, GLuint *dlistP)
{
#ifdef STANDALONE
  const char *font = get_string_resource (res, "Font");
#else
  const char *font = res;
#endif
  XFontStruct *f;
  Font id;
  int first, last;

  if (!font) font = "-*-times-bold-r-normal-*-180-*";

  f = XLoadQueryFont(MI_DISPLAY(mi), font);
  if (!f) f = XLoadQueryFont(MI_DISPLAY(mi), "fixed");

  id = f->fid;
  first = f->min_char_or_byte2;
  last = f->max_char_or_byte2;

  clear_gl_error ();
  *dlistP = glGenLists ((GLuint) last+1);
  if (check_gl_error ("glGenLists"))
	return False;
  /*-
   * PURIFY reports a cumulative memory leak on the next line with Mesa 3.4.1
   * on Solaris 2.X and SunOS 4.1.X. This can be fixed with a patch to Mesa
   * 3.4.1. OpenGL on Solaris does not have the memory leak.
   */
  glXUseXFont(id, first, last-first+1, *dlistP + first);
  if (check_gl_error ("glXUseXFont"))
	return False;

  *fontP = f;
  return True;
}
예제 #21
0
int main(int argc, char *argv[])
{
char*			command_name;
char*			display_name;
Display*		display;
Window			window;
int			scrnum;
Window			root;
int			x, y;
GLXContext		context;
XVisualInfo*		vinfo;
XSetWindowAttributes	winattrs;
XFontStruct*		font;
unsigned long		winmask;
static const char* getopt_string = "sf::ima::r:vh";
static const struct option longopts[] =
{
	{ "full", no_argument, NULL, 's' },
	{ "fps", optional_argument, NULL, 'f' },
	{ "info", no_argument, NULL, 'i' },
	{ "fsaa", no_argument, NULL, 'm' },
	{ "aniso", optional_argument, NULL, 'a' },
	{ "runlength", required_argument, NULL, 'r' },
	{ "version", no_argument, NULL, 'v' },
	{ "help", no_argument, NULL, 'h' },
	{ 0, 0, 0, 0 }
};
static const char* x11font = "-*-courier-bold-r-normal--14-*-*-*-*-*-*-*";
static int		attributes[] = {
					GLX_RGBA,
					GLX_DOUBLEBUFFER,
					GLX_RED_SIZE, 8,
					GLX_GREEN_SIZE, 8,
					GLX_BLUE_SIZE, 8,
					GLX_ALPHA_SIZE, 8,
					GLX_DEPTH_SIZE, 24,
					0
					};

/* Comman line arguments processing */

command_name = basename(argv[0]);

while (1)
{
	int c = getopt_long(argc, argv, getopt_string, longopts, NULL);

	if (c == -1)
		break;

	switch (c)
	{
	case 's':
		full_screen = GL_TRUE;
		break;
	case 'f':
		if( optarg == NULL )
		{
			print_fps = GL_TRUE;
		}
		else
			if( ( Timed = (GLfloat)atof(optarg) ) > 0.0f )
				print_fps = GL_TRUE;
			else
			{
				printf("<!> Time slice for fps computation must be greater than 0\n");
				return 0;
			}

		break;
	case 'i':
		print_info = GL_TRUE;
		break;
	case 'm':
		enable_fsaa = GL_TRUE;
		break;
	case 'a':
		if( optarg == NULL )
		{
			enable_anisotropic = GL_TRUE;
			AnisoLevel = 16.0f;
		}
		else
			if( ( AnisoLevel = (GLfloat)atof(optarg) ) > 0.0f )
				if( 	( AnisoLevel ==  2.0f ) ||
					( AnisoLevel ==  4.0f ) ||
					( AnisoLevel ==  8.0f ) ||
					( AnisoLevel == 16.0f ) )
						enable_anisotropic = GL_TRUE;
				else
				{
					printf("<!> Incorrect anisotropic filtering level specified, must be 2, 4, 8 or 16\n");
					return 0;
				}
			else
			{
				printf("<!> Incorrect anisotropic filtering level specified, must be 2, 4, 8 or 16\n");
				return 0;
			}

		break;
	case 'r':
		if( ( max_timer = (GLfloat)atof(optarg) ) > 0.0f )
			use_timer = GL_TRUE;
		else
		{
			printf("<!> Timer must be greater than 0\n");
			return 0;
		}

		break;
	case 'v':
		printf("Version: " VERSION "\n");
		return 0;
	case 'h':
		printf("Usage: %s [OPTIONS]...\n"
				"%s is an OpenGL rendering demo.\n"
				"   -s, --full         : display full screen\n"
				"   -f[t], --fps[=t]   : display frames per second every t seconds (default 5)\n"
				"   -i, --info         : display X11/OpenGL and program info\n"
				"   -m, --fsaa         : enable anti-aliasing\n"
				"   -a[l], --aniso[=l] : enable xl anisotropic filtering (default 16)\n"
				"   -rL, --runlength=L : run the demo for L secs, then exit\n"
				"   -v, --version      : display version and exit\n",
				"   -h, --help         : display this information\n",
				command_name, command_name
		);
		return 0;
	case '?':
	case ':':
		exit(-1);
	}
}

/* Set signal handlers */

act.sa_handler = signal_handler;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;

if( (sigaction(SIGINT, &act, &oact) < 0)
	|| (sigaction(SIGTERM, &act, &oact) < 0)
	|| (sigaction(SIGHUP, &act, &oact) < 0) )
{
	printf("<!> Setting signal handler failed\n");
	return 1;
}

/* Open the connection to the X server */

display_name = getenv("DISPLAY");
display = XOpenDisplay(display_name);

if (!display)
{
	printf("<!> Couldn't open display %s\n", display_name);
	return 1;
}
else if (print_info)
	printf("<-> Name of display: %s\n", DisplayString(display));

/* Find the proper visual */

scrnum = DefaultScreen( display );
root = RootWindow( display, scrnum );

x = 0; y = 0;

if (full_screen)
{
	width = DisplayWidth( display, scrnum );
	height = DisplayHeight( display, scrnum );
}
else
{
	width = DisplayWidth( display, scrnum )*3/4;
	height = DisplayHeight( display, scrnum )*3/4;
}

vinfo = glXChooseVisual(display, scrnum, attributes);

if (!vinfo)
{
	printf("<!> Couldn't get an RGB, Double-buffered visual\n");
	return 1;
}
else if (print_info)
	printf("<-> Visual ID: %x\n", vinfo->visualid);

/* Create the window */

winattrs.event_mask =	ExposureMask | StructureNotifyMask |
			ButtonPressMask | ButtonReleaseMask |
			PointerMotionMask | KeyPressMask;

winattrs.background_pixel = BlackPixel(display, scrnum);
winattrs.border_pixel = BlackPixel(display, scrnum);
winattrs.bit_gravity = StaticGravity;
winattrs.colormap = XCreateColormap( display, root, vinfo->visual, AllocNone);
winattrs.override_redirect = full_screen;

winmask = CWBitGravity | CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect;

window = XCreateWindow( display, root,
			x, y, width, height, 0, vinfo->depth, InputOutput,
			vinfo->visual, winmask, &winattrs );

XChangeProperty(display, window, XA_WM_NAME, XA_STRING, 8, 0,
		command_name, strlen(argv[0]));
XChangeProperty(display, window, XA_WM_ICON_NAME, XA_STRING, 8, 0,
		command_name, strlen(argv[0]));

/* Create the OpenGL context */

context = glXCreateContext(display, vinfo, 0, True);

if (!context)
{
	printf("<!> glXCreateContext failed\n");
	return 1;
}

XFree(vinfo);

XMapWindow( display, window );
glXMakeCurrent( display, window, context );

/* Print info */

if (print_info)
{
	printf("<-> GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
	printf("<-> GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
	printf("<-> GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
	printf("<-> GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
}

/* Setup fonts */
if( ( font = XLoadQueryFont(display, x11font) ) == NULL )
{
	//Try fallback first
	if( ( font = XLoadQueryFont(display, "fixed") ) == NULL )
	{
		printf("<!> Can't load font \"%s\"\n", x11font);
		return -1;
	}
	else if (print_info)
		printf("<-> Loaded font \"fixed\"\n");
}
else if (print_info)
	printf("<-> Loaded font \"%s\"\n", x11font);

fps_font = glGenLists(96);
glXUseXFont(font->fid, ' ', 96, fps_font);


/* Setup Rendering Context */

if (setup())
{
	printf("<!> Setup failed, exiting ...\n");
	return 1;
}

/* Event loop */

event_loop( display, window );

/* Print average fps */
printf("Average FPS: %.1f\n", fps_mean);

/* Clean up */

// Delete shader identifiers
glDeleteProgramsARB(NUM_SHADERS, ids);

// Delete shader objects
glDeleteObjectARB(progObj);

//Texture objects
glDeleteTextures( NUM_TEXTURES, texture_id );
if (texture_id)
	free(texture_id);

//Lists
glDeleteLists(fps_font, 96);
glDeleteLists(FList, 1);

//MD2 models
int model_id;

for (model_id = 0; model_id < NUM_MODELS; ++model_id)
	if (md2_model[model_id])
	{
		if (md2_model[model_id]->normal)
		{
			free(md2_model[model_id]->normal);
			md2_model[model_id]->normal = NULL;
		}
		if (md2_model[model_id]->skin)
		{
			free(md2_model[model_id]->skin);
			md2_model[model_id]->skin = NULL;
		}
		free(md2_model[model_id]);
		md2_model[model_id] = NULL;
	}
	
//Floor
if (floor_texture)
{
	free(floor_texture);
	floor_texture = NULL;
}

//Destroy FB objects
glDeleteTextures(1, &shadow_tx);
glDeleteFramebuffersEXT(1, &FBO);

glXDestroyContext( display, context );
XDestroyWindow( display, window );
XCloseDisplay( display );

if( print_info )
	printf("Program exit successfully\n");

return 0;
}
예제 #22
0
bool CGLTxtFontX11::Create()
{
	if( !m_poDisplay )
		return false;

	Destroy();

	//UpdatePixelExt();

	Font id;
	int first, last, firstbitmap, i;
	int firstrow, lastrow;
	int maxchars;


	m_poFont = XLoadQueryFont( m_poDisplay, m_pcFont );
	if( !m_poFont )
		return false;

	long unsigned int luiValue;
	//if( XGetFontProperty( m_poFont, XA_X_HEIGHT, &luiValue ) ) {
	//	m_uiSize = luiValue;
	//	GLTXT_LOG( "font size: %li\n", luiValue );
	//}

	if( XGetFontProperty( m_poFont, XA_FONT, &luiValue ) )
	{
		char *pcFontName = XGetAtomName( m_poDisplay, (Atom)luiValue );
		GLTXT_LOG( "font name: %s\n", pcFontName );

		const char *pcStartSize = 0;
		unsigned int c = 0;
		while( *pcFontName )
		{
			if( *pcFontName == '-' )
			{
				++c;
				if( c == 7 )
				{
					pcStartSize = pcFontName + 1;
				}
				else if( c == 8 )
				{
					*pcFontName = '\0';
					m_uiSize = atoi( pcStartSize );
					GLTXT_LOG( "font pixel size: %d\n", m_uiSize );
					break;
				}
			}
			pcFontName++;
		}
	}
	id = m_poFont->fid;

	// First and Last char in a row of chars.
	first = (int)m_poFont->min_char_or_byte2;
	last = (int)m_poFont->max_char_or_byte2;

	// First and Last row of chars, important for multibyte charset's.
	firstrow = (int)m_poFont->min_byte1;
	lastrow = (int)m_poFont->max_byte1;

	// How many chars in the charset.
	maxchars = 256 * lastrow + last;
	InitDisplayLists( glGenLists(maxchars+1) );

	// Get offset to first char in the charset.
	firstbitmap = 256 * firstrow + first;

	// for each row of chars, call glXUseXFont to build the bitmaps.
	for( i=firstrow; i<=lastrow; i++ )
	{
		glXUseXFont( id, firstbitmap, last-first+1, m_uiLstBase+firstbitmap );
		firstbitmap += 256;
	}

	return true;
}
예제 #23
0
/* Loads the font named by the X resource "res".
   Returns an XFontStruct.
   Also converts the font to a set of GL lists and returns the first list.
*/
void
load_font (Display *dpy, char *res, XFontStruct **font_ret, GLuint *dlist_ret)
{
    XFontStruct *f;
#ifdef STANDALONE
    const char *font = get_string_resource (dpy, res, "Font");
#else
    const char *font = NULL;
#endif
    const char *def1 = "-*-helvetica-medium-r-normal-*-180-*";
    const char *def2 = "fixed";
    Font id;
    int first, last;

    if (!res || !*res) abort();
    if (!font_ret && !dlist_ret) abort();

    if (!font) font = def1;

    f = XLoadQueryFont(dpy, font);
    if (!f && !!strcmp (font, def1))
    {
        fprintf (stderr, "%s: unable to load font \"%s\", using \"%s\"\n",
                 progname, font, def1);
        font = def1;
        f = XLoadQueryFont(dpy, font);
    }

    if (!f && !!strcmp (font, def2))
    {
        fprintf (stderr, "%s: unable to load font \"%s\", using \"%s\"\n",
                 progname, font, def2);
        font = def2;
        f = XLoadQueryFont(dpy, font);
    }

    if (!f)
    {
        fprintf (stderr, "%s: unable to load fallback font \"%s\" either!\n",
                 progname, font);
        exit (1);
    }

    id = f->fid;
    first = f->min_char_or_byte2;
    last = f->max_char_or_byte2;


# ifndef HAVE_COCOA /* Xlib version */

    if (dlist_ret)
    {
        clear_gl_error ();
        *dlist_ret = glGenLists ((GLuint) last+1);
        check_gl_error ("glGenLists");
        glXUseXFont(id, first, last-first+1, *dlist_ret + first);
        check_gl_error ("glXUseXFont");
    }

# else  /* HAVE_COCOA */

    {
        int afid, face, size;
        afid = jwxyz_font_info (id, &size, &face);

        if (dlist_ret)
        {
            clear_gl_error ();
            *dlist_ret = glGenLists ((GLuint) last+1);
            check_gl_error ("glGenLists");

            AGLContext ctx = aglGetCurrentContext();
            if (! aglUseFont (ctx, afid, face, size,
                              first, last-first+1, *dlist_ret + first)) {
                check_gl_error ("aglUseFont");
                abort();
            }
        }
    }

# endif  /* HAVE_COCOA */

    if (font_ret)
        *font_ret = f;
}
예제 #24
0
void draw(xcb_connection_t *connection, xcb_screen_t *screen, xcb_window_t window) {
    if (NULL != testcase) {
        DRAW_FUNC pf = (DRAW_FUNC)dlsym(0, testcase);
        if (NULL != pf) {
            fprintf(stderr, "call %s \n", testcase);
            pf();
            return;
        }
    }

    //get_version();
   
    xcb_font_t font = xcb_generate_id(connection);
    xcb_void_cookie_t cookie_font = xcb_open_font_checked(connection, font, strlen(font_name_pattern), font_name_pattern);
    xcb_generic_error_t *error = xcb_request_check(connection, cookie_font);
    if (error) {
        fprintf(stderr, "ERROR: can't open font :%d\n", error->error_code);
        xcb_disconnect(connection);
        exit(0);
    }
    
    xcb_gcontext_t gc = xcb_generate_id(connection);
    uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_BACKGROUND | XCB_GC_FONT;
    uint32_t value_list[3];
    value_list[0] = screen->black_pixel;
    value_list[1] = screen->white_pixel;
    value_list[2] = font;
    xcb_void_cookie_t cookie_gc = xcb_create_gc_checked(connection, gc, window, mask, value_list);
    error = xcb_request_check(connection, cookie_gc);
    if (error) {
        fprintf(stderr, "ERROR: can't create gc: %d\n", error->error_code);
        xcb_disconnect(connection);
        exit(0);
    }

    cookie_font = xcb_close_font_checked(connection, font);
    error = xcb_request_check(connection, cookie_font);
    if (error) {
        fprintf(stderr, "ERROR: can't close font: %d\n", error->error_code);
        xcb_disconnect(connection);
        exit(0);
    }
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush();

    glColor3f(1.0f, 0.0f, 0.0f);
    glRasterPos2f(0.0f, 0.0f);
    glPushAttrib(GL_LIST_BIT);

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    static int isFirstCall = 1;
    static GLuint lists;
    if (isFirstCall) {
        lists = glGenLists(128);
    }
#if 1 
    //for (i = 0; i < sizeof(letters)
    glNewList(lists + 'A', GL_COMPILE);
    glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, letters[0]);
    glEndList();
    GLubyte *str = (GLubyte*)"A";
#else
    glXUseXFont(font, 0, 128, lists);
    GLubyte *str = (GLubyte*)"Hello, world.";
#endif
    glListBase(lists);
    glCallLists(strlen(str), GL_UNSIGNED_BYTE, str);
    glPopAttrib();
    glFlush();


/*    static int isFirstCall = 1;
    static GLuint lists;
    //load font
    //gen list
    if (isFirstCall) {
        lists = glGenLists(128);
    }

    glXUseXFont(font, 0, 128, lists);
    glListBase(lists);
    char *str = "Hello, world";
    for (; *str!='\0';++str) {
        glCallList(lists + *str);
    }
    glFlush();
    //glDeleteLists(lists, 256);
    //use font
    //draw text
    //unuse font?
    //delete list
    //unload font*/

    cookie_gc = xcb_free_gc(connection, gc);
    error = xcb_request_check(connection, cookie_gc);
    if (error) {
        fprintf(stderr, "ERROR: can't free gc: %d\n", error->error_code);
        xcb_disconnect(connection);
        exit(0);
    }
}
예제 #25
0
파일: main.c 프로젝트: kissthink/clabs
int glx_init( int fullscreen )
{
    int vi_attr[] =
    {
        GLX_RGBA,
        GLX_DOUBLEBUFFER,
        GLX_RED_SIZE,       4,
        GLX_GREEN_SIZE,     4,
        GLX_BLUE_SIZE,      4,
        GLX_DEPTH_SIZE,    16,
        None
    };

    XVisualInfo *vi;
    Window root_win;
    XWindowAttributes win_attr;
    XSetWindowAttributes set_attr;
    XFontStruct *fixed;
    XColor black =
    {
        0, 0, 0, 0, 0, 0
    };

    if( ( dpy = XOpenDisplay( NULL ) ) == NULL )
    {
        fprintf( stderr, "XOpenDisplay failed\n" );
        return( 1 );
    }

    if( ( vi = glXChooseVisual( dpy, DefaultScreen( dpy ),
                                vi_attr ) ) == NULL )
    {
        fprintf( stderr, "glXChooseVisual failed\n" );
        XCloseDisplay( dpy );
        return( 1 );
    }

    root_win = RootWindow( dpy, vi->screen );

    XGetWindowAttributes( dpy, root_win, &win_attr );

    width  = ( fullscreen ) ? win_attr.width  : 640;
    height = ( fullscreen ) ? win_attr.height : 480;

    set_attr.border_pixel = 0;

    set_attr.colormap =
        XCreateColormap( dpy, root_win, vi->visual, AllocNone );

    set_attr.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask |
                          ButtonReleaseMask | PointerMotionMask | StructureNotifyMask;

    set_attr.override_redirect = ( ( fullscreen ) ? True : False );

    win =
        XCreateWindow(
            dpy, root_win, 0, 0, width, height, 0, vi->depth,
            InputOutput, vi->visual, CWBorderPixel | CWColormap |
            CWEventMask | CWOverrideRedirect, &set_attr );

    XStoreName( dpy, win, AppTitle );
    XMapWindow( dpy, win );

    if( fullscreen )
    {
        XGrabKeyboard(  dpy, win, True, GrabModeAsync,
                        GrabModeAsync, CurrentTime );
    }
    else
    {
        wmDelete = XInternAtom( dpy, "WM_DELETE_WINDOW", True );
        XSetWMProtocols( dpy, win, &wmDelete, 1 );
    }

    if( ( ctx = glXCreateContext( dpy, vi, NULL, True ) ) == NULL )
    {
        fprintf( stderr, "glXCreateContext failed\n" );
        XDestroyWindow( dpy, win );
        XCloseDisplay( dpy );
        return( 1 );
    }

    if( glXMakeCurrent( dpy, win, ctx ) == False )
    {
        fprintf( stderr, "glXMakeCurrent failed\n" );
        glXDestroyContext( dpy, ctx );
        XDestroyWindow( dpy, win );
        XCloseDisplay( dpy );
        return( 1 );
    }

    font = glGenLists( 256 );

    fixed = XLoadQueryFont(
                dpy, "-misc-fixed-medium-r-*-*-20-*-*-*-*-*-*-*" );

    null_cursor = XCreateGlyphCursor(
                      dpy, fixed->fid, fixed->fid, ' ', ' ', &black, &black );

    glXUseXFont( fixed->fid, 0, 256, font );

    XFreeFont( dpy, fixed );

    return( 0 );
}