• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ FT_Load_Char函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中FT_Load_Char函数的典型用法代码示例。如果您正苦于以下问题:C++ FT_Load_Char函数的具体用法?C++ FT_Load_Char怎么用?C++ FT_Load_Char使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了FT_Load_Char函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: fprintf

void GSOsdManager::upload_texture_atlas(GSTexture* t) {
	if (!m_face) return;

	if (m_char_info.size() > 96) // we only reserved space for this many glyphs
		fprintf(stderr, "More than 96 glyphs needed for OSD");

	// This can be sped up a bit by only uploading new glyphs
	int x = 0;
	for(auto &pair : m_char_info) {
		if(FT_Load_Char(m_face, pair.first, FT_LOAD_RENDER)) {
			fprintf(stderr, "failed to load char U%d\n", (int)pair.first);
			continue;
		}

		// Size of char
		pair.second.ax = m_face->glyph->advance.x >> 6;
		pair.second.ay = m_face->glyph->advance.y >> 6;

		pair.second.bw = m_face->glyph->bitmap.width;
		pair.second.bh = m_face->glyph->bitmap.rows;

		pair.second.bl = m_face->glyph->bitmap_left;
		pair.second.bt = m_face->glyph->bitmap_top;

		GSVector4i r(x, 0, x+pair.second.bw, pair.second.bh);
		if (r.width())
			t->Update(r, m_face->glyph->bitmap.buffer, m_face->glyph->bitmap.pitch);

		if (r.width() > m_max_width) m_max_width = r.width();

		pair.second.tx = (float)x / m_atlas_w;
		pair.second.ty = (float)pair.second.bh / m_atlas_h;
		pair.second.tw = (float)pair.second.bw / m_atlas_w;

		x += pair.second.bw;
	}

	m_texture_dirty = false;
}
开发者ID:IlDucci,项目名称:pcsx2,代码行数:39,代码来源:GSOsdManager.cpp


示例2: FT_Load_Char

double PdfFontMetricsFreetype::UnicodeCharWidth( unsigned short c ) const
{
    FT_Error ftErr;
    double   dWidth = 0.0;


    if( static_cast<int>(c) < PODOFO_WIDTH_CACHE_SIZE ) 
    {
        dWidth = m_vecWidth[static_cast<unsigned int>(c)];
    }
    else
    {
        ftErr = FT_Load_Char( m_pFace, static_cast<FT_UInt>(c), FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP );
        if( ftErr )
            return dWidth;

        dWidth = m_pFace->glyph->metrics.horiAdvance * 1000.0 / m_pFace->units_per_EM;
    }

    return dWidth * static_cast<double>(this->GetFontSize() * this->GetFontScale() / 100.0) / 1000.0 +
        static_cast<double>( this->GetFontSize() * this->GetFontScale() / 100.0 * this->GetFontCharSpace() / 100.0);
}
开发者ID:TodorGrin,项目名称:boox-opensource,代码行数:22,代码来源:PdfFontMetricsFreetype.cpp


示例3: swfStrWidthUTF8

double swfStrWidthUTF8(const char *str, const pGEcontext gc, pDevDesc dd)
{
#ifdef SWF_DEBUG
    Rprintf("strWidthUTF8 called\n");
    Rprintf("** family = %s, str[0] = %d, str[1] = %d\n",
        gc->fontfamily, str[0], str[1]);
#endif
    /* Convert UTF-8 string to Unicode array */
    int maxLen = strlen(str);
    wchar_t *unicode = (wchar_t *) calloc(maxLen + 1, sizeof(wchar_t));
    int len = utf8towcs(unicode, str, maxLen);
    /* Get the font face object */
    FT_Face face = swfGetFTFace(gc);
    FT_Error err;
    double fontSize = gc->ps * gc->cex;
    double ratio = fontSize / face->units_per_EM;
    double width = 0.0;
    int i;
    /* Add up the 'advance' of each character */
    for(i = 0; i < len; i++)
    {
        err = FT_Load_Char(face, unicode[i], FT_LOAD_NO_SCALE);
        if(err)
        {
            errorcode(err);
            continue;
        }
        width += face->glyph->metrics.horiAdvance * ratio;
    }
    
    free(unicode);

#ifdef SWF_DEBUG
    Rprintf("** strWidthUTF8(width = %f)\n", width);
#endif

    return width;
}
开发者ID:cran,项目名称:R2SWF,代码行数:38,代码来源:swfDevice.c


示例4: render_text

void render_text(const std::string &str, FT_Face face, float x, float y, float sx, float sy) {
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	const FT_GlyphSlot glyph = face->glyph;

	for (auto c : str) {
		if (FT_Load_Char(face, c, FT_LOAD_RENDER) != 0)
			continue;

		glTexImage2D(GL_TEXTURE_2D, 0, GL_R8,
			glyph->bitmap.width, glyph->bitmap.rows,
			0, GL_RED, GL_UNSIGNED_BYTE, glyph->bitmap.buffer);

		const float vx = x + glyph->bitmap_left * sx;
		const float vy = y + glyph->bitmap_top * sy;
		const float w = glyph->bitmap.width * sx;
		const float h = glyph->bitmap.rows * sy;

		struct {
			float x, y, s, t;
		} data[6] = {
			{ vx    , vy    , 0, 0 },
			{ vx    , vy - h, 0, 1 },
			{ vx + w, vy    , 1, 0 },
			{ vx + w, vy    , 1, 0 },
			{ vx    , vy - h, 0, 1 },
			{ vx + w, vy - h, 1, 1 }
		};

		glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(float), data, GL_DYNAMIC_DRAW);
		glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
		glDrawArrays(GL_TRIANGLES, 0, 6);

		x += (glyph->advance.x >> 6) * sx;
		y += (glyph->advance.y >> 6) * sy;
	}

	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
}
开发者ID:LucaSeem2000,项目名称:Anothometry,代码行数:38,代码来源:main.cpp


示例5: strlen

/**
* Gets the width of a string. The width of a string is not necesserily
* the sum of all the widths of it's glyphs.
*
* @param text The string to return the width of.
* @return The width of a string.
*/
int OpenGLFont::getWidth(const std::string& text) const
{
	unsigned int w = 0;

	const char* ptr = text.c_str();
	size_t textlen = strlen(ptr);
	while (textlen > 0) {
		Uint32 c = UTF8_getch(&ptr, &textlen);
		if (c == UNICODE_BOM_NATIVE || c == UNICODE_BOM_SWAPPED) {
			continue;
		}

		FT_GlyphSlot slot = this->pmpl->face->glyph;

		// Load glyph image into the slot
		int error = FT_Load_Char(this->pmpl->face, c, FT_LOAD_DEFAULT);
		if (error) continue;

		w += (slot->advance.x >> 6);
	}

	return w;
}
开发者ID:TheJosh,项目名称:chaotic-rage,代码行数:30,代码来源:opengl_font.cpp


示例6: FT_New_Face

Face *FontManager::getFont(const std::string fontPath, const int size) {
    if (fonts.count(fontPath + std::to_string(size)) == 0) {
        FT_Face face;
        if (FT_New_Face(ft, fontPath.c_str(), 0, &face)) {
            std::cerr << "Could not create font with path=[" << fontPath << "]" << std::endl
            << "Creating with default path=[" << DEFAULT_FONT_PATH << "]" << std::endl;

            //if path is broken, this can be broken too, we need better error handling
            FT_New_Face(ft, DEFAULT_FONT_PATH.c_str(), 0, &face);
        }

        fonts[fontPath + std::to_string(size)] = new Face(glHelper, fontPath, size, face);
        FT_Set_Pixel_Sizes(face, 0, size);
        //now we should calculate what we have


        unsigned int w = 0;
        unsigned int h = 0;

        for (unsigned int i = 0; i < 256; i++) {
            if (FT_Load_Char(face, i, FT_LOAD_RENDER)) {
                fprintf(stderr, "Loading character %c failed!\n", i);
                continue;
            }

            w = std::max(w, face->glyph->bitmap.width);
            h = std::max(h, face->glyph->bitmap.rows);

        }

        std::cout << "atlas h: " << h << ", w " << w << std::endl;

        //now we have maximum size of the textures
    }

    return fonts[fontPath + std::to_string(size)];
}
开发者ID:enginmanap,项目名称:uberGame,代码行数:37,代码来源:FontManager.cpp


示例7: YE_LoadGlyph

static void YE_LoadGlyph(Font *font, FT_Face face, char c)
{
    FT_Error error = FT_Load_Char(face, c, FT_LOAD_RENDER);
    if (error)
    {
        Log(1, "[Font loader] Failed to load glyph \"%c\": %s", c, FTErrorString(error));
        return;
    }

    FT_GlyphSlot glyph = face->glyph;

    byte *image = YE_ConvertBitmap(&glyph->bitmap);

    auto size = Vector2i(glyph->bitmap.width, glyph->bitmap.rows);
    auto offset = Vector2f(glyph->metrics.horiBearingX>>6, -(size.y - (glyph->metrics.horiBearingY>>6)));
    auto advance = Vector2f(glyph->advance.x>>6, glyph->advance.y>>6);

    GLuint texture;
    GLenum origformat = GL_LUMINANCE;
    GLenum gpuformat = GL_LUMINANCE8;

    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);

    // Turn off mipmaps and enable linear interpolation
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glTexImage2D(GL_TEXTURE_2D, 0, gpuformat,
                 size.x, size.y,
                 0, // <----------------------------------------- old useless crap
                 origformat, GL_UNSIGNED_BYTE, image);

    font->SetGlyph(c, make_unique<Glyph>(texture, size, offset, advance));
    delete image;
}
开发者ID:DjSkaarj,项目名称:YayEvil,代码行数:37,代码来源:fontloader.cpp


示例8: swfMetricInfo

void swfMetricInfo(int c, const pGEcontext gc, double* ascent, double* descent, double* width, pDevDesc dd)
{
#ifdef SWF_DEBUG
    Rprintf("metricInfo called\n");
    Rprintf("** family = %s, c = %d\n", gc->fontfamily, c);
#endif
    pswfDesc swfInfo = (pswfDesc) dd->deviceSpecific;
    FT_Face face = swfGetFTFace(gc, swfInfo);
    FT_Error err;
    double fontSize = gc->ps * gc->cex;
    double ratio = fontSize / face->units_per_EM;
  
    if(c == 0) c = 77;
    if(c < 0)
    {
        c = -c;
    }
    
    /* c is the unicode of the character */
    FT_Set_Char_Size(face, 0, fontSize * 64, 72, 0);
    err = FT_Load_Char(face, c, FT_LOAD_NO_SCALE);
    if(err)
    {
        errorcode(err);
        *ascent = *descent = *width = 0.0;
        return;
    }
    
    *ascent = face->glyph->metrics.horiBearingY * ratio;
    *descent = face->glyph->metrics.height * ratio - *ascent;
    *width = face->glyph->metrics.horiAdvance * ratio;
#ifdef SWF_DEBUG
    Rprintf("** metricInfo(ascent = %f, descent = %f, width = %f)\n",
            *ascent, *descent, *width);
#endif
}
开发者ID:yixuan,项目名称:R2SWF-archive,代码行数:36,代码来源:swfDevice.c


示例9: create_font_atlas

void create_font_atlas(FontAtlas* fa, char* filename, unsigned int height) {
  Font f;
  if (!load_font(&f, filename)) {
    fprintf(stderr, "Couldn't load font from file: %s\n", filename);
  }
  FT_Set_Pixel_Sizes(f.face, 0, height);
  FT_GlyphSlot g = f.face->glyph;
  int roww = 0;
  int rowh = 0;
  fa->w = 0;
  fa->h = 0;
  memset(fa->c, 0, sizeof fa->c);
  /* Find minimum size for a texture holding all visible ASCII characters */
  for (int i = 32; i < 128; i++) {
    if (FT_Load_Char(f.face, i, FT_LOAD_RENDER)) {
      fprintf(stderr, "Loading character %c failed!\n", i);
      continue;
    }
    if (roww + g->bitmap.width + 1 >= MAXWIDTH) {
      fa->w = max(fa->w, roww);
      fa->h += rowh;
      roww = 0;
      rowh = 0;
    }
    roww += g->bitmap.width + 1;
    rowh = max(rowh, g->bitmap.rows);
  }

  fa->w = max(fa->w, roww);
  fa->h += rowh;

  init_atlas_texture(fa);
  copy_glyphs_to_texture(fa, &f);
  // Clean up
  delete_font(&f);
}
开发者ID:andrewrch,项目名称:orrery,代码行数:36,代码来源:text.c


示例10: Measure

		CharStruct Measure(Char const *string, int length=0)
		{
			if (not length) while (string[length]) ++length;

			CharStruct extent;
			for (int it = 0; it < length; ++it)
			{
				FT_Load_Char(face, string[it], FT_LOAD_NO_BITMAP);
				FT_Glyph_Metrics &meter = face->glyph->metrics;

				extent.advance += meter.horiAdvance;
				if (extent.ascent < meter.horiBearingY)
				{
					extent.ascent = meter.horiBearingY;
				}

				FT_Pos diff = meter.height - meter.horiBearingY;
				if (extent.descent < diff)
				{
					extent.descent = diff;
				}
			}
			return extent;
		}
开发者ID:JesseMaurais,项目名称:SGe,代码行数:24,代码来源:FreeType.hpp


示例11: SWFShape_addString

void SWFShape_addString(SWFShape shape, const wchar_t* str, size_t nchar,
                        double fontSize,
                        FT_Face face, FT_Outline_Funcs *funs)
{
    OutlineData data;
    FT_Outline outline;
    FT_Error err;
    int i;
    
    data.shape = shape;
    data.ratio_EM = fontSize / face->units_per_EM;
    data.deltax = 0.0;

    for(i = 0; i < nchar; i++)
    {
        /* str should be Unicode */
        err = FT_Load_Char(face, str[i], FT_LOAD_NO_SCALE);
        if(err)
        {
            errorcode(err);
            continue;
        }
        outline = face->glyph->outline;
        err = FT_Outline_Decompose(&outline, funs, &data);
        if(err)
        {
            errorcode(err);
            continue;
        }
        /* After we draw a character, we move the pen right to a distance
        of the advance */
        /* See the picture in
        http://www.freetype.org/freetype2/docs/tutorial/step2.html */
        data.deltax += face->glyph->metrics.horiAdvance * data.ratio_EM;
    }
}
开发者ID:yixuan,项目名称:R2SWF-archive,代码行数:36,代码来源:swfText.c


示例12: ShaderManager

void FreeTypeFont::initGlCmds()
{
	std::string vertex = vertexSource;
	std::string fragment = fragmentSource;
	mShaderManager = new ShaderManager(vertex, fragment, false);
	GLuint program = mShaderManager->getProgram();

	if (program == 0)
	{
		LOGE("In Font::initGlCmds() program is 0");
	}
	mHudMVPMatrixLocation = glGetUniformLocation(program, "u_mvpMatrix");
	mVetextLocation = glGetAttribLocation(program, "a_position");
	mTextureLocation = glGetAttribLocation(program, "a_texCoord");
	mSamplerLocation = glGetUniformLocation(program, "s_texture");
	mColorLocation = glGetUniformLocation(program, "u_color");

	glGenBuffers(1, &mVertexVBO);
	// Bind the VBO
	glBindBuffer(GL_ARRAY_BUFFER, mVertexVBO);

	if(FT_Load_Char(mFace, 'A', FT_LOAD_RENDER)) {
		LOGE("Could not load character 'X'\n");
		return ;
	}
	FT_GlyphSlot g = mFace->glyph;
	float sx = 2.0 / Scene::getInstance()->getWidth();
	float sy = 2.0 / Scene::getInstance()->getHeight();
	float x2 = 0.1 + g->bitmap_left * sx;
	float y2 = -0.1 - g->bitmap_top * sy;
	float w = g->bitmap.width * sx;
	float h = g->bitmap.rows * sy;

	GLfloat box[] = {
			x2,     -y2 ,
			x2 + w, -y2 ,
			x2,     -y2 - h,
			x2 + w, -y2 - h,
	};

	glGenTextures(1, &mTextureId);
	// Set the filtering mode
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	// Bind the texture
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, mTextureId);

	glTexImage2D(
	      GL_TEXTURE_2D,
	      0,
	      GL_ALPHA,
	      g->bitmap.width,
	      g->bitmap.rows,
	      0,
	      GL_ALPHA,
	      GL_UNSIGNED_BYTE,
	      g->bitmap.buffer
	    );

	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, mTextureData);
	//delete[] mTextureData;
	float sceneWidth = Scene::getInstance()->getWidth();
	float sceneHeight = Scene::getInstance()->getHeight();
	float a = g->bitmap.width / sceneWidth;
	float b = g->bitmap.rows / sceneHeight;

	glm::mat4 mModelMatrix = glm::mat4(1.0);
	mModelMatrix = glm::translate(mModelMatrix, glm::vec3(0.5, 0.5, 0));
	mModelMatrix = glm::scale(mModelMatrix, glm::vec3(a, b, 0));
	Scene::getInstance()->getCamera()->updateHudMVP(128, 128);
	mHudMVPMatrix = Scene::getInstance()->getCamera()->getHudMVP() * mModelMatrix;

	mGLHasInitialized = true;
}
开发者ID:eaglewangy,项目名称:Android3D,代码行数:79,代码来源:FreeTypeFont.cpp


示例13: fprintf

void Font::buildAtlas()
{
	//find the size we should use
	FT_GlyphSlot g = face->glyph;
	int w = 0;
	int h = 0;

	/*for(int i = 32; i < 128; i++)
	{
		if(FT_Load_Char(face, i, FT_LOAD_RENDER))
		{
			fprintf(stderr, "Loading character %c failed!\n", i);
			continue;
		}

		w += g->bitmap.width;
		h = std::max(h, g->bitmap.rows);
	}*/

	//the max size (GL_MAX_TEXTURE_SIZE) is like 3300
	w = 2048;
	h = 512;

	textureWidth = w;
	textureHeight = h;



	//create the texture
	glGenTextures(1, &textureID);
	glBindTexture(GL_TEXTURE_2D, textureID);

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	glPixelStorei(GL_PACK_ALIGNMENT, 1);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL);

	//copy the glyphs into the texture
	int x = 0;
	int y = 0;
	int maxHeight = 0;
	for(int i = 32; i < 128; i++)
	{
		if(FT_Load_Char(face, i, FT_LOAD_RENDER))
			continue;

		 //prints rendered texture to the console
		/*std::cout << "uploading at x: " << x << ", w: " << g->bitmap.width << " h: " << g->bitmap.rows << "\n";

		for(int k = 0; k < g->bitmap.rows; k++)
		{
			for(int j = 0; j < g->bitmap.width; j++)
			{
				if(g->bitmap.buffer[g->bitmap.width * k + j])
					std::cout << ".";
				else
					std::cout << " ";
			}
			std::cout << "\n";
		}*/

		if(x + g->bitmap.width >= textureWidth)
		{
			x = 0;
			y += maxHeight;
			maxHeight = 0;
		}

		if(g->bitmap.rows > maxHeight)
			maxHeight = g->bitmap.rows;

		glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, g->bitmap.width, g->bitmap.rows, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap.buffer);


		charData[i].texX = x;
		charData[i].texY = y;
		charData[i].texW = g->bitmap.width;
		charData[i].texH = g->bitmap.rows;
		charData[i].advX = g->metrics.horiAdvance >> 6;
		charData[i].advY = g->advance.y >> 6;
		charData[i].bearingY = g->metrics.horiBearingY >> 6;

		if(charData[i].texH > mMaxGlyphHeight)
			mMaxGlyphHeight = charData[i].texH;

		x += g->bitmap.width;
	}

	glBindTexture(GL_TEXTURE_2D, 0);

	//std::cout << "generated texture \"" << textureID << "\" (w: " << w << " h: " << h << ")" << std::endl;
}
开发者ID:batlol,项目名称:EmulationStation,代码行数:95,代码来源:Font.cpp


示例14: vw_LoadFontChar

//------------------------------------------------------------------------------------
// загрузка и генерация всех необходимых данных для символа (utf32)
//------------------------------------------------------------------------------------
eFontChar* vw_LoadFontChar(unsigned UTF32)
{
	// устанавливаем размеры
	if (FT_Set_Char_Size( InternalFace, InternalFontSize <<6, InternalFontSize <<6, 96, 96 ))
	{
		fprintf(stderr, "Can't set char size %i.", InternalFontSize);
		return 0;
	}


	// загрузка глифа нужного нам символа
	if (FT_Load_Char( InternalFace, UTF32, FT_LOAD_RENDER | FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT))
	{
		fprintf(stderr, "Can't load Char: %u\n", UTF32);
		return 0;
	}


	// создаем структуру FontChar
	eFontChar* NewChar;
	NewChar = new eFontChar;

	NewChar->UTF32 = UTF32;
	NewChar->CharTexture = 0;
	NewChar->FontSize = InternalFontSize;
	NewChar->TexturePositionLeft = 0;
	NewChar->TexturePositionRight = InternalFace->glyph->bitmap.width; // в случае одной текстуры совпадают с шириной
	NewChar->TexturePositionTop = 0;
	NewChar->TexturePositionBottom = InternalFace->glyph->bitmap.rows; // в случае одной текстуры совпадают с высотой
	NewChar->Width = InternalFace->glyph->bitmap.width;
	NewChar->Height = InternalFace->glyph->bitmap.rows;
	NewChar->Left = InternalFace->glyph->bitmap_left;
	NewChar->Top = InternalFace->glyph->bitmap_top;
	NewChar->AdvanceX = InternalFace->glyph->advance.x / 64.0f;
	NewChar->Prev = 0;
	NewChar->Next = 0;

	BYTE * pixels;
	pixels = new BYTE[NewChar->Width*NewChar->Height*4];

	// битмап идет в 1 канале градаций серого, делаем 32бита rgba
	int k=0;
	BYTE ColorRGB[3]={255,255,255};
	for (int j=0; j<NewChar->Height; j++)
	{
		for (int i=0; i<NewChar->Width; i++)
		{
			// RGB составляющую заполняем белым
			memcpy(pixels + k, ColorRGB, 3);
			k+=3;
			memcpy(pixels + k, InternalFace->glyph->bitmap.buffer+(NewChar->Height-j-1)*NewChar->Width+i, 1);
			k++;
		}
	}

	// называем текстуру номером символа в утф32
	char texturefilename[MAX_PATH];
	sprintf(texturefilename, "%i", UTF32);

	vw_SetTextureProp(RI_MAGFILTER_LINEAR | RI_MINFILTER_LINEAR | RI_MIPFILTER_NONE, RI_CLAMP_TO_EDGE, true, TX_ALPHA_GREYSC, false);
	NewChar->CharTexture = vw_CreateTextureFromMemory(texturefilename, pixels, NewChar->Width, NewChar->Height, 4, false, 0, 0, false);
	// очищаем память
	delete [] pixels;

	// подключаем к менеджеру
	vw_AttachFontChar(NewChar);
	return NewChar;
}
开发者ID:dbluelle,项目名称:pandora-astromenace,代码行数:71,代码来源:Font.cpp


示例15: vw_GenerateFontChars

//-----------------------------------------------------------------------------
// делаем генерацию нужных символов по списку генерируя одну текстуру
//-----------------------------------------------------------------------------
void vw_GenerateFontChars(int FontTextureWidth, int FontTextureHeight, const char * CharsList)
{

	printf("Font characters generation start.\n");

	// будем использовать последовательность как имя текстуры
	const char *TextureName = CharsList;
	// временный массив
	BYTE * DIB;
	DIB = new BYTE[FontTextureWidth*FontTextureHeight*4]; // всегда делаем rgba
	// устанавливаем 0 везде, чтобы потом не краcить rgb, а только формировать альфу
	memset(DIB, 0, FontTextureWidth*FontTextureHeight*4);

	// данные для работы с вклеиванием в текстуру
	int CurrentDIBX = 0;
	int CurrentDIBY = 0;
	int EdgingSpace = 2;
	int MaxHeightInCurrentLine = 0;

	// устанавливаем размеры
	if (FT_Set_Char_Size( InternalFace, InternalFontSize <<6, InternalFontSize <<6, 96, 96 ))
	{
		fprintf(stderr, "Can't set char size %i.", InternalFontSize);
		return;
	}

	// первый проход, формируем одну большую текстуру
	const char *CharsList2 = CharsList;
	while (strlen(CharsList) > 0)
	{
		unsigned CurrentChar;
		// преобразуем в утф32 и "сдвигаемся" на следующий символ в строке
		CharsList = utf8_to_utf32(CharsList, &CurrentChar);


		// загрузка глифа нужного нам символа
		if (FT_Load_Char( InternalFace, CurrentChar, FT_LOAD_RENDER | FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT))
		{
			fprintf(stderr, "Can't load Char: %u\n", CurrentChar);
			return;
		}

		// создаем структуру FontChar
		eFontChar* NewChar;
		NewChar = new eFontChar;

		NewChar->UTF32 = CurrentChar;
		NewChar->CharTexture = 0;
		NewChar->FontSize = InternalFontSize;
		NewChar->TexturePositionLeft = 0;
		NewChar->TexturePositionRight = 0;
		NewChar->TexturePositionTop = 0;
		NewChar->TexturePositionBottom = 0;
		NewChar->Width = InternalFace->glyph->bitmap.width;
		NewChar->Height = InternalFace->glyph->bitmap.rows;
		NewChar->Left = InternalFace->glyph->bitmap_left;
		NewChar->Top = InternalFace->glyph->bitmap_top;
		NewChar->AdvanceX = InternalFace->glyph->advance.x / 64.0f;
		NewChar->Prev = 0;
		NewChar->Next = 0;

		// делаем установку параметров для вклеивания

		// если в текущую строку символов уже не можем вписывать - смещаемся на новую, ниже
		if (CurrentDIBX + NewChar->Width > FontTextureWidth)
		{
			CurrentDIBX = 0;
			CurrentDIBY += MaxHeightInCurrentLine + EdgingSpace;
			MaxHeightInCurrentLine = 0;
		}
		// если в текущую строку не влазит уже по высоте - значит это фейл... кричим чтоб дали больше текстуру
		if (CurrentDIBY + NewChar->Height > FontTextureHeight)
		{
			fprintf(stderr, "!!! Can't generate all font chars in one texture. Too many chars or too small texture size!\n");
			delete NewChar;
			break;
		}

		// "вклеиваем" новый символ в массив
		BYTE ColorRGB[3]={255,255,255};
		for (int j=0; j<NewChar->Height; j++)
		for (int i=0; i<NewChar->Width; i++)
		{
			memcpy(DIB + (FontTextureHeight-CurrentDIBY-j-1)*FontTextureWidth*4 + (CurrentDIBX+i)*4,
					ColorRGB,
					3);
			memcpy(DIB + (FontTextureHeight-CurrentDIBY-j-1)*FontTextureWidth*4 + (CurrentDIBX+i)*4 + 3,
					InternalFace->glyph->bitmap.buffer+j*NewChar->Width+i,
					1);
		}

		// устанавливаем параметры текстуры для прорисовки нашему символу
		NewChar->TexturePositionLeft = CurrentDIBX;
		NewChar->TexturePositionRight = CurrentDIBX + NewChar->Width;
		NewChar->TexturePositionTop = CurrentDIBY;
		NewChar->TexturePositionBottom = CurrentDIBY + NewChar->Height;

//.........这里部分代码省略.........
开发者ID:dbluelle,项目名称:pandora-astromenace,代码行数:101,代码来源:Font.cpp


示例16: lock

osgText::Glyph3D * FreeTypeFont::getGlyph3D(unsigned int charcode)
{
    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(FreeTypeLibrary::instance()->getMutex());

    //
    // GT: fix for symbol fonts (i.e. the Webdings font) as the wrong character are being
    // returned, for symbol fonts in windows (FT_ENCONDING_MS_SYMBOL in freetype) the correct
    // values are from 0xF000 to 0xF0FF not from 0x000 to 0x00FF (0 to 255) as you would expect.
    // Microsoft uses a private field for its symbol fonts
    //
    unsigned int charindex = charcode;
    if (_face->charmap != NULL)
    {
        if (_face->charmap->encoding == FT_ENCODING_MS_SYMBOL)
        {
            charindex |= 0xF000;
        }
    }

    FT_Error error = FT_Load_Char( _face, charindex, FT_LOAD_DEFAULT|_flags );
    if (error)
    {
        OSG_WARN << "FT_Load_Char(...) error 0x"<<std::hex<<error<<std::dec<<std::endl;
        return 0;
    }
    if (_face->glyph->format != FT_GLYPH_FORMAT_OUTLINE)
    {
        OSG_WARN << "FreeTypeFont3D::getGlyph : not a vector font" << std::endl;
        return 0;
    }

    float coord_scale = _freetype_scale/64.0f;

    // ** init FreeType to describe the glyph
    FreeType::Char3DInfo char3d(_facade->getNumberCurveSamples());
    char3d._coord_scale = coord_scale;

    FT_Outline outline = _face->glyph->outline;
    FT_Outline_Funcs funcs;
    funcs.conic_to = (FT_Outline_ConicToFunc)&FreeType::conicTo;
    funcs.line_to = (FT_Outline_LineToFunc)&FreeType::lineTo;
    funcs.cubic_to = (FT_Outline_CubicToFunc)&FreeType::cubicTo;
    funcs.move_to = (FT_Outline_MoveToFunc)&FreeType::moveTo;
    funcs.shift = 0;
    funcs.delta = 0;

    // ** record description
    FT_Error _error = FT_Outline_Decompose(&outline, &funcs, &char3d);
    if (_error)
    {
        OSG_WARN << "FreeTypeFont3D::getGlyph : - outline decompose failed ..." << std::endl;
        return 0;
    }

    // ** create geometry for each part of the glyph
    osg::ref_ptr<osg::Geometry> frontGeo(new osg::Geometry);

    osg::ref_ptr<osg::Vec3Array> rawVertices = new osg::Vec3Array(*(char3d._verts));
    osg::Geometry::PrimitiveSetList rawPrimitives;
    for(osg::Geometry::PrimitiveSetList::iterator itr = char3d.get()->getPrimitiveSetList().begin();
        itr != char3d.get()->getPrimitiveSetList().end();
        ++itr)
    {
        rawPrimitives.push_back(dynamic_cast<osg::PrimitiveSet*>((*itr)->clone(osg::CopyOp::DEEP_COPY_ALL)));
    }

    // ** save vertices and PrimitiveSetList of each face in the Glyph3D PrimitiveSet face list
    osg::ref_ptr<osgText::Glyph3D> glyph3D = new osgText::Glyph3D(_facade, charcode);

    // copy the raw primitive set list before we tessellate it.
    glyph3D->getRawFacePrimitiveSetList() = rawPrimitives;
    glyph3D->setRawVertexArray(rawVertices.get());


    FT_Glyph_Metrics* metrics = &(_face->glyph->metrics);

    glyph3D->setHorizontalBearing(osg::Vec2((float)metrics->horiBearingX * coord_scale,(float)(metrics->horiBearingY-metrics->height) * coord_scale)); // bottom left.
    glyph3D->setHorizontalAdvance((float)metrics->horiAdvance * coord_scale);
    glyph3D->setVerticalBearing(osg::Vec2((float)metrics->vertBearingX * coord_scale,(float)(metrics->vertBearingY-metrics->height) * coord_scale)); // top middle.
    glyph3D->setVerticalAdvance((float)metrics->vertAdvance * coord_scale);

    glyph3D->setWidth((float)metrics->width * coord_scale);
    glyph3D->setHeight((float)metrics->height * coord_scale);

    FT_BBox ftbb;
    FT_Outline_Get_BBox(&outline, &ftbb);

    long xmin = ft_floor( ftbb.xMin );
    long xmax = ft_ceiling( ftbb.xMax );
    long ymin = ft_floor( ftbb.yMin );
    long ymax = ft_ceiling( ftbb.yMax );

    osg::BoundingBox bb(xmin * coord_scale, ymin * coord_scale, 0.0f, xmax * coord_scale, ymax * coord_scale, 0.0f);

    glyph3D->setBoundingBox(bb);

    return glyph3D.release();
}
开发者ID:nsmoooose,项目名称:osg,代码行数:98,代码来源:FreeTypeFont.cpp


示例17: font_renderer_create_atlas

static bool font_renderer_create_atlas(ft_font_renderer_t *handle)
{
   unsigned i;
   bool ret = true;

   uint8_t *buffer[FT_ATLAS_SIZE] = {NULL};
   unsigned pitches[FT_ATLAS_SIZE] = {0};

   unsigned max_width = 0;
   unsigned max_height = 0;

   for (i = 0; i < FT_ATLAS_SIZE; i++)
   {
      FT_GlyphSlot slot;
      struct font_glyph *glyph = &handle->glyphs[i];

      if (!glyph)
         continue;

      if (FT_Load_Char(handle->face, i, FT_LOAD_RENDER))
      {
         ret = false;
         goto end;
      }

      FT_Render_Glyph(handle->face->glyph, FT_RENDER_MODE_NORMAL);
      slot = handle->face->glyph;

      /* Some glyphs can be blank. */
      buffer[i] = (uint8_t*)calloc(slot->bitmap.rows * slot->bitmap.pitch, 1);

      glyph->width = slot->bitmap.width;
      glyph->height = slot->bitmap.rows;
      pitches[i] = slot->bitmap.pitch;

      glyph->advance_x = slot->advance.x >> 6;
      glyph->advance_y = slot->advance.y >> 6;
      glyph->draw_offset_x = slot->bitmap_left;
      glyph->draw_offset_y = -slot->bitmap_top;

      if (buffer[i])
         memcpy(buffer[i], slot->bitmap.buffer,
               slot->bitmap.rows * pitches[i]);
      max_width  = MAX(max_width, (unsigned)slot->bitmap.width);
      max_height = MAX(max_height, (unsigned)slot->bitmap.rows);
   }

   handle->atlas.width = max_width * FT_ATLAS_COLS;
   handle->atlas.height = max_height * FT_ATLAS_ROWS;

   handle->atlas.buffer = (uint8_t*)
      calloc(handle->atlas.width * handle->atlas.height, 1);

   if (!handle->atlas.buffer)
   {
      ret = false;
      goto end;
   }

   /* Blit our texture atlas. */
   for (i = 0; i < FT_ATLAS_SIZE; i++)
   {
      uint8_t *dst      = NULL;
      unsigned offset_x = (i % FT_ATLAS_COLS) * max_width;
      unsigned offset_y = (i / FT_ATLAS_COLS) * max_height;

      handle->glyphs[i].atlas_offset_x = offset_x;
      handle->glyphs[i].atlas_offset_y = offset_y;

      dst = (uint8_t*)handle->atlas.buffer;
      dst += offset_x + offset_y * handle->atlas.width;

      if (buffer[i])
      {
         unsigned r, c;
         const uint8_t *src = (const uint8_t*)buffer[i];

         for (r = 0; r < handle->glyphs[i].height;
               r++, dst += handle->atlas.width, src += pitches[i])
            for (c = 0; c < handle->glyphs[i].width; c++)
               dst[c] = src[c];
      }
   }

end:
   for (i = 0; i < FT_ATLAS_SIZE; i++)
      free(buffer[i]);
   return ret;
}
开发者ID:tlanks,项目名称:RetroArch,代码行数:89,代码来源:freetype.c


示例18: FT_Set_Pixel_Sizes

bool mugg::gui::Font::Load(const std::string& path, unsigned int pixelSize = 48) {
    if(FT_New_Face(this->ft, path.c_str(), 0, &this->face)) {
        std::cout << "ERR: Failed to load font " << path << std::endl;
        return false;
    }

    FT_Set_Pixel_Sizes(this->face, 0, pixelSize);

    this->g = this->face->glyph;
    int w = 0;
    int h = 0;

    for(int i = 32; i < 128; i++) {
        if(FT_Load_Char(this->face, i, FT_LOAD_RENDER)) {
            std::cout << "ERR: Loading character " << i << " from " << path << " failed!\n";
        }

        w += this->g->bitmap.width;
        h = std::max(h, this->g->bitmap.rows);

        this->width = w;
    }

    glGenTextures(1, &this->textureID);
    glBindTexture(GL_TEXTURE_2D, this->textureID);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, GL_UNSIGNED_BYTE, nullptr);
    
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    int x = 0;

    for(int i = 32; i < 128; i++) {
        if(FT_Load_Char(this->face, i, FT_LOAD_RENDER))
            continue;

        glTexSubImage2D(GL_TEXTURE_2D, 0, x, 0, this->g->bitmap.width, this->g->bitmap.rows, GL_ALPHA, GL_UNSIGNED_BYTE, this->g->bitmap.buffer);

        x += this->g->bitmap.width;
        
        const uint8_t *p;

        this->c[*p].ax = this->g->advance.x >> 6;
        this->c[*p].ay = this->g->advance.y >> 6;
        
        this->c[*p].bw = this->g->bitmap.width;
        this->c[*p].bh = this->g->bitmap.rows;
        
        this->c[*p].bl = this->g->bitmap_left;
        this->c[*p].bt = this->g->bitmap_top;
        
        this->c[*p].tx = (float)x / w;
    }

}
开发者ID:drmugg123,项目名称:mugg_game,代码行数:61,代码来源:font.cpp


示例19: init_timecode

int init_timecode(p_info_rec* p_info, timecode_data* tc_data,
                  char* font, const int size,
                  const int aspect_ratio_num, const int aspect_ratio_den)
{
    info_rec*		info;
    FT_GlyphSlot	slot;
    char		cset[] = "0123456789:";
    int         bb_t, bb_b, bb_l, bb_r; // bounding box
    BYTE*		dstLine;
    BYTE*		srcPtr;
    BYTE*		dstPtr;
    int			c, j;
    int			result;

    // initialise our data
    if (*p_info == NULL)
    {
        result = allocate_info(p_info);
        if (result < 0)
            return result;
    }
    info = *p_info;
    // create a suitable text image
    result = set_font(info, font, size, aspect_ratio_num, aspect_ratio_den);
    if (result < 0)
        return result;
    // get bounding box for characters
    bb_t =  1000000;
    bb_b = -1000000;
    bb_l =  1000000;
    bb_r = -1000000;
    for (c = 0; c < 11; c++)
    {
        /* load glyph image into the slot (erase previous one) */
        if (FT_Load_Char(info->face, cset[c], FT_LOAD_RENDER))
            return YUV_freetype;
        slot = info->face->glyph;  /* a small shortcut */
        if (bb_t > -slot->bitmap_top)
            bb_t = -slot->bitmap_top;
        if (bb_b < slot->bitmap.rows - slot->bitmap_top)
            bb_b = slot->bitmap.rows - slot->bitmap_top;
        if (bb_l > slot->bitmap_left)
            bb_l = slot->bitmap_left;
        if (bb_r < slot->bitmap_left + slot->bitmap.width)
            bb_r = slot->bitmap_left + slot->bitmap.width;
    }
    // expand bounding box a little
    bb_t -= 1;
    bb_b += 1;
    bb_l -= 1;
    bb_r += 1;
    tc_data->height = bb_b - bb_t;
    // initialise character overlays
    for (c = 0; c < 11; c++)
    {
        tc_data->tc_ovly[c].w = bb_r - bb_l;
        tc_data->tc_ovly[c].h = tc_data->height;
        tc_data->tc_ovly[c].ssx = -1;
        tc_data->tc_ovly[c].ssy = -1;
        tc_data->tc_ovly[c].buff = malloc(tc_data->tc_ovly[c].w *
                                          tc_data->tc_ovly[c].h * 2);
        if (tc_data->tc_ovly[c].buff == NULL)
            return YUV_no_memory;
        memset(tc_data->tc_ovly[c].buff, 0, tc_data->tc_ovly[c].w *
                                            tc_data->tc_ovly[c].h * 2);
        tc_data->tc_ovly[c].Cbuff = NULL;
    }
    // copy bitmaps
    for (c = 0; c < 11; c++)
    {
        /* load glyph image into the slot (erase previous one) */
        if (FT_Load_Char(info->face, cset[c], FT_LOAD_RENDER))
            return YUV_freetype;
        slot = info->face->glyph;  /* a small shortcut */
        if (c == 10)
        {
            // make colon narrower than other characters
            tc_data->tc_ovly[c].w = slot->advance.x / 64;
        }
        srcPtr = slot->bitmap.buffer;
        dstLine = tc_data->tc_ovly[c].buff;
        // add vertical offset
        dstLine += tc_data->tc_ovly[c].w * (-slot->bitmap_top - bb_t);
        // horizontally centre character
        dstLine += (tc_data->tc_ovly[c].w - slot->bitmap.width) / 2;
        for (j = 0; j < slot->bitmap.rows; j++)
        {
            dstPtr = dstLine;
            memcpy(dstLine, srcPtr, slot->bitmap.width);
            srcPtr += slot->bitmap.width;
            dstLine += tc_data->tc_ovly[c].w;
        }
    }
    tc_data->width = (tc_data->tc_ovly[0].w * 8) +
                     (tc_data->tc_ovly[10].w * 3);	// 8 digits and 3 colons
    return YUV_OK;
}
开发者ID:UIKit0,项目名称:bbc-ingex,代码行数:97,代码来源:YUV_text_overlay.c


示例20: autolock

< 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ FT_Load_Glyph函数代码示例发布时间:2022-05-30
下一篇:
C++ FT_Init_FreeType函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap