/**************************************************************************** ** 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; }
/******************************************************************************* * Function Name : RenderScene * Returns : true if no error occured * Description : Main rendering loop function of the program. The shell will * call this function every frame. *******************************************************************************/ bool CImage::RenderScene() { //Clear the screen with the current clear colour. vgClear(0, 0, PVRShellGet(prefWidth), PVRShellGet(prefHeight)); //Change the matrix mode to VG_MATRIX_IMAGE_USER_TO_SURFACE so we can transform the images vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); //Set the current matrix to the identity vgLoadIdentity(); //Translate the image to the desired position vgTranslate(PVRShellGet(prefWidth) * 0.5f - (IMG_SIZE * 0.5f), PVRShellGet(prefHeight)* 0.5f + 5); //Draw the first image vgDrawImage(m_avgImage[0]); //Reset the current matrix... vgLoadIdentity(); //...Perform a translation to position the second image... vgTranslate(PVRShellGet(prefWidth) * 0.5f - (IMG_SIZE * 0.5f), PVRShellGet(prefHeight)* 0.5f - IMG_SIZE - 5); //...and draw vgDrawImage(m_avgImage[1]); m_PrintVG.DisplayDefaultTitle("Image", "", ePVRTPrint3DLogoIMG); return true; }
/******************************************************************************* * Function Name : InitView * Inputs : uWidth, uHeight * 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 CTransforms::InitView() { // Create paths CreatePaths(); // Create paint m_vgPaint = vgCreatePaint(); vgSetParameteri(m_vgPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); vgSetColor(m_vgPaint, PVRTRGBA(255, 255, 170, 255)); vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND); vgSetf(VG_STROKE_LINE_WIDTH, 2.5f / PVRShellGet(prefHeight)); /* The clear colour will be used whenever calling vgClear(). The colour is given as non-premultiplied sRGBA. */ VGfloat afClearColour[] = { 0.6f, 0.8f, 1.0f, 1.0f }; vgSetfv(VG_CLEAR_COLOR, 4, afClearColour); // Initialise custom text drawing m_PrintVG.Initialize(PVRShellGet(prefWidth), PVRShellGet(prefHeight)); m_ui32StartTime = PVRShellGetTime(); return true; }
/******************************************************************************* * Function Name : InitView * Inputs : uWidth, uHeight * 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 COVGIntroducingSVG::InitView() { char *pszOvgFilename = NULL; // Get file from command line. const SCmdLineOpt* psCmdLineOpts = (const SCmdLineOpt*)PVRShellGet(prefCommandLineOpts); int i32CmdLineOpts = PVRShellGet(prefCommandLineOptNum); for (int i = 0; i < i32CmdLineOpts; ++i) { if(strcmp(psCmdLineOpts[i].pArg, "-svg") == 0) { pszOvgFilename = (char*)psCmdLineOpts[i].pVal; break; } } // If no command-line, load tiger.svg file (in the same location where the .exe resides) if(pszOvgFilename == NULL) pszOvgFilename = (char*) &c_szSVGFile[0]; // Get the screen width and height m_i32WindowWidth = PVRShellGet(prefWidth); m_i32WindowHeight = PVRShellGet(prefHeight); /* Load the .svg file into the object using the SVG parser. We need to pass the screen width and height to the load function as the tools code scales the scene based on the viewbox/width & height parameters. */ CPVRTSVGParser SVGParser; if(!SVGParser.Load(pszOvgFilename, &m_SVGObject, m_i32WindowWidth, m_i32WindowHeight)) { PVRShellSet(prefExitMessage, "Failed to load *.svg file."); return false; } // Set the clear colour VGfloat afClearColour[] = { 0.6f, 0.8f, 1.0f, 1.0f }; vgSetfv(VG_CLEAR_COLOR, 4, afClearColour); /* Setup the transformation for the SVGObject. The aim of the transformation is to translate the SVG object to the centre of the screen. */ // Set the object so its centre is at the origin m_SVGObject.SetToOrigin(); // Set the transformation of the object so it is translated from the origin to the centre of the screen. PVRTMat3 m_Transformation; m_Transformation = PVRTMat3::Translation(m_i32WindowWidth * 0.5f, m_i32WindowHeight * 0.5f); m_SVGObject.SetTransformation(&m_Transformation); // Initialise PrintVG for the logo and the title m_PrintVG.Initialize(m_i32WindowWidth, m_i32WindowHeight); return true; }
/******************************************************************************* * Function Name : ReleaseView * Returns : Nothing * Description : Code in ReleaseView() will be called by the Shell before * changing to a new rendering context. *******************************************************************************/ bool CStrokeStyles::ReleaseView() { vgDestroyPath(m_vgPath); m_PrintVG.Terminate(); return true; }
/******************************************************************************* * Function Name : ReleaseView * Returns : Nothing * Description : Code in ReleaseView() will be called by the Shell before * changing to a new rendering context. *******************************************************************************/ bool CTransforms::ReleaseView() { // Cleanup: destroy paths and paint vgDestroyPath(m_avgPaths[0]); vgDestroyPath(m_avgPaths[1]); vgDestroyPaint(m_vgPaint); // Cleanup for custom text drawing m_PrintVG.Terminate(); return true; }
/******************************************************************************* * Function Name : ReleaseView * Returns : true if no error occured * Description : Code in ReleaseView() will be called by the Shell before * changing to a new rendering context. *******************************************************************************/ bool CImage::ReleaseView() { // Cleanup: destroy OpenVG images vgDestroyImage(m_avgImage[0]); m_avgImage[0] = 0; vgDestroyImage(m_avgImage[1]); m_avgImage[1] = 0; m_PrintVG.Terminate(); return true; }
/******************************************************************************* * Function Name : RenderScene * Returns : true if no error occured * Description : Main rendering loop function of the program. The shell will * call this function every frame. *******************************************************************************/ bool COVGIntroducingSVG::RenderScene() { // Clear surface vgClear(0, 0, m_i32WindowWidth, m_i32WindowHeight); // Draw the SVGobject m_SVGObject.Draw(); // Display the title and logo. m_PrintVG.DisplayDefaultTitle("IntroducingSVG", "", ePVRTPrint3DSDKLogo); return true; }
/******************************************************************************* * Function Name : ReleaseView * Returns : true if no error occured * Description : Code in ReleaseView() will be called by the Shell before * changing to a new rendering context. *******************************************************************************/ bool OVGMaskLayer::ReleaseView() { // Cleanup: destroy the paths vgDestroyPath(m_avgPath[0]); vgDestroyPath(m_avgPath[1]); m_PrintVG.Terminate(); // Destroy the mask layers vgDestroyMaskLayer(m_vgMaskLayer[0]); vgDestroyMaskLayer(m_vgMaskLayer[1]); return true; }
/******************************************************************************* * Function Name : RenderScene * Returns : true if no error occured * Description : Main rendering loop function of the program. The shell will * call this function every frame. *******************************************************************************/ bool OVGMaskLayer::RenderScene() { //Clear the screen with the current clear colour vgClear(0, 0, m_ui32ScreenWidth, m_ui32ScreenHeight); // Set the paint and draw the path vgSetPaint(m_avgColourPaint[1], VG_FILL_PATH); vgDrawPath(m_avgPath[0], VG_STROKE_PATH | VG_FILL_PATH); //Enable masking vgSeti(VG_MASKING, VG_TRUE); // Set paint vgSetPaint(m_avgColourPaint[2], VG_FILL_PATH); /* Modify the drawing surface's mask layer by loading it with the values from our first mask layer. See OVGMasking for more details on vgMask. */ vgMask(m_vgMaskLayer[0], VG_SET_MASK, 0, 0, m_ui32ScreenWidth, m_ui32ScreenHeight); // Draw our path vgDrawPath(m_avgPath[1], VG_STROKE_PATH | VG_FILL_PATH); // Load the second mask layer into the mask vgMask(m_vgMaskLayer[1], VG_SET_MASK, 0, 0, m_ui32ScreenWidth, m_ui32ScreenHeight); // Draw our path vgDrawPath(m_avgPath[2], VG_STROKE_PATH | VG_FILL_PATH); // Change paint for the triangle vgSetPaint(m_avgColourPaint[0], VG_FILL_PATH); // Merge our first mask layer into the mask (that currently contains the data from our second layer) vgMask(m_vgMaskLayer[0], VG_INTERSECT_MASK, 0, 0, m_ui32ScreenWidth, m_ui32ScreenHeight); // Draw our path vgDrawPath(m_avgPath[3], VG_STROKE_PATH | VG_FILL_PATH); // Disable masking vgSeti(VG_MASKING, VG_FALSE); // Draw title and logo m_PrintVG.DisplayDefaultTitle("MaskLayer", "", ePVRTPrint3DSDKLogo); return true; }
/******************************************************************************* * Function Name : ReleaseView * Returns : true if no error occured * Description : Code in ReleaseView() will be called by the Shell before * changing to a new rendering context. *******************************************************************************/ bool CChildImage::ReleaseView() { // Cleanup: destroy OpenVG image. vgDestroyImage(m_vgImage); m_vgImage = 0; //Destroy the children as well otherwise the memory isn't reclaimed vgDestroyImage(m_avgChildImages[0]); m_avgChildImages[0] = 0; vgDestroyImage(m_avgChildImages[1]); m_avgChildImages[1] = 0; m_PrintVG.Terminate(); return true; }
/******************************************************************************* * Function Name : InitView * Inputs : uWidth, uHeight * 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 CStrokeStyles::InitView() { /* Create path */ CreatePath(); /* The clear colour will be used whenever calling vgClear(). The colour is given as non-premultiplied sRGBA. */ VGfloat afClearColour[] = { 0.6f, 0.8f, 1.0f, 1.0f }; vgSetfv(VG_CLEAR_COLOR, 4, afClearColour); /* Initialise custom text drawing */ m_PrintVG.Initialize(PVRShellGet(prefWidth), PVRShellGet(prefHeight)); return true; }
/******************************************************************************* * Function Name : RenderScene * Returns : true if no error occured * Description : Main rendering loop function of the program. The shell will * call this function every frame. *******************************************************************************/ bool CChildImage::RenderScene() { //Clear the screen with the current clear color. vgClear(0, 0, PVRShellGet(prefWidth), PVRShellGet(prefHeight)); //Change the matrix mode to VG_MATRIX_IMAGE_USER_TO_SURFACE so we can transform the images vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); //Set the current matrix to the identiy vgLoadIdentity(); //Translate the image to the desired position vgTranslate(PVRShellGet(prefWidth) * 0.5f - (IMG_SIZE * 0.5f), PVRShellGet(prefHeight)* 0.5f + 5.0f); //Draw the main image vgDrawImage(m_vgImage); //Reset the current matrix... vgLoadIdentity(); //...Perform a translation to position the first child image... int i32Height = vgGetParameteri(m_avgChildImages[0], VG_IMAGE_HEIGHT); vgTranslate(PVRShellGet(prefWidth) * 0.5f - (vgGetParameteri(m_avgChildImages[1], VG_IMAGE_WIDTH) * 0.5f), PVRShellGet(prefHeight)* 0.5f - i32Height - 5.0f); //...and draw vgDrawImage(m_avgChildImages[0]); //Reset the current matrix... vgLoadIdentity(); //...Perform a translation to position the second child image... i32Height = vgGetParameteri(m_avgChildImages[0], VG_IMAGE_HEIGHT) + vgGetParameteri(m_avgChildImages[1], VG_IMAGE_HEIGHT); vgTranslate(PVRShellGet(prefWidth) * 0.5f - (vgGetParameteri(m_avgChildImages[1], VG_IMAGE_WIDTH) * 0.5f), PVRShellGet(prefHeight)* 0.5f - i32Height - 10.0f); //...and draw vgDrawImage(m_avgChildImages[1]); m_PrintVG.DisplayDefaultTitle("ChildImage", "", ePVRTPrint3DLogoIMG); return true; }
/******************************************************************************* * Function Name : RenderScene * Returns : true if no error occured * Description : Main rendering loop function of the program. The shell will * call this function every frame. *******************************************************************************/ bool CTransforms::RenderScene() { m_ui32AbsTime = PVRShellGetTime(); // Clear the screen with clear color. vgClear(0, 0, PVRShellGet(prefWidth), PVRShellGet(prefHeight)); // Set fill paint vgSetPaint(m_vgPaint, VG_FILL_PATH); unsigned int ui32TimeSinceStart = PVRShellGetTime() - m_ui32StartTime; // toggle segment type every 3 seconds int ui32ActiveTransform = (ui32TimeSinceStart % (3000 * 7)) / 3000; switch(ui32ActiveTransform) { case 0: DoTranslate(); break; case 1: DoScaleCentered(); break; case 2: DoScaleOrigin(); break; case 3: DoRotateCentered(); break; case 4: DoRotateOrigin(); break; case 5: DoShearCentered(); break; case 6: DoShearOrigin(); break; } // Draw user interface static char* apszTransforms[] = { "Translation", "Scaling (centered on object)", "Scaling (from origin)", "Rotate (centered on object)", "Rotate (around origin)", "Shear (centered on object)", "Shear (from origin)", }; m_PrintVG.DisplayDefaultTitle("Transforms", apszTransforms[ui32ActiveTransform], ePVRTPrint3DLogoIMG); return true; }
/******************************************************************************* * 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; }
/******************************************************************************* * Function Name : RenderScene * Returns : true if no error occured * Description : Main rendering loop function of the program. The shell will * call this function every frame. *******************************************************************************/ bool CStrokeStyles::RenderScene() { /* If the left or right arrow keys are pressed then change the CapStyle or JoinStyle or DashStyle depending on which one is selected. */ if(PVRShellIsKeyPressed(PVRShellKeyNameLEFT)) { switch(m_i32Selected) { case 0: m_i32CapStyle = (m_i32CapStyle + 2) % 3; break; case 1: m_i32JoinStyle = (m_i32JoinStyle + 2) % 3; break; case 2: m_i32DashStyle = (m_i32DashStyle + 2) % 3; break; } } if(PVRShellIsKeyPressed(PVRShellKeyNameRIGHT)) { switch(m_i32Selected) { case 0: m_i32CapStyle = (m_i32CapStyle + 1) % 3; break; case 1: m_i32JoinStyle = (m_i32JoinStyle + 1) % 3; break; case 2: m_i32DashStyle = (m_i32DashStyle + 1) % 3; break; } } /* If the up or down arrow is pressed then change which item is selected. */ if(PVRShellIsKeyPressed(PVRShellKeyNameUP)) m_i32Selected = (m_i32Selected + 2) % 3; if(PVRShellIsKeyPressed(PVRShellKeyNameDOWN)) m_i32Selected = (m_i32Selected + 1) % 3; vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgScale((float)PVRShellGet(prefWidth), (float)PVRShellGet(prefHeight)); // Clear the screen with clear colour. vgClear(0, 0, PVRShellGet(prefWidth), PVRShellGet(prefHeight)); // Draw the path with the stroke styles that we want vgSeti(VG_STROKE_CAP_STYLE , VG_CAP_BUTT + m_i32CapStyle); vgSeti(VG_STROKE_JOIN_STYLE , VG_JOIN_MITER + m_i32JoinStyle); vgSetf(VG_STROKE_MITER_LIMIT, m_fMiterLimit * PVRShellGet(prefHeight)); if(m_i32DashStyle > 0) { vgSetf(VG_STROKE_DASH_PHASE, m_fDashPhase); static float s_afDashes[] = { 0.1f, 0.15f, 0.23f, 0.11f }; vgSetfv(VG_STROKE_DASH_PATTERN, 4, s_afDashes); if(m_i32DashStyle == 2) m_fDashPhase += 0.01f; } else { vgSetfv(VG_STROKE_DASH_PATTERN, 0, NULL); } vgSetf(VG_STROKE_LINE_WIDTH, 20.0f / PVRShellGet(prefHeight)); vgDrawPath(m_vgPath, VG_STROKE_PATH); /* Draw the text. If one of the pieces of text is currently selected then it will be drawn in yellow. */ static char* apszCapStrings[] = { "Butt", "Round", "Square" }; static char* apszJoinStrings[] = { "Miter", "Round", "Bevel" }; static char* apszDashStrings[] = { "None", "Pattern", "Moving" }; m_PrintVG.DisplayDefaultTitle("StrokeStyles", "", ePVRTPrint3DLogoIMG); float fHeight = PVRShellGet(prefHeight) - 40.0f; /* Draw the Cap text. */ m_PrintVG.DrawString(2.0f , fHeight, 0.6f, "Cap:", (int) PVRTRGBA(204,204,204,255)); m_PrintVG.DrawShadowString(65.0f, fHeight, 0.6f, apszCapStrings[m_i32CapStyle], m_i32Selected == 0 ? (int) PVRTRGBA(255,255,0,255) : (int) PVRTRGBA(255,255,255,255)); /* Draw the Join text. */ fHeight -= 20.0f; m_PrintVG.DrawString(2.0f, fHeight, 0.6f, "Join:", (int) PVRTRGBA(204,204,204,255)); m_PrintVG.DrawShadowString(65.0f, fHeight, 0.6f, apszJoinStrings[m_i32JoinStyle], m_i32Selected == 1 ? (int) PVRTRGBA(255,255,0,255) : (int) PVRTRGBA(255,255,255,255)); /* Draw the Dash text. */ fHeight -= 20.0f; m_PrintVG.DrawString(2.0f,fHeight, 0.6f, "Dash:", (int) PVRTRGBA(204,204,204,255)); m_PrintVG.DrawShadowString(65.0f, fHeight, 0.6f, apszDashStrings[m_i32DashStyle], m_i32Selected == 2 ? (int) PVRTRGBA(255,255,0,255) : (int) PVRTRGBA(255,255,255,255)); return true; }
/******************************************************************************* * Function Name : RenderScene * Returns : true if no error occured * Description : Main rendering loop function of the program. The shell will * call this function every frame. *******************************************************************************/ bool OVGFont::RenderScene() { // Clear the screen vgClear(0, 0, m_ui32ScreenWidth, m_ui32ScreenHeight); // Set the current fill paint... vgSetPaint(m_vgFontPaint, VG_FILL_PATH); /* Set the matrix mode to GLYPH_USER_TO_SURFACE as we want to translate and scale the glyphs. */ vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE); /* Set the string. The vgDrawGlyphs function used and explained in DrawLine excepts an array of unsiged ints for an array of glyph IDs which is why we are not defining a char array. An alternative to vgDrawGlyphs is vgDrawGlyph that can be used to display 1 glyph at a time. */ static VGuint str[] = {'T','e','x','t','y', '!',' '}; /* The DrawLine function repeats the string until the line has covered the width of the screen. */ // Draw the string with the path based font at 4 different scales DrawLine(m_vgPathFont, 7, &str[0], m_ui32ScreenHeight * 0.75f, 2.0f); DrawLine(m_vgPathFont, 7, &str[0], m_ui32ScreenHeight * 0.65f, 1.0f); DrawLine(m_vgPathFont, 7, &str[0], m_ui32ScreenHeight * 0.60f, 0.5f); DrawLine(m_vgPathFont, 7, &str[0], m_ui32ScreenHeight * 0.55f, 0.25f); /* Set the blend mode for the image based glyphs */ vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER); /* Set the image mode to DRAW_IMAGE_MULTIPLY so the image based glyphs are multiplied by the paint colour and alpha values. */ vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY); // Draw the string with the image based font at 4 different scales. DrawLine(m_vgImageFont, 7, &str[0], m_ui32ScreenHeight * 0.35f, 2.0f); DrawLine(m_vgImageFont, 7, &str[0], m_ui32ScreenHeight * 0.25f, 1.0f); DrawLine(m_vgImageFont, 7, &str[0], m_ui32ScreenHeight * 0.20f, 0.5f); DrawLine(m_vgImageFont, 7, &str[0], m_ui32ScreenHeight * 0.15f, 0.25f); // Disable blending vgSeti(VG_BLEND_MODE, VG_BLEND_SRC); // Display the title and logo. m_PrintVG.DisplayDefaultTitle("Font", "", ePVRTPrint3DSDKLogo); return true; }
/******************************************************************************* * Function Name : ReleaseView * Returns : Nothing * Description : Code in ReleaseView() will be called by the Shell before * changing to a new rendering context. *******************************************************************************/ bool COVGIntroducingSVG::ReleaseView() { // free anything print vg created m_PrintVG.Terminate(); return true; }
/******************************************************************************* * 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 CChildImage::InitView() { //Create an image m_vgImage = vgCreateImage(VG_sRGBA_8888, IMG_SIZE, IMG_SIZE, VG_IMAGE_QUALITY_NONANTIALIASED); /* Populate the image from memory. A 32bit integer array (8bits per component) is created and populated. */ VGuint* pui32ImgData = new VGuint[IMG_SIZE*IMG_SIZE]; for(int i = 0; i < IMG_SIZE; ++i) { for(int j = 0; j < IMG_SIZE; ++j) { // Fills the data with a fancy pattern if ( ((i*j)/8) % 2 ) pui32ImgData[j*IMG_SIZE+i] = PVRTRGBA(255,255,0,255); else pui32ImgData[j*IMG_SIZE+i] = PVRTRGBA(255, 255 - (j * 2), 255 - i, 255 - (i * 2)); } } /* The data in the array is then copied to the portion of the image starting at (0,0) through to (IMG_SIZE, IMG_SIZE), in this case that is the whole image. The coordinate system of the image places (0,0) at the bottom left-hand corner and (IMG_SIZE, IMG_SIZE) at the top right-hand corner. */ vgImageSubData(m_vgImage, pui32ImgData, sizeof(VGuint) * IMG_SIZE, VG_sRGBA_8888, 0, 0, IMG_SIZE, IMG_SIZE); // Delete the image data as it is now in OpenVG memory delete[] pui32ImgData; pui32ImgData = 0; //Create child images /* The first child is a child of m_vgImage and is made up of the region of m_vgImage from (0,0) to (IMG_SIZE / 2, IMG_SIZE / 2). Note: The area specified must be in the bounds of the parent. */ m_avgChildImages[0] = vgChildImage(m_vgImage, 0, 0, (VGint) (IMG_SIZE * 0.5), (VGint) (IMG_SIZE * 0.5)); //The second child is a clone of the first child. //Get the dimensions of the first child.. int i32ChildWidth = vgGetParameteri(m_avgChildImages[0], VG_IMAGE_WIDTH); int i32ChildHeight= vgGetParameteri(m_avgChildImages[0], VG_IMAGE_HEIGHT); //..and use them to define the region for creating the second child. m_avgChildImages[1] = vgChildImage(m_avgChildImages[0], 0, 0, i32ChildWidth, i32ChildHeight); /* Clear a small portion of the bottom left-hand corner of m_avgChildImages[0] to red. This change will be seen in all relatives of m_avgChildImages[0], reason being they all share the same physical memory. Note: When clearing you specify the coordinate you want to start from and then how many pixels across and up you want to clear. */ VGfloat afClearColour[] = {1.0f, 0.0f, 0.0f, 1.0f}; vgSetfv(VG_CLEAR_COLOR, 4, afClearColour); vgClearImage(m_avgChildImages[0], 0, 0, 10, 10); //Set the clear colour for clearing the sceen afClearColour[0] = 0.6f; afClearColour[1] = 0.8f; afClearColour[2] = 1.0f; afClearColour[3] = 1.0f; vgSetfv(VG_CLEAR_COLOR, 4, afClearColour); m_PrintVG.Initialize(PVRShellGet(prefWidth), PVRShellGet(prefHeight)); return true; }
/******************************************************************************* * 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 CImage::InitView() { //Create a pair of images m_avgImage[0] = vgCreateImage(VG_sRGBA_8888, IMG_SIZE, IMG_SIZE, VG_IMAGE_QUALITY_NONANTIALIASED); m_avgImage[1] = vgCreateImage(VG_sRGBA_8888, IMG_SIZE, IMG_SIZE, VG_IMAGE_QUALITY_NONANTIALIASED); /* The first image will be populated from memory. A 32bit integer array (8bits per component) is created and populated. */ VGuint* pui32ImgData = new VGuint[IMG_SIZE * IMG_SIZE]; for (int i = 0; i < IMG_SIZE; ++i) { for (int j = 0; j < IMG_SIZE; ++j) { // Fills the data with a fancy pattern if ( ((i*j)/8) % 2 ) pui32ImgData[j*IMG_SIZE+i] = PVRTRGBA(255,255,0,255); else pui32ImgData[j*IMG_SIZE+i] = PVRTRGBA(255, 255 - (j * 2), 255 - i, 255 - (i * 2)); } } /* The data in the array is then copied to the portion of the image starting at (0,0) through to (IMG_SIZE, IMG_SIZE), in this case that is the whole image. The coordinate system of the image places (0,0) at the bottom left-hand corner and (IMG_SIZE, IMG_SIZE) at the top right-hand corner. */ vgImageSubData(m_avgImage[0],pui32ImgData, sizeof(VGuint) * IMG_SIZE,VG_sRGBA_8888, 0, 0, IMG_SIZE, IMG_SIZE); // Delete the image data as it is now in OpenVG memory delete[] pui32ImgData; pui32ImgData = 0; /* The second image will initially be cleared to a single colour and then a part of the first image will be copied to it. */ //The colour to clear the image to is taken from the currently set VG_CLEAR_COLOR. VGfloat afClearColour[] = { 1.0f, 0.8f, 0.6f, 1.0f }; vgSetfv(VG_CLEAR_COLOR, 4, afClearColour); //Clear the part of the image in the range (0,0) to (IMG_SIZE, IMG_SIZE), in this case that is the whole image. vgClearImage(m_avgImage[1], 0, 0, IMG_SIZE, IMG_SIZE); /* Copy the bottom left-hand corner ((0,0) to (IMG_SIZE / 2, IMG_SIZE / 2)) of the first image into the the second image starting at (IMG_SIZE / 4, IMG_SIZE / 4). */ int i32ImgSizeQuarter = (int) (IMG_SIZE * 0.25); vgCopyImage(m_avgImage[1], i32ImgSizeQuarter, i32ImgSizeQuarter, m_avgImage[0], 0,0, (VGint) (IMG_SIZE * 0.5), (VGint) (IMG_SIZE * 0.5), (VGboolean) false); //Set the clear colour for clearing the sceen afClearColour[0] = 0.6f; afClearColour[1] = 0.8f; afClearColour[2] = 1.0f; afClearColour[3] = 1.0f; vgSetfv(VG_CLEAR_COLOR, 4, afClearColour); m_PrintVG.Initialize(PVRShellGet(prefWidth), PVRShellGet(prefHeight)); return true; }