コード例 #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;
}
コード例 #2
0
void SubtitleRenderer::
draw_text(VGFont font, VGFont italic_font,
          const std::vector<SubtitleRenderer::InternalChar>& text,
          int x, int y,
          unsigned int lightness) {
  VGPaint paint = vgCreatePaint();
  assert(paint);

  vgSetColor(paint, (lightness<<8) | (lightness<<16) | (lightness<<24) | 0xFF);
  assert(!vgGetError());

  vgSetPaint(paint, VG_FILL_PATH);
  assert(!vgGetError());

  vgDestroyPaint(paint);
  assert(!vgGetError());

  vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY);
  assert(!vgGetError());

  VGfloat pos[] = {static_cast<VGfloat>(x), static_cast<VGfloat>(y)};

  vgSetfv(VG_GLYPH_ORIGIN, 2, pos);
  assert(!vgGetError());

  for (auto c = text.begin(); c != text.end(); ++c) {
    vgDrawGlyph(c->italic ? italic_font : font,
                c->codepoint,
                VG_FILL_PATH,
                VG_FALSE);
    assert(!vgGetError());
  }
}
コード例 #3
0
/*******************************************************************************
 * 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;
}
コード例 #4
0
static void setVGSolidColor(VGPaintMode paintMode, const Color& color)
{
    VGPaint paint = vgCreatePaint();
    vgSetParameteri(paint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
    vgSetColor(paint, colorToVGColor(color));
    vgSetPaint(paint, paintMode);
    vgDestroyPaint(paint);
    ASSERT_VG_NO_ERROR();
}
コード例 #5
0
/*!***************************************************************************
 @Function		SetAlpha
 @Input			ui8Alpha (0x00 = Fuly translucent, 0xFF = fully opaque)
 @Description	Overwrites path translucency parameter
*****************************************************************************/
void CPVRTPVGObject::SetAlpha(unsigned char ui8Alpha)
{
	assert(m_bInitialized);
	int i32Color;
	for(int i = 0; i < m_i32NumPaths; ++i)
	{
		if(m_pPaths[i].m_bIsNewFill)
		{
			i32Color = (vgGetColor(m_pPaths[i].m_fillPaint) & 0xFFFFFF00) + ui8Alpha;
			vgSetColor(m_pPaths[i].m_fillPaint, i32Color);
		}
		if(m_pPaths[i].m_bIsNewStroke)
		{
			i32Color = (vgGetColor(m_pPaths[i].m_strokePaint) & 0xFFFFFF00) + ui8Alpha;
			vgSetColor(m_pPaths[i].m_strokePaint, i32Color);
		}
		m_pPaths[i].m_bNeedsBlending = (ui8Alpha != 255);
	}
}
コード例 #6
0
/****************************************************************************
** 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 CIntroducingPVRShell::InitView()
{
	/*
	Initially, the OpenVG coordinate system is based on the output resolution.
	To get a device independent coordinate system, we need to apply a
	transformation. Scaling by the output resolution means that coordinates
	between (0, 0) and (1, 1) will be visible on screen.

	It should be noted, however, that different aspect ratios usually require
	special attention regarding the layout of elements on screen.
	*/
	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
	vgLoadIdentity();
	vgScale((float)PVRShellGet(prefWidth), (float)PVRShellGet(prefHeight));

	/*
	Drawing shapes with OpenVG requires a path which represents a series of
	line and curve segments describing the outline of the shape. The shape
	does not need to be closed, but for now we will start with a simple
	triangle.
	First we create a path object, then we append segment and point data.
	*/
	m_vgPath = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
							1.0f, 0.0f, 4, 3, (unsigned int)VG_PATH_CAPABILITY_ALL);

	VGubyte aui8PathSegments[4] = {
		VG_MOVE_TO_ABS,
		VG_LINE_TO_ABS,
		VG_LINE_TO_ABS,
		VG_CLOSE_PATH,
	};
	VGfloat afPoints[6] = {
			0.3f, 0.3f,
			0.7f, 0.3f,
			0.5f, 0.7f,
	};
	vgAppendPathData(m_vgPath, 4, aui8PathSegments, afPoints);

	/*
	To fill a shape, we need a paint that describes how to fill it: a gradient,
	pattern, or single colour. Here we choose a simple opaque red.
	*/
	m_vgFillPaint = vgCreatePaint();
	vgSetParameteri(m_vgFillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(m_vgFillPaint, PVRTRGBA(255,255,170,255));

	/*
	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);

	return true;
}
コード例 #7
0
  BoxRenderer(unsigned int opacity) {
    path_ = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
                        1.0, 0.0,
                        0, 0,
                        VG_PATH_CAPABILITY_ALL);
    assert(path_);

    paint_ = vgCreatePaint();
    assert(paint_);

    vgSetColor(paint_, opacity);
    assert(!vgGetError());
  }
コード例 #8
0
ファイル: svg2.c プロジェクト: dschmenk/SEGL
int main(int argc, char **argv)
{
    float rotate, color[4] = {0.0, 0.33, 0.33, 1.0};
    VGPath path;
    VGPaint paintStroke;
    VGubyte pathSegments[] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_CLOSE_PATH};
    float   pathData[] = {200.0, 300.0, 100.0, 100.0};
    float   incData[]  = {  1.0,   2.0,  -2.5,  -0.5};

    EGLDisplayState *eglState = eglOpenDisplay(0 /* min win dimension */,
                                               8 /* min color component size */,
                                               8 /* min alpha size */,
                                               0 /* min Z depth */,
                                               EGL_OPENVG_BIT /* render type */);
    path = vgCreatePath(VG_PATH_FORMAT_STANDARD,
                        VG_PATH_DATATYPE_F,
                        1.0, 0.0,
                        0,   0,
                        VG_PATH_CAPABILITY_APPEND_TO | VG_PATH_CAPABILITY_MODIFY);
    vgAppendPathData(path, 3, pathSegments, pathData);
    paintStroke = vgCreatePaint();
    vgSetColor(paintStroke, 0x00FF00FF);
    vgSetParameteri(paintStroke, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
    vgSetPaint(paintStroke, VG_STROKE_PATH | VG_FILL_PATH);
    vgSetf(VG_STROKE_LINE_WIDTH, 5.0);
    vgLoadIdentity();
    for (rotate = 0.0; rotate < 1000.0; rotate++) {
        color[0] = rotate / 1000.0;
        vgSetfv(VG_CLEAR_COLOR, 4, color);
        vgClear(0, 0, eglState->win.width, eglState->win.height);
        bounce(2, pathData, incData, eglState->win.width, eglState->win.height);
        vgModifyPathCoords(path, 0, 3, pathData);
        vgDrawPath(path, VG_STROKE_PATH);
        eglUpdateDisplay(eglState);
    }
    eglCloseDisplay(eglState);
}
コード例 #9
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;
}
コード例 #10
0
/****************************************************************************
** Application entry point
****************************************************************************/
int main()
{
	// Variable set in the message handler to finish the demo
	bool				bDemoDone	= false;

	// X11 variables
	Display*			x11Display	= 0;
	Window				x11Window	= 0;
	Colormap			x11Colormap	= 0;

	EGLDisplay			eglDisplay	= 0;
	EGLConfig			eglConfig	= 0;
	EGLSurface			eglSurface	= 0;
	EGLContext			eglContext	= 0;
	int i32NumConfigs, i32MajorVersion, i32MinorVersion;

	/*
	Step 0 - Initialize OpenVG
	--------------------------

	The following code up to the next comment block consists of the
	steps 0 to 8 taken straight from the Initialization tutorial.
	*/
	Window					sRootWindow;
    XSetWindowAttributes	sWA;
	unsigned int			ui32Mask;
	int						i32Depth;

	// Initializes the display and screen
	x11Display = XOpenDisplay( 0 );
	if (!x11Display)
	{
		printf("Error: Unable to open X display\n");
		goto cleanup;
	}
	long x11Screen;
	x11Screen = XDefaultScreen( x11Display );

	// Gets the window parameters
	sRootWindow = RootWindow(x11Display, x11Screen);
	i32Depth = DefaultDepth(x11Display, x11Screen);
	XVisualInfo* x11Visual;
	x11Visual = new XVisualInfo;
	XMatchVisualInfo( x11Display, x11Screen, i32Depth, TrueColor, x11Visual);
	if (!x11Visual)
	{
		printf("Error: Unable to acquire visual\n");
		goto cleanup;
	}
    x11Colormap = XCreateColormap( x11Display, sRootWindow, x11Visual->visual, AllocNone );
    sWA.colormap = x11Colormap;

    // Add to these for handling other events
    sWA.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask;
    ui32Mask = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap;

	// Creates the X11 window
    x11Window = XCreateWindow( x11Display, RootWindow(x11Display, x11Screen), 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT,
								 0, CopyFromParent, InputOutput, CopyFromParent, ui32Mask, &sWA);
	XMapWindow(x11Display, x11Window);
	XFlush(x11Display);

	eglDisplay = (EGLDisplay)eglGetDisplay((NativeDisplayType)x11Display);

	if(!eglInitialize(eglDisplay, &i32MajorVersion, &i32MinorVersion))
	{
		printf("Error: eglInitialize() failed.\n");
		goto cleanup;
	}

	eglBindAPI(EGL_OPENVG_API);

	static const int ai32ConfigAttribs[] =
	{
		EGL_RED_SIZE,       5,
		EGL_GREEN_SIZE,     6,
		EGL_BLUE_SIZE,      5,
		EGL_ALPHA_SIZE,     0,
		EGL_SURFACE_TYPE,   EGL_WINDOW_BIT,
		EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
		EGL_NONE
	};

	if(!eglChooseConfig(eglDisplay, ai32ConfigAttribs, &eglConfig, 1, &i32NumConfigs) || (i32NumConfigs != 1))
	{
		printf("Error: eglChooseConfig() failed.\n");
		goto cleanup;
	}

	eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, (NativeWindowType)x11Window, NULL);
	if((eglGetError() != EGL_SUCCESS) || (eglSurface == EGL_NO_SURFACE))
	{
		printf("Error: eglCreateWindowSurface() failed.\n");
		goto cleanup;
	}

	eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);
	if((eglGetError() != EGL_SUCCESS) || (eglContext == EGL_NO_CONTEXT))
	{
		printf("Error: eglCreateContext() failed.\n");
		goto cleanup;
	}

	eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
	if(eglGetError() != EGL_SUCCESS)
	{
		printf("Error: eglMakeCurrent() failed.\n");
		goto cleanup;
	}

	/*
	Steps 1 to 4 - Prepare OpenVG to draw a triangle
	------------------------------------------------

	At this point we could theoretically start drawing with OpenVG. But
	we have to specify what to draw and how to draw it first.
	*/

	/*
	Step 1 - Set up a device independent coordinate system
	------------------------------------------------------

	Initially, the OpenVG coordinate system is based on the output resolution.
	To get a device independent coordinate system, we need to apply a
	transformation: Scaling by the output resolution means that coordinates
	between (0, 0) and (1, 1) will be visible on screen, with the origin
	in the lower left corner.

	Transformations are described more in-depth in the Transforms tutorial.

	It should be noted that different aspect ratios often require
	special attention regarding the layout of elements on screen.
	*/

	int i32WindowWidth, i32WindowHeight;
	eglQuerySurface(eglDisplay, eglSurface, EGL_WIDTH, &i32WindowWidth);
	eglQuerySurface(eglDisplay, eglSurface, EGL_HEIGHT, &i32WindowHeight);

	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
	vgLoadIdentity();
	vgScale((float)i32WindowWidth, (float)i32WindowHeight);


	/*
	Step 2 - Create a path
	----------------------
	Drawing shapes with OpenVG requires a path which represents a series of
	line and curve segments describing the outline of the shape. The shape
	does not need to be closed, but for now we will start with a simple
	triangle.
	First we create a path handle, then we append segment and point data.

	Creating a path involves choosing a datatype used for point data (we use
	float here, indicated by VG_PATH_DATATYPE_F) and capabilities that we want
	to use. Picking the right capabilities is important as the OpenVG driver
	can use a more efficient and compact internal representation for paths
	with limited capabilities. We only need two capabilities for this tutorial:
	adding data	to the path and drawing it, with the latter being implicitly
	enabled	for all paths.
	*/
	VGPath vgTriangle;
	vgTriangle = vgCreatePath(
							VG_PATH_FORMAT_STANDARD,
							VG_PATH_DATATYPE_F,
							1.0f, 0.0f, 4, 3,
							(unsigned int)VG_PATH_CAPABILITY_APPEND_TO);

	/*
	The segments of a path are described as a series of commands, represented as
	an array of bytes. You can imagine the commands being performed by a pen:
	First the pen moves to a starting location without drawing, from there it
	draws a line to a second point. Then another line to a third point. After
	that, it closes the shape by drawing a line from the last point to the
	starting location: triangle finished!

	The suffixes _ABS and _REL attached to the commands indicate whether the
	coordinates are to be interpreted as absolute locations (seen from the
	origin)or as being relative to the location of the current point.
	*/
	VGubyte aui8PathSegments[4];
	aui8PathSegments[0] = VG_MOVE_TO_ABS;
	aui8PathSegments[1] = VG_LINE_TO_ABS;
	aui8PathSegments[2] = VG_LINE_TO_ABS;
	aui8PathSegments[3] = VG_CLOSE_PATH;

	/*
	In addition to the array of commands, the path needs a list of points. A
	command can "consume" from 0 to 6 values, depending on its type. MOVE_TO
	and LINE_TO each take two values, CLOSE_PATH takes none.
	A triangle requires 3 2D vertices.
	*/
	VGfloat afPoints[6];
	afPoints[0] = 0.3f;
	afPoints[1] = 0.3f;
	afPoints[2] = 0.7f;
	afPoints[3] = 0.3f;
	afPoints[4] = 0.5f;
	afPoints[5] = 0.7f;

	/*
	When appending data to the path, only the number of segments needs to be
	specified since the number of points used depends on the actual commands.
	*/
	vgAppendPathData(vgTriangle, 4, aui8PathSegments, afPoints);

	/*
	Path capabilities should be removed as soon as they are no longer needed.
	The OpenVG implementation might work more efficiently if it knows that
	path data will not change since it can use an optimized internal
	representation.
	*/
	vgRemovePathCapabilities(vgTriangle, VG_PATH_CAPABILITY_APPEND_TO);


	/*
	Step 3 - Create a paint
	-----------------------
	To fill a shape, we need a paint that describes how to fill it: a gradient,
	pattern, or single color. Here we choose a paint with type COLOR that
	is a simple opaque red. vgSetColor is a shortcut function that takes a
	non-premultiplied sRGBA color encoded as a 32bit integer in RGBA_8888 form.
	*/
	VGPaint vgFillPaint;
	vgFillPaint = vgCreatePaint();
	vgSetParameteri(vgFillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(vgFillPaint, 0xFFFFAAFF);

	/*
	Step 4 - Prepare the render loop
	--------------------------------

	The clear color will be used whenever calling vgClear(). The color is given
	as non-premultiplied sRGBA, represented by four float values.
	*/
	VGfloat afClearColor[4];
	afClearColor[0] = 0.6f;
	afClearColor[1] = 0.8f;
	afClearColor[2] = 1.0f;
	afClearColor[3] = 1.0f;

	// Set the clear color
	vgSetfv(VG_CLEAR_COLOR, 4, afClearColor);

	/*
	Step 5 - Render loop
	--------------------

	Start the render loop for 1000 frames!
	*/
	for(int i = 0; i < 1000; ++i)
	{
		// Check if the message handler finished the demo
		if (bDemoDone) break;

		// Clear the whole surface with the clear color
		vgClear(0, 0, i32WindowWidth, i32WindowHeight);

		// Set the current fill paint...
		vgSetPaint(vgFillPaint, VG_FILL_PATH);

		// Draw the triangle!
		vgDrawPath(vgTriangle, VG_FILL_PATH);

		/*
		Drawing is double buffered, so you never see any intermediate
		results of the drawing. When you have finished drawing
		you have to call eglSwapBuffers to make the results appear on
		screen.
		*/
		eglSwapBuffers(eglDisplay, eglSurface);

		// Managing the X11 messages
		int i32NumMessages = XPending( x11Display );
		for( int i = 0; i < i32NumMessages; i++ )
		{
			XEvent	event;
			XNextEvent( x11Display, &event );

			switch( event.type )
			{
			// Exit on mouse click
			case ButtonPress:
        		bDemoDone = true;
        		break;
			default:
				break;
			}
		}
	}

	/*
	Step 6 - Destroy resources
	--------------------------

	OpenVG resources like paths and paints need to be destroyed
	when they are no longer needed.
	*/
	vgDestroyPath(vgTriangle);
	vgDestroyPaint(vgFillPaint);


cleanup:
	/*
	Step 7 - Terminate OpenVG
	-------------------------

	Again, the following code is taken from the Initialization tutorial,
	steps 10 and 11.
	*/
	eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
	eglTerminate(eglDisplay);

	if (x11Window) XDestroyWindow(x11Display, x11Window);
    if (x11Colormap) XFreeColormap( x11Display, x11Colormap );
	if (x11Display) XCloseDisplay(x11Display);

	// Say goodbye
	printf("%s finished.", pszAppName);
	return 0;
}
コード例 #11
0
void CNVGCSIcon::DrawPaintL(VGPaint aPaint, VGMatrixMode aMatrixMode, TUint & aLastPaintType, TUint & aLastPaintColor, VGPaintMode aPaintMode)
    {
    VGPaintType paintType = (VGPaintType)iNVGIconData->ReadInt32L();
    
    if (paintType == VG_PAINT_TYPE_LINEAR_GRADIENT ||
        paintType == VG_PAINT_TYPE_RADIAL_GRADIENT)
        {
        VGPaintParamType paintPType = VG_PAINT_LINEAR_GRADIENT;
        if (paintType == VG_PAINT_TYPE_RADIAL_GRADIENT)
            {
            paintPType = VG_PAINT_RADIAL_GRADIENT;
            }
        
        VGPaint paintHandle = iNVGIconData->ReadInt32L();
        TInt count = iNVGIconData->ReadInt32L();
        VGfloat gradientData[5];
        VGfloat gradientMatrix[9];
        
        iNVGIconData->ReadL((TUint8 *)gradientData, count * sizeof(VGfloat));
        iNVGIconData->ReadL((TUint8 *)gradientMatrix, 9 * sizeof(VGfloat));
        
        if (paintHandle)
            {
            vgSetPaint(paintHandle,   aPaintMode);
            vgSeti(VG_MATRIX_MODE, aMatrixMode);
            vgLoadMatrix(gradientMatrix);
            if (aPaintMode == VG_FILL_PATH)
                {
                iResetFillPaint = 1;
                }
            else
                {
                iResetStrokePaint = 1;
                }
            }
        else
            {
        if (aLastPaintType != paintType)
            {
            vgSetParameteri(aPaint, VG_PAINT_TYPE, paintType);
            }
        vgSetParameterfv(aPaint, paintPType, count, gradientData);
        
        vgSeti(VG_MATRIX_MODE, aMatrixMode);
        vgLoadMatrix(gradientMatrix);
            }
        vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
        }
    else if (paintType == VG_PAINT_TYPE_COLOR)
        {
        if (aPaintMode == VG_FILL_PATH && iResetFillPaint)
            {
            iResetFillPaint = 0;
            vgSetPaint(aPaint, aPaintMode);
            }
        else if (aPaintMode == VG_STROKE_PATH && iResetStrokePaint)
            {
            iResetStrokePaint = 0;
            vgSetPaint(aPaint, aPaintMode);
            }
        TUint color = static_cast<TUint>(iNVGIconData->ReadInt32L());
        if (aLastPaintType != paintType)
            {
            vgSetParameteri(aPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
            vgSetColor(aPaint, color);
            }
        else
            {
            if (aLastPaintColor != color)
                {
                vgSetColor(aPaint, color);
                }
            }
        aLastPaintColor = color;
        }
    else
        {
        User::Leave(KErrCorrupt);
        }
    aLastPaintType = paintType;
    }