void display(float interval) { VGfloat cc[] = {0,0,0,1}; vgSetfv(VG_CLEAR_COLOR, 4, cc); vgClear(0,0,testWidth(),testHeight()); vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER); vgLoadIdentity(); vgTranslate(tx, ty); vgRotate(ang); vgScale(sx, sy); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgSetPaint(radialFill, VG_FILL_PATH); vgDrawPath(p, VG_FILL_PATH); vgTranslate(tx, ty); vgRotate(ang); vgScale(sx, sy); vgSetPaint(blackFill, VG_FILL_PATH | VG_STROKE_PATH); vgDrawPath(radius, VG_STROKE_PATH); vgDrawPath(center, VG_STROKE_PATH); vgDrawPath(focus, VG_FILL_PATH); }
void display(float interval) { VGfloat cc[] = {0,0,0,1}; vgSetfv(VG_CLEAR_COLOR, 4, cc); vgClear(0,0,testWidth(),testHeight()); vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER); vgLoadIdentity(); vgTranslate(tx, ty); vgScale(sx, sy); vgRotate(a); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY); vgLoadIdentity(); vgSetPaint(patternFill, VG_FILL_PATH); /*vgDrawPath(p, VG_FILL_PATH);*/ vgDrawImage(backImage); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(tx, ty); vgScale(sx, sy); vgRotate(a); vgSetPaint(blackFill, VG_FILL_PATH | VG_STROKE_PATH); vgDrawPath(org, VG_FILL_PATH); }
/******************************************************************************* * 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 : DoShearOrigin * Description : Demonstrate the effect of shearing from the origin. *******************************************************************************/ void CTransforms::DoShearOrigin() { // Make sure we're operating on the path user-to-surface matrix vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); // Load Identity matrix. This clears all previous transformations vgLoadIdentity(); // To be independent of screen resolution, we need to scale the // coordinates so everything in the range [0, 1] will be visible vgScale((float)PVRShellGet(prefWidth), (float)PVRShellGet(prefHeight)); // turn time(ms) into a periodic triangle function int i32Zigzag = m_ui32AbsTime % 2000; if(i32Zigzag > 1000) i32Zigzag = 2000 - i32Zigzag; i32Zigzag = PVRT_MAX(100, PVRT_MIN(900, i32Zigzag)) - 500; vgShear(i32Zigzag * 0.001f, 0); // draw first path vgDrawPath(m_avgPaths[0], VG_STROKE_PATH | VG_FILL_PATH); // draw second path vgDrawPath(m_avgPaths[1], VG_STROKE_PATH | VG_FILL_PATH); }
void render(int w, int h) { { float clearColor[4] = {1,1,1,1}; float scale = w / (tigerMaxX - tigerMinX); eglSwapBuffers(egldisplay, eglsurface); //force EGL to recognize resize vgSetfv(VG_CLEAR_COLOR, 4, clearColor); vgClear(0, 0, w, h); vgLoadIdentity(); vgTranslate(w * 0.5f, h * 0.5f); vgRotate(rotateN); vgTranslate(-w * 0.5f, -h * 0.5f); vgScale(scale, scale); vgTranslate(-tigerMinX, -tigerMinY + 0.5f * (h / scale - (tigerMaxY - tigerMinY))); PS_render(tiger); assert(vgGetError() == VG_NO_ERROR); renderWidth = w; renderHeight = h; } }
void loadTiger() { int i; VGPath temp; temp = testCreatePath(); tigerPaths = (VGPath*)malloc(pathCount * sizeof(VGPath)); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgTranslate(-100,100); vgScale(1,-1); for (i=0; i<pathCount; ++i) { vgClearPath(temp, VG_PATH_CAPABILITY_ALL); vgAppendPathData(temp, commandCounts[i], commandArrays[i], dataArrays[i]); tigerPaths[i] = testCreatePath(); vgTransformPath(tigerPaths[i], temp); } tigerStroke = vgCreatePaint(); tigerFill = vgCreatePaint(); vgSetPaint(tigerStroke, VG_STROKE_PATH); vgSetPaint(tigerFill, VG_FILL_PATH); vgLoadIdentity(); vgDestroyPath(temp); }
//Display functions void display(float interval) { int i; const VGfloat *style; VGfloat clearColor[] = {1,1,1,1}; if (animate) { ang += interval * 360 * 0.1f; if (ang > 360) ang -= 360; } vgSetfv(VG_CLEAR_COLOR, 4, clearColor); vgClear(0,0,testWidth(),testHeight()); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(testWidth()/2 + tx,testHeight()/2 + ty); vgScale(sx, sy); vgRotate(ang); for (i=0; i<pathCount; ++i) { style = styleArrays[i]; vgSetParameterfv(tigerStroke, VG_PAINT_COLOR, 4, &style[0]); vgSetParameterfv(tigerFill, VG_PAINT_COLOR, 4, &style[4]); vgSetf(VG_STROKE_LINE_WIDTH, style[8]); vgDrawPath(tigerPaths[i], (VGint)style[9]); // Bingo!!, Draw it!! } vgFlush(); }
/******************************************************************************* * Function Name : DoScaleOrigin * Description : Demonstrate the effect of scaling from the origin. *******************************************************************************/ void CTransforms::DoScaleOrigin() { // Make sure we're operating on the path user-to-surface matrix vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); // Load Identity matrix. This clears all previous transformations vgLoadIdentity(); // To be independent of screen resolution, we need to scale the // coordinates so everything in the range [0, 1] will be visible vgScale((float) PVRShellGet(prefWidth), (float) PVRShellGet(prefHeight)); // turn time(ms) into a periodic triangle function int i32Zigzag = m_ui32AbsTime % 2000; if(i32Zigzag > 1000) i32Zigzag = 2000 - i32Zigzag; i32Zigzag = PVRT_MAX(100, PVRT_MIN(900, i32Zigzag)); float fScaleFactor = 0.3f + (i32Zigzag * 0.0009f); // Scaling a scene from the origin means that objects will // either get pulled towards the origin or move away from it // along with being resized. vgScale(fScaleFactor, fScaleFactor); // draw first path vgDrawPath(m_avgPaths[0], VG_STROKE_PATH | VG_FILL_PATH); // draw second path vgDrawPath(m_avgPaths[1], VG_STROKE_PATH | VG_FILL_PATH); }
void OVGFont::DrawLine(VGFont &vgFont, VGint i32Size, VGuint *pStr, float fHeight, float fScale) { static float fOrigin[] = {0.0f, 0.0f}; /* Everytime vgDrawGlyph(s) is called the glyph(s) are drawn at the position defined by VG_GLYPH_ORIGIN. This value is updated after each call by the escapement vector defined by the glyph. As we don't want our text to follow any of the text previously drawn we're setting the glyph orign to 0,0. */ vgSetfv(VG_GLYPH_ORIGIN, 2, fOrigin); /* Using the matrix mode MATRIX_GLYPH_USER_TO_SURFACE translate and scale the font. */ vgLoadIdentity(); vgTranslate(0.0f, fHeight); vgScale(fScale, fScale); /* Our string is only a few glyphs long so we're going to repeatedly draw it until the x value of the GLYPH_ORIGIN is greater than the scaled width. */ float fGlyphOrigin[2]; fGlyphOrigin[0] = 0.0f; fGlyphOrigin[1] = 0.0f; float fScaledWidth = m_ui32ScreenWidth / fScale; while(fGlyphOrigin[0] < fScaledWidth) { /* Draw i32Size no of glyphs from pStr. The VG_FILL_PATH parameter defines how you would like the glyph (if a path) to be displayed. You can also have it stroked by using VG_STROKE_PATH. This parameter doesn't affect image based glyphs unless it's value is set to 0 in which case no glyph (path or image based) will be drawn. The fourth and fifth parameters are the x and y adjustments for each glyph. These can be set to adjust the position of the glyphs drawn or can be set to NULL. The final parameter (set to VG_TRUE) disables or enables autohinting. If equal to true autohinting may be applied to alter the glyphs slightly to improve the render quality. */ vgDrawGlyphs(vgFont, i32Size, &pStr[0], NULL,NULL, VG_FILL_PATH, VG_TRUE); // Get the updated GLYPH_ORIGIN vgGetfv(VG_GLYPH_ORIGIN, 2, &fGlyphOrigin[0]); } }
static void draw(void) { vgClear(0, 0, window_width(), window_height()); vgLoadIdentity(); vgTranslate(50, 21); vgDrawPath(path, VG_FILL_PATH); vgFlush(); }
/******************************************************************************* * Function Name : DoShearCentered * Description : Demonstrate the effect of shearing centred on a * shape. Each path is transformed separately. *******************************************************************************/ void CTransforms::DoShearCentered() { // Make sure we're operating on the path user-to-surface matrix vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); // Load Identity matrix. This clears all previous transformations vgLoadIdentity(); // To be independent of screen resolution, we need to scale the // coordinates so everything in the range [0, 1] will be visible vgScale((float)PVRShellGet(prefWidth), (float)PVRShellGet(prefHeight)); // Unlike OpenGL, OpenVG does not maintain a matrix stack. So instead of // pushing the current matrix to the stack, we have to store it ourselves float afUnitMatrix[3 * 3]; vgGetMatrix(afUnitMatrix); // turn time(ms) into a clipped periodic triangle function int i32Zigzag1 = m_ui32AbsTime % 2000; if(i32Zigzag1 > 1000) i32Zigzag1 = 2000 - i32Zigzag1; i32Zigzag1 = PVRT_MAX(250, PVRT_MIN(750, i32Zigzag1)) - 500; // and again, now with shifted phase int i32Zigzag2 = (m_ui32AbsTime + 500) % 2000; if(i32Zigzag2 > 1000) i32Zigzag2 = 2000 - i32Zigzag2; i32Zigzag2 = PVRT_MAX(250, PVRT_MIN(750, i32Zigzag2)) - 500; // Scaling a shape from its center is identical to moving it to the // origin, scaling it there, and moving it back where it was. // // IMPORTANT: // Since OpenVG right-multiplies matrices, you conceptually need to // call the transformation functions in backwards order. vgTranslate(0.5f, 0.75f); vgShear(0.001f * i32Zigzag1, 0); vgTranslate(-0.5f, -0.75f); // draw first path vgDrawPath(m_avgPaths[0], VG_STROKE_PATH | VG_FILL_PATH); // restore the unit matrix ([0, 1] visible) vgLoadMatrix(afUnitMatrix); // transformation for second path vgTranslate(0.5f, 0.25f); vgShear(0.001f * i32Zigzag2, 0); vgTranslate(-0.5f, -0.25f); // draw second path vgDrawPath(m_avgPaths[1], VG_STROKE_PATH | VG_FILL_PATH); }
// Start begins the picture, clearing a rectangular region with a specified color void Start(int width, int height) { VGfloat color[4] = { 1, 1, 1, 1 }; vgSetfv(VG_CLEAR_COLOR, 4, color); vgClear(0, 0, width, height); color[0] = 0, color[1] = 0, color[2] = 0; setfill(color); setstroke(color); StrokeWidth(0); vgLoadIdentity(); }
/**************************************************************************** ** 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; }
int render(int width, int height) { static DWORD startTick =0; static DWORD frames = 0; VGImage image; char buf[256]; if((startTick == 0)||(frames > 50)) { if(frames > 50) frames = 0; startTick = GetTickCount(); frames++; } else { sprintf(buf, "fps:%2.2f frames/sec \n", (float)(frames++)*1000/(GetTickCount() - startTick)); OutputDebugString(buf); } if(pReadFile == NULL) { pReadFile = fopen("test.rgb","rb"); if(pReadFile) fseek(pReadFile, 0 , SEEK_SET); } if(pReadFile && (feof(pReadFile))) fseek(pReadFile, 0 , SEEK_SET); if(pReadFile) fread(pBuff, sizeof(BYTE),SRC_WIDTH*SRC_HEIGHT*2,pReadFile); image = vgCreateImage( VG_sRGB_565, SRC_WIDTH, SRC_HEIGHT, VG_IMAGE_QUALITY_BETTER ); if(image == NULL) return -1; vgImageSubData( image, pBuff, SRC_WIDTH*2, VG_sRGB_565, 0, 0, SRC_WIDTH, SRC_HEIGHT); vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgLoadIdentity(); vgScale((VGfloat)width/SRC_WIDTH, (VGfloat)height/SRC_HEIGHT); vgTranslate(SRC_WIDTH, SRC_HEIGHT); vgRotate(180.0f); vgDrawImage( image ); vgDestroyImage( image ); if ( vgGetError() == VG_NO_ERROR ) eglSwapBuffers( egldisplay, eglsurface ); return 0; }
/******************************************************************************* * 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; }
static void draw(void) { const VGint w = 48; VGImage img1, img2; VGint x, y; vgSetfv(VG_CLEAR_COLOR, 4, white); vgClear(0, 0, window_width(), window_height()); img1 = vgCreateImage(VG_sRGBA_8888, w, w, VG_IMAGE_QUALITY_NONANTIALIASED); img2 = vgCreateImage(VG_sRGBA_8888, w, w, VG_IMAGE_QUALITY_NONANTIALIASED); x = 5; y = (window_height() - w) / 2; /* test vgSetPixels */ vgSetfv(VG_CLEAR_COLOR, 4, red); vgClearImage(img1, 0, 0, w, w / 2); vgSetfv(VG_CLEAR_COLOR, 4, black); vgClearImage(img1, 0, w / 2, w, w / 2); vgSetPixels(x, y, img1, 0, 0, w, w); x += w + 5; /* test vgDrawImage */ vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(x, y); vgDrawImage(img1); /* test vgGetPixels */ vgGetPixels(img1, 0, 0, x, y, w, w); x += w + 5; vgSetPixels(x, y, img1, 0, 0, w, w); x += w + 5; /* test vgCopyImage */ vgCopyImage(img2, 0, 0, img1, 0, 0, w, w, VG_FALSE); vgSetPixels(x, y, img2, 0, 0, w, w); /* vgCopyPixels */ vgCopyPixels(x + w + 5, y, x, y, w, w); vgDestroyImage(img1); vgDestroyImage(img2); }
static void draw(void) { VGint WINDSIZEX = window_width(); VGint WINDSIZEY = window_height(); VGPaint fill; VGPath box; VGfloat color[4] = {1.f, 0.f, 0.f, 1.f}; VGfloat bgCol[4] = {0.7f, 0.7f, 0.7f, 1.0f}; VGfloat transCol[4] = {0.f, 0.f, 0.f, 0.f}; VGImage image = vgCreateImage(VG_sRGBA_8888, img_width, img_height, VG_IMAGE_QUALITY_NONANTIALIASED); /* Background clear */ fill = vgCreatePaint(); vgSetParameterfv(fill, VG_PAINT_COLOR, 4, color); vgSetPaint(fill, VG_FILL_PATH); box = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); /* Rectangle to cover completely 16x16 pixel area. */ RectToPath(box, 0, 0, 64, 64); vgSetfv(VG_CLEAR_COLOR, 4, transCol); vgClearImage(image, 0, 0, img_width, img_height); vgSetfv(VG_CLEAR_COLOR, 4, color); vgClearImage(image, 10, 10, 12, 12); //vgImageSubData(image, pukki_64x64_data, pukki_64x64_stride, // VG_sRGBA_8888, 0, 0, 32, 32); vgSeti(VG_MASKING, VG_TRUE); vgLoadIdentity(); vgSetfv(VG_CLEAR_COLOR, 4, bgCol); vgClear(0, 0, WINDSIZEX, WINDSIZEY); vgMask(image, VG_FILL_MASK, 0, 0, window_width(), window_height()); vgMask(image, VG_SET_MASK, x_pos, y_pos, 100, 100); vgDrawPath(box, VG_FILL_PATH); //vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); //vgTranslate(-10, -10); //vgDrawImage(image); vgDestroyPaint(fill); vgDestroyPath(box); }
static void update_display(setting_render_internal_t* renderer) { // Render it out vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgSetfv(VG_CLEAR_COLOR, 4, renderer->definition.background_colour); vgClear(renderer->definition.x, renderer->definition.y, renderer->definition.width, renderer->definition.height); vgSetiv(VG_SCISSOR_RECTS, 4, &renderer->definition.x); vgSeti(VG_SCISSORING, VG_TRUE); vgTranslate(renderer->definition.x, renderer->definition.y); vgSeti(VG_RENDERING_QUALITY, renderer->definition.text_quality); vgSetPaint(renderer->state.text_paint, VG_FILL_PATH); gfx_render_text(renderer->definition.text_x_offset, renderer->definition.text_y_offset, renderer->definition.text, &gfx_font_sans, renderer->definition.text_size); VGfloat text_width = gfx_text_width(renderer->definition.text, &gfx_font_sans, renderer->definition.text_size); const size_t buffer_size = 512; char setting_text_buffer[buffer_size]; setting_t* setting = renderer->definition.setting; switch(setting->type) { case SETTING_TYPE_INT: { snprintf(setting_text_buffer, buffer_size - 1, renderer->definition.format, setting_get_value_int(setting)); break; } case SETTING_TYPE_FLOAT: { snprintf(setting_text_buffer, buffer_size - 1, renderer->definition.format, setting_get_value_float(setting)); break; } case SETTING_TYPE_ENUM: { snprintf(setting_text_buffer, buffer_size - 1, renderer->definition.format, setting_get_value_enum(setting)); break; } default: snprintf(setting_text_buffer, buffer_size - 1, "ILLEGAL SETTING TYPE: %d", (int)setting->type); break; } setting_text_buffer[buffer_size - 1] = 0; gfx_render_text(text_width + 2 + renderer->definition.text_x_offset, renderer->definition.text_y_offset, setting_text_buffer, &gfx_font_sans, renderer->definition.text_size); vgSeti(VG_SCISSORING, VG_FALSE); }
/******************************************************************************* * Function Name : DoTranslate * Description : Demonstrate the effect of translations. Each path is * translated separately *******************************************************************************/ void CTransforms::DoTranslate() { // Make sure we're operating on the path user-to-surface matrix vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); // Load Identity matrix. This clears all previous transformations vgLoadIdentity(); // To be independent of screen resolution, we need to scale the // coordinates so everything in the range [0, 1] will be visible vgScale((float) PVRShellGet(prefWidth), (float) PVRShellGet(prefHeight)); // Unlike OpenGL, OpenVG does not maintain a matrix stack. So instead of // pushing the current matrix to the stack, we have to store it ourselves float afUnitMatrix[3 * 3]; vgGetMatrix(afUnitMatrix); // turn time(ms) into a clipped periodic triangle function int i32Zigzag1 = m_ui32AbsTime % 2000; if(i32Zigzag1 > 1000) i32Zigzag1 = 2000 - i32Zigzag1; i32Zigzag1 = PVRT_MAX(250, PVRT_MIN(750, i32Zigzag1)) - 500; // and again, now with shifted phase int i32Zigzag2 = (m_ui32AbsTime + 500) % 2000; if(i32Zigzag2 > 1000) i32Zigzag2 = 2000 - i32Zigzag2; i32Zigzag2 = PVRT_MAX(250, PVRT_MIN(750, i32Zigzag2)) - 250; // translation for first path vgTranslate(-0.001f * i32Zigzag1, -0.001f * i32Zigzag2); // draw first path vgDrawPath(m_avgPaths[0], VG_STROKE_PATH | VG_FILL_PATH); // restore the unit matrix ([0, 1] visible) vgLoadMatrix(afUnitMatrix); // translation for second path vgTranslate(0.001f * i32Zigzag1, 0.001f * i32Zigzag2); // draw second path vgDrawPath(m_avgPaths[1], VG_STROKE_PATH | VG_FILL_PATH); }
static void draw(void) { vgClear(0, 0, width, height); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(width/2, height/2); vgRotate(angle); vgTranslate(-width/2, -height/2); lion_render(lion); ++angle; eglutPostRedisplay(); }
void display(float interval) { VGfloat cc[] = {0,0,0,1}; angle += interval * 0.4 * PI; if (angle > 2*PI) angle -= 2*PI; amount = (sin(angle) + 1) * 0.5f; createMorph(); vgSetfv(VG_CLEAR_COLOR, 4, cc); vgClear(0,0,testWidth(),testHeight()); vgLoadIdentity(); vgTranslate(testWidth()/2, testHeight()/2); vgScale(1.5, 1.5); vgDrawPath(iMorph, VG_FILL_PATH); }
static void draw(void) { VGPath line; VGPaint fillPaint; VGubyte lineCommands[3] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS}; VGfloat lineCoords[] = {-2.0f,-1.0f, 0.0f,0.0f, -1.0f, -2.0f}; VGfloat clearColor[] = {0.0f, 0.0f, 0.0f, 1.0f};/* black color */ VGfloat fillColor[] = {1.0f, 1.0f, 1.0f, 1.0f};/* white color */ //VGfloat testRadius = 60.0f; VGfloat testRadius = 10.0f; int WINDSIZEX = window_width(); int WINDSIZEY = window_height(); line = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL); fillPaint = vgCreatePaint(); vgSetf(VG_STROKE_LINE_WIDTH, 1.0f); //vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_ROUND); vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_BUTT); vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND); //vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_BEVEL); vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(60, 60); vgScale(testRadius * 2, testRadius * 2); vgAppendPathData(line, 3, lineCommands, lineCoords); vgSetfv(VG_CLEAR_COLOR, 4, clearColor); vgSetPaint(fillPaint, VG_STROKE_PATH); vgSetParameterfv(fillPaint, VG_PAINT_COLOR, 4, fillColor); vgSetParameteri( fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); vgClear(0, 0, WINDSIZEX, WINDSIZEY); vgDrawPath(line, VG_STROKE_PATH); vgDestroyPath(line); vgDestroyPaint(fillPaint); }
void CTSmallWindowOpenVG::RenderL() { CTWindow::RenderL(); // Make sure that this egl status is active eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG); VGfloat clearColor[4] = {0.1f, 0.2f, 0.4f, 1.f}; VGfloat scaleFactor = Size().iWidth/200.f; if (Size().iHeight/200.f < scaleFactor) { scaleFactor = Size().iHeight/200.f; } iCurrentRotation = iTime; if (iCurrentRotation >= 360.f) { iCurrentRotation -= 360.f; } vgSetfv(VG_CLEAR_COLOR, 4, clearColor); vgClear(0, 0, Size().iWidth, Size().iHeight); vgLoadIdentity(); vgTranslate((float)Size().iHeight / 2, (float)Size().iHeight / 2); vgScale(scaleFactor, scaleFactor); vgRotate(iCurrentRotation); vgTranslate(-50.f, -50.f); vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER); vgSeti(VG_FILL_RULE, VG_EVEN_ODD); vgSetPaint(iFillPaint, VG_FILL_PATH); vgSetf(VG_STROKE_LINE_WIDTH, 10.f); vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_ROUND); vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND); vgSetf(VG_STROKE_MITER_LIMIT, 0.f); vgSetPaint(iStrokePaint, VG_STROKE_PATH); vgDrawPath(iPath, VG_FILL_PATH | VG_STROKE_PATH); iTime++; eglSwapBuffers(iDisplay, iSurface); }
void GtkOvgGlue::setRenderHandlerSize(int width, int height) { GNASH_REPORT_FUNCTION; assert(width > 0); assert(height > 0); assert(_renderer != NULL); #ifdef ENABLE_EGL_OFFSCREEN if (_offscreenbuf && _offscreenbuf->width == width && _offscreenbuf->height == height) { return; } if (_offscreenbuf) { gdk_image_destroy(_offscreenbuf); } GdkVisual* visual = gdk_drawable_get_visual(_drawing_area->window); _offscreenbuf = gdk_image_new (GDK_IMAGE_FASTEST, visual, width, height); #endif #if 1 // if (_renderer) { // vgScale(width, height); // } #else // Attach the window to the low level device long xid = GDK_WINDOW_XID(gtk_widget_get_window(_drawing_area)); _device->attachWindow(static_cast<renderer::GnashDevice::native_window_t> (xid)); vgLoadIdentity(); // Allow drawing everywhere by default InvalidatedRanges ranges; ranges.setWorld(); _renderer->set_invalidated_regions(ranges); renderer::EGLDevice *egl = (renderer::EGLDevice*)_device.get(); egl->swapBuffers(); #endif }
/******************************************************************************* * Function Name : DoRotateCentered * Description : Demonstrate the effect of rotating around the centre of a * shape. Each path is transformed separately. *******************************************************************************/ void CTransforms::DoRotateCentered() { // Make sure we're operating on the path user-to-surface matrix vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); // Load Identity matrix. This clears all previous transformations vgLoadIdentity(); // To be independent of screen resolution, we need to scale the // coordinates so everything in the range [0, 1] will be visible vgScale((float)PVRShellGet(prefWidth), (float)PVRShellGet(prefHeight)); // Unlike OpenGL, OpenVG does not maintain a matrix stack. So instead of // pushing the current matrix to the stack, we have to store it ourselves float afUnitMatrix[3*3]; vgGetMatrix(afUnitMatrix); float fRotationAngle = m_ui32AbsTime * 0.03f; // Scaling a shape from its center is identical to moving it to the // origin, scaling it there, and moving it back where it was. // // IMPORTANT: // Since OpenVG right-multiplies matrices, you conceptually need to // call the transformation functions in backwards order. vgTranslate(0.5f, 0.75f); vgRotate(fRotationAngle); vgTranslate(-0.5f, -0.75f); // draw first path vgDrawPath(m_avgPaths[0], VG_STROKE_PATH | VG_FILL_PATH); // restore the unit matrix ([0, 1] visible) vgLoadMatrix(afUnitMatrix); // transformation for second path vgTranslate(0.5f, 0.25f); vgRotate(-fRotationAngle); vgTranslate(-0.5f, -0.25f); // draw second path vgDrawPath(m_avgPaths[1], VG_STROKE_PATH | VG_FILL_PATH); }
bool HbSgimageIconProcessor::renderNvg(const QByteArray& byteArray, const QRect& rect, Qt::AspectRatioMode aspectRatioMode, bool mirrored) { QPoint topLeft = rect.topLeft(); QSize size(rect.size()); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); if (!topLeft.isNull()) { vgTranslate(topLeft.x(), topLeft.y()); } NvgAspectRatioSettings settings = mapKeyAspectRatioToNvgAspectRatio(aspectRatioMode); sgImageRenderer->nvgEngine()->setPreserveAspectRatio(settings.nvgAlignStatusAndAspectRatio, settings.type); sgImageRenderer->nvgEngine()->enableMirroring(mirrored); HbNvgEngine::HbNvgErrorType errorType = sgImageRenderer->nvgEngine()->drawNvg(byteArray, size); return errorType == HbNvgEngine::NvgErrNone; }
static void draw(EGLmanager *eglman) { VGfloat black[] = {0.f, 0.f, 0.f, 1.f}; // Render 3D scene by GL eglBindAPI(EGL_OPENGL_ES_API); eglMakeCurrent(eglman->dpy, eglman->pbuf_surface, eglman->pbuf_surface, eglman->es_ctx); // Modify GL texture source glClearColor(1.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2); glClearColor(0.0, 1.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, TEXTURE_WIDTH/2, 0, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2); glClearColor(0.0, 0.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, TEXTURE_HEIGHT/2, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2); glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2, 0, 0, TEXTURE_WIDTH/2, TEXTURE_HEIGHT/2); // Make current to VG content eglBindAPI(EGL_OPENVG_API); eglMakeCurrent(eglman->dpy, eglman->win_surface, eglman->win_surface, eglman->vg_ctx); // Draw VGImage target vgSetfv(VG_CLEAR_COLOR, 4, black); vgClear(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); vgSeti(VG_BLEND_MODE, VG_BLEND_SRC); vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgLoadIdentity(); vgTranslate(WINDOW_WIDTH/2.0f, WINDOW_HEIGHT/2.0f); vgScale((VGfloat)WINDOW_WIDTH/(VGfloat)TEXTURE_WIDTH * 0.8f, (VGfloat)WINDOW_HEIGHT/(VGfloat)TEXTURE_HEIGHT * 0.8f); vgTranslate(-TEXTURE_WIDTH/2.0f, -TEXTURE_HEIGHT/2.0f); vgDrawImage(eglman->vg_image); // Swap buffer eglSwapBuffers(eglman->dpy, eglman->win_surface); return; }
void display(float interval) { int x,y,p; VGfloat white[] = {1,1,1,1}; vgSetfv(VG_CLEAR_COLOR, 4, white); vgClear(0, 0, testWidth(), testHeight()); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); for (y=0, p=0; y<3; ++y) { for (x=0; x<3; ++x, ++p) { if (p > NUM_PRIMITIVES) break; vgLoadIdentity(); vgTranslate(100 + x*150, 100 + y*150); vgDrawPath(primitives[p], VG_STROKE_PATH); } } }
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); }
void createApple(VGPath p) { VGPath temp; VGubyte segs[] = { VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH, VG_MOVE_TO_ABS, VG_CUBIC_TO_ABS, VG_CUBIC_TO_ABS, VG_CLOSE_PATH }; VGfloat data[] = { 1.53125,-44.681982, -3.994719,-44.681982, -8.0085183,-50.562501, -26.5625,-50.562501, -42.918439,-50.562501, -56.46875,-34.239393, -56.46875,-12.187501, -56.46875,26.520416, -34.65822,61.731799, -16.84375,61.812499, -7.1741233,61.812499, -2.9337937,55.656199, 4.15625,55.656199, 11.746294,55.656199, 17.981627,62.281199, 25.4375,62.281199, 33.88615,62.281199, 50.53251,44.282999, 58.75,15.718799, 47.751307,9.086518, 40.999985,-0.228074, 41,-13.046574, 41,-27.849147, 46.64686,-34.763001, 52.4375,-39.937501, 46.111827,-47.219094, 39.0413,-50.503784, 29.09375,-50.446384, 11.146487,-50.342824, 8.6341912,-44.681982, 1.53125,-44.681982, 0.23972344,-52.075169, -2.8344902,-69.754133, 5.9303785,-81.915323, 24.152707,-86.881406, 23.71828,-70.367255, 15.114064,-58.365865, 0.23972344,-52.075169 }; temp = testCreatePath(); vgAppendPathData(temp, sizeof(segs), segs, data); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadIdentity(); vgScale(1,-1); vgTransformPath(p, temp); vgDestroyPath(temp); }