Esempio n. 1
1
/****************************************************************************
** InitView() is called by PVRShell each time a rendering variable is changed
** in the Shell menu (Z-Buffer On/Off, resolution change, buffering mode...)
** In this function one should initialise all variables that are dependant on
** general rendering variables (screen mode, 3D device, etc...)
****************************************************************************/
bool OVGFont::InitView()
{
	CPVRTPVGObject* pPVGObj;
	VGImage vgImage;
	VGImage vgChild;
	float fW,fH;
	PVRTVECTOR2 fGlyphOrigin, fEscapement;

	// Store the screen width and height
	m_ui32ScreenWidth  = PVRShellGet(prefWidth);
	m_ui32ScreenHeight = PVRShellGet(prefHeight);

	// Set the clear colour
	VGfloat afClearColour[] = { 0.6f, 0.8f, 1.0f, 1.0f };
	vgSetfv(VG_CLEAR_COLOR, 4, afClearColour);

	// Initialise PrintVG for the logo and the title
	m_PrintVG.Initialize(m_ui32ScreenWidth, m_ui32ScreenHeight);

	// Load the font path data from the pvg file
	pPVGObj = CPVRTPVGObject::FromFile(c_szPVGFile);

	if(pPVGObj == NULL)
	{
		PVRShellSet(prefExitMessage, "Error: Failed to load Font.pvg.");
		return false;
	}

	if(pPVGObj->m_i32NumPaths != g_i32ImageCharNo)
	{
		PVRShellSet(prefExitMessage, "Error: Font.pvg doesn't contain the expected amount of characters.");

		delete pPVGObj;
		return false;
	}

	// Load the image based font data
	if(PVRTImageLoadFromPVR(c_szPVRFile, &vgImage) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "Error: Failed to open mask.pvr.");
		return false;
	}

	/*
		Create two fonts. m_vgPathFont will purely contain glyphs represented by paths
		and m_vgImageFont by images. It is also reasonable to have a font that contains
		a mixture but we are keeping them seperate so they can be compared.
	*/

	m_vgImageFont = vgCreateFont(g_i32ImageCharNo);
	m_vgPathFont  = vgCreateFont(pPVGObj->m_i32NumPaths);

	// Add the glyphs to the fonts.
	for(int i = 0; i < g_i32ImageCharNo; ++i)
	{
		// Load glyph from path data

		/*
			Each path in the PVG file represents a glyph. First we need to acquire the origin
			of the glyph so we use vgPathBounds to achieve this as the origin described in
			g_CharDesc is for the image.
		*/
		vgPathBounds(pPVGObj->m_pPaths[i].m_path, &fGlyphOrigin.x, &fGlyphOrigin.y, &fW, &fH);

		// We offset the origin so glyphs like a 'y' are lower
		fGlyphOrigin.x += g_CharDesc[i].fOriginOffset.x;
		fGlyphOrigin.y += g_CharDesc[i].fOriginOffset.y;

		/*
			Add the glyph and assign it a unique ID. The characters we're loading have ASCII codes ranging from
			33 to 128 hence we're giving the glyphs IDs starting at 33. The glyph origin defines the coordinates
			in path space at which to start drawing the glyph and the escapement character is the offset to start
			drawing the next following character.
		*/
		vgSetGlyphToPath(m_vgPathFont, 33 + i, pPVGObj->m_pPaths[i].m_path, VG_TRUE, (VGfloat*) &fGlyphOrigin.x, (VGfloat*) &g_CharDesc[i].fEscapement.x);

		// Load glyph from image data

		/*
			Using a child image we 'cut' the glyph out of the main image (see the child image training course for
			an explanation).
		*/
		vgChild = vgChildImage(vgImage,  g_CharDesc[i].i32Origin[0], g_CharDesc[i].i32Origin[1], g_CharDesc[i].i32Width, g_CharDesc[i].i32Height);

		/*
			We then add the child image to the font. We use the origin offset value directly for the value as the glyph's
			origin is 0,0 within the child image.
		*/
		vgSetGlyphToImage(m_vgImageFont, 33 + i, vgChild, (VGfloat*) &g_CharDesc[i].fOriginOffset.x, (VGfloat*) &g_CharDesc[i].fEscapement.x);

		// Destroy the child image as we no longer need it.
		vgDestroyImage(vgChild);
	}

	// Destroy the image as it is no longer required
	vgDestroyImage(vgImage);

	// Destroy the PVG data as it too is no longer required
	delete pPVGObj;
	pPVGObj = 0;

	// Space

	/*
		Glyphs such as spaces that do not have a visual representation can be added to
		the fonts by passing VG_INVALID_HANDLE instead of a path or image handle.
	*/

	// Set the glyph origin and escapement for the space...
	fGlyphOrigin.x = 0.0f;
	fGlyphOrigin.y = 0.0f;
	// ... We're giving the space a width of 10.0f
	fEscapement.x = 10.0f;
	fEscapement.y = 0.0f;

	vgSetGlyphToImage(m_vgImageFont, 32, VG_INVALID_HANDLE, (VGfloat*) &fGlyphOrigin.x, (VGfloat*) &fEscapement.x);
	vgSetGlyphToPath(m_vgPathFont, 32, VG_INVALID_HANDLE, VG_TRUE, (VGfloat*) &fGlyphOrigin.x, (VGfloat*) &fEscapement.x);

	// Create font paint
	m_vgFontPaint = vgCreatePaint();

	vgSetParameteri(m_vgFontPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(m_vgFontPaint, PVRTRGBA(255,0,0,255));

	return true;
}
Esempio n. 2
0
/*******************************************************************************
 * Function Name  : InitView
 * Returns        : true if no error occured
 * Description    : Code in InitView() will be called by the Shell upon a change
 *					in the rendering context.
 *					Used to initialise variables that are dependent on the rendering
 *					context (e.g. textures, vertex buffers, etc.)
 *******************************************************************************/
