예제 #1
0
void ElementImage::GenerateGeometry()
{
	// Release the old geometry before specifying the new vertices.
	geometry.Release(true);

	std::vector< Rocket::Core::Vertex >& vertices = geometry.GetVertices();
	std::vector< int >& indices = geometry.GetIndices();

	vertices.resize(4);
	indices.resize(6);

	// Generate the texture coordinates.
	Vector2f texcoords[2];
	if (using_coords)
	{
		Vector2f texture_dimensions((float) texture.GetDimensions(GetRenderInterface()).x, (float) texture.GetDimensions(GetRenderInterface()).y);
		if (texture_dimensions.x == 0)
			texture_dimensions.x = 1;
		if (texture_dimensions.y == 0)
			texture_dimensions.y = 1;

		texcoords[0].x = (float) coords[0] / texture_dimensions.x;
		texcoords[0].y = (float) coords[1] / texture_dimensions.y;

		texcoords[1].x = (float) coords[2] / texture_dimensions.x;
		texcoords[1].y = (float) coords[3] / texture_dimensions.y;
	}
	else
	{
		texcoords[0] = Vector2f(0, 0);
		texcoords[1] = Vector2f(1, 1);
	}

    const Property* element_colour = GetProperty(BACKGROUND_COLOR);
    float opacity = GetProperty<float>(OPACITY);

    Colourb quad_colour = Colourb(255, 255, 255);
    if (element_colour)
    {
        Colourb background_colour = element_colour->Get<Colourb>();

        // Should be a non-transparent background
        if (background_colour.alpha != 0)
            quad_colour = background_colour;
    }

    // Apply opacity
    quad_colour.alpha = (byte)(opacity * (float)quad_colour.alpha);

	Rocket::Core::GeometryUtilities::GenerateQuad(&vertices[0],									// vertices to write to
												  &indices[0],									// indices to write to
												  Vector2f(0, 0),					            // origin of the quad
												  GetBox().GetSize(Rocket::Core::Box::CONTENT),	// size of the quad
												  quad_colour,		                            // colour of the vertices
												  texcoords[0],									// top-left texture coordinate
												  texcoords[1]);								// top-right texture coordinate

	geometry_dirty = false;
}
예제 #2
0
void ElementImage::GenerateGeometry()
{
	// Release the old geometry before specifying the new vertices.
	geometry.Release(true);

	std::vector< Rocket::Core::Vertex >& vertices = geometry.GetVertices();
	std::vector< int >& indices = geometry.GetIndices();

	vertices.resize(4);
	indices.resize(6);

	// Generate the texture coordinates.
	Vector2f texcoords[2];
	if (using_coords)
	{
		Vector2f texture_dimensions((float) texture.GetDimensions(GetRenderInterface()).x, (float) texture.GetDimensions(GetRenderInterface()).y);
		if (texture_dimensions.x == 0)
			texture_dimensions.x = 1;
		if (texture_dimensions.y == 0)
			texture_dimensions.y = 1;

		texcoords[0].x = (float) coords[0] / texture_dimensions.x;
		texcoords[0].y = (float) coords[1] / texture_dimensions.y;

		texcoords[1].x = (float) coords[2] / texture_dimensions.x;
		texcoords[1].y = (float) coords[3] / texture_dimensions.y;
	}
	else
	{
		texcoords[0] = Vector2f(0, 0);
		texcoords[1] = Vector2f(1, 1);
	}

	Colourb colour(255, 255,255,255);
	const Property* property = GetLocalProperty(COLOR);
	if (property)
		colour = property->value.Get<Colourb>();

	Rocket::Core::GeometryUtilities::GenerateQuad(&vertices[0],									// vertices to write to
												  &indices[0],									// indices to write to
												  Vector2f(0, 0),					// origin of the quad
												  GetBox().GetSize(Rocket::Core::Box::CONTENT),	// size of the quad
												  colour,		// colour of the vertices
												  texcoords[0],									// top-left texture coordinate
												  texcoords[1]);								// top-right texture coordinate

	geometry_dirty = false;
}