Esempio n. 1
0
// Generate texture layout for all unplaced characters
bool FontFaceLayer::GenerateLayout()
{
	int prior_num_rectangles = texture_layout.GetNumRectangles();
	int prior_num_textures = texture_layout.GetNumTextures();

	// Generate the texture layout; this will position the glyph rectangles efficiently and
	// allocate the texture data ready for writing.
	if (!texture_layout.GenerateLayout(512))
		return false;

	// Iterate over each rectangle in the layout, copying the glyph data into the rectangle as
	// appropriate and generating geometry.
	int rectangle_count = texture_layout.GetNumRectangles();
	for (int i = prior_num_rectangles; i < rectangle_count; ++i)
	{
		TextureLayoutRectangle* rectangle = texture_layout.GetRectangle(i);
		Character* character = characters[(word) rectangle->GetId()];
		if (!character)
			continue;
		const TextureLayoutTexture* texture = texture_layout.GetTexture(rectangle->GetTextureIndex());

		// Set the character's texture index.
		character->texture_index = rectangle->GetTextureIndex();

		// Generate the character's texture coordinates.
		character->texcoords[0].x = float(rectangle->GetPosition().x) / float(texture->GetDimensions().x);
		character->texcoords[0].y = float(rectangle->GetPosition().y) / float(texture->GetDimensions().y);
		character->texcoords[1].x = float(rectangle->GetPosition().x + rectangle->GetDimensions().x) / float(texture->GetDimensions().x);
		character->texcoords[1].y = float(rectangle->GetPosition().y + rectangle->GetDimensions().y) / float(texture->GetDimensions().y);
	}

	if (prior_num_textures > 0 && prior_num_rectangles != rectangle_count)
		textures[prior_num_textures-1]->Update();

	// Generate the textures.
	int texture_count = texture_layout.GetNumTextures();
	for (int i = prior_num_textures; i < texture_count; ++i)
	{
		Texture* texture = new Texture();
		if (!texture->Load(String(64, "?font::%p/%p/%d/%p", handle, effect, i, texture_layout.GetTexture(i))))
		{
			delete texture;
			return false;
		}

		textures.push_back(texture);
	}

	return true;
}
Esempio n. 2
0
TextureLayout& TextureLayout::operator+=(const TextureLayout &layout)
{
  const int texture_size = GetNumTextures();

  for (TextureList::const_iterator i = layout.textures.begin(); i != layout.textures.end(); ++i)
  {
    TextureLayoutTexture *texture = *i;

    texture->AddReference();
    textures.push_back(texture);
  }
  for (RectangleList::const_iterator i = layout.rectangles.begin(); i != layout.rectangles.end(); ++i)
  {
    TextureLayoutRectangle *rect = *i;

    rect->AddReference();
    rect->Place(texture_size + rect->GetTextureIndex(), rect->GetPosition());
    rectangles.push_back(rect);
  }

  return *this;
}