bool OVGMaskLayer::InitView()
{
	// Get screen dimensions
	m_ui32ScreenWidth = PVRShellGet(prefWidth);
	m_ui32ScreenHeight= PVRShellGet(prefHeight);

	// Create the paths so we have something to look at.
	CreatePath();

	// Set the render quality so the stroke borders have some form of anti-aliasing
	vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER);

	// Create the paints that the paths will use
	m_avgColourPaint[0] = vgCreatePaint();
	vgSetParameteri(m_avgColourPaint[0], VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(m_avgColourPaint[0], PVRTRGBA(255,255,15,255));

	m_avgColourPaint[1] = vgCreatePaint();
	vgSetParameteri(m_avgColourPaint[1], VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(m_avgColourPaint[1], PVRTRGBA(255,50,0, 255));

	m_avgColourPaint[2] = vgCreatePaint();
	vgSetParameteri(m_avgColourPaint[2], VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(m_avgColourPaint[2], PVRTRGBA(50,250,15, 255));

	/*
		Load the images we're going to use to modify the mask layer.

		For more details on masking please refer to our OVGMasking training course
	*/

	// Create the VGImages.
	VGImage vgMaskImg, vgMaskImg2;

	// Using the PVR Tools we're going to load the mask data from a pvr file
	if(PVRTImageLoadFromPVR(c_szMask1File, &vgMaskImg) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "Error: Failed to open mask1.pvr.");
		return false;
	}

	if(PVRTImageLoadFromPVR(c_szMask2File, &vgMaskImg2) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "Error: Failed to open mask2.pvr.");
		return false;
	}

	/*
		Create a mask layer

		A VGMaskLayer is an object that allows you to store and manipulate the drawing surface's mask layer
	*/

	m_vgMaskLayer[0] = vgCreateMaskLayer(m_ui32ScreenWidth, m_ui32ScreenHeight);

	if(m_vgMaskLayer[0] == 0)
	{
		PVRShellSet(prefExitMessage, "Error: Failed to create mask layer.");
		return false;
	}

	// Tile the first image in the drawing surface's masking layer
	TileImageInMask(vgMaskImg, VG_SET_MASK);

	/*
		Copy the contents of the drawing surface mask layer into our mask layer object

		vgCopyMask has the following parameters

		VGMaskLayer maskLayer, VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height)

		where

		masklayer is the masklayer to copy to
		dx, dy are the coordinates to start the copy at in the masklayer
		sx, sy are the coordinates to start the copy from in the source mask layer
		width and the height are the width and height of the region you wish to copy.

		In our case we're copying the full mask layer.
	*/

	vgCopyMask(m_vgMaskLayer[0], 0, 0, 0, 0, m_ui32ScreenWidth, m_ui32ScreenHeight);

	// Create the second mask layer
	m_vgMaskLayer[1] = vgCreateMaskLayer(m_ui32ScreenWidth, m_ui32ScreenHeight);

	if(m_vgMaskLayer[1] == 0)
	{
		PVRShellSet(prefExitMessage, "Error: Failed to create mask layer.");
		return false;
	}

	// Replace the contents of the mask by tiling the second image
	TileImageInMask(vgMaskImg2, VG_SET_MASK);

	// Copy the contents of the mask into the second mask layer
	vgCopyMask(m_vgMaskLayer[1], 0, 0, 0, 0, m_ui32ScreenWidth, m_ui32ScreenHeight);

	// Destroy the images as they are no longer needed
	vgDestroyImage(vgMaskImg);
	vgDestroyImage(vgMaskImg2);

	// Set the mask to ones
	vgMask(VG_INVALID_HANDLE, VG_FILL_MASK, 0, 0, m_ui32ScreenWidth, m_ui32ScreenHeight);

	// Init PrintVG
	m_PrintVG.Initialize(m_ui32ScreenWidth, m_ui32ScreenHeight);

	// Setup the transformation to scale the paths to fit the screen
	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
	vgLoadIdentity();

	vgScale((float) m_ui32ScreenWidth, (float) m_ui32ScreenHeight);

	// Reduce the stroke size to compensate for our scaling
	vgSetf(VG_STROKE_LINE_WIDTH, 1.0f / m_ui32ScreenHeight);

	//Create and set the clear colour
	VGfloat afClearColour[] = { 0.6f, 0.8f, 1.0f, 1.0f };
	vgSetfv(VG_CLEAR_COLOR, 4, afClearColour);

	return true;
}