void applyStrokeStyle() { if (strokeStyle == DottedStroke) { VGfloat vgFloatArray[2] = { 1.0, 1.0 }; vgSetfv(VG_STROKE_DASH_PATTERN, 2, vgFloatArray); vgSetf(VG_STROKE_DASH_PHASE, 0.0); } else if (strokeStyle == DashedStroke) { if (!strokeDashArray.size()) { VGfloat vgFloatArray[2] = { 4.0, 3.0 }; vgSetfv(VG_STROKE_DASH_PATTERN, 2, vgFloatArray); } else { Vector<VGfloat> vgFloatArray(strokeDashArray.size()); for (int i = 0; i < strokeDashArray.size(); ++i) vgFloatArray[i] = strokeDashArray[i]; vgSetfv(VG_STROKE_DASH_PATTERN, vgFloatArray.size(), vgFloatArray.data()); } vgSetf(VG_STROKE_DASH_PHASE, strokeDashOffset); } else { vgSetfv(VG_STROKE_DASH_PATTERN, 0, 0); vgSetf(VG_STROKE_DASH_PHASE, 0.0); } ASSERT_VG_NO_ERROR(); }
static void vg_draw_message(vg_t *vg, const char *msg) { settings_t *settings = config_get_ptr(); if (!vg->mLastMsg || strcmp(vg->mLastMsg, msg)) vg_render_message(vg, msg); vgSeti(VG_SCISSORING, VG_FALSE); vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL); VGfloat origins[] = { vg->mScreenWidth * settings->video.msg_pos_x - 2.0f, vg->mScreenHeight * settings->video.msg_pos_y - 2.0f, }; vgSetfv(VG_GLYPH_ORIGIN, 2, origins); vgSetPaint(vg->mPaintBg, VG_FILL_PATH); vgDrawGlyphs(vg->mFont, vg->mMsgLength, vg->mGlyphIndices, NULL, NULL, VG_FILL_PATH, VG_TRUE); origins[0] += 2.0f; origins[1] += 2.0f; vgSetfv(VG_GLYPH_ORIGIN, 2, origins); vgSetPaint(vg->mPaintFg, VG_FILL_PATH); vgDrawGlyphs(vg->mFont, vg->mMsgLength, vg->mGlyphIndices, NULL, NULL, VG_FILL_PATH, VG_TRUE); vgSeti(VG_SCISSORING, VG_TRUE); vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL); }
static void rpi_draw_message(rpi_t *rpi, const char *msg) { if (!rpi->mLastMsg || strcmp(rpi->mLastMsg, msg)) rpi_render_message(rpi, msg); vgSeti(VG_SCISSORING, VG_FALSE); vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_STENCIL); VGfloat origins[] = { rpi->mScreenWidth * g_settings.video.msg_pos_x - 2.0f, rpi->mScreenHeight * g_settings.video.msg_pos_y - 2.0f, }; vgSetfv(VG_GLYPH_ORIGIN, 2, origins); vgSetPaint(rpi->mPaintBg, VG_FILL_PATH); vgDrawGlyphs(rpi->mFont, rpi->mMsgLength, rpi->mGlyphIndices, NULL, NULL, VG_FILL_PATH, VG_TRUE); origins[0] += 2.0f; origins[1] += 2.0f; vgSetfv(VG_GLYPH_ORIGIN, 2, origins); vgSetPaint(rpi->mPaintFg, VG_FILL_PATH); vgDrawGlyphs(rpi->mFont, rpi->mMsgLength, rpi->mGlyphIndices, NULL, NULL, VG_FILL_PATH, VG_TRUE); vgSeti(VG_SCISSORING, VG_TRUE); vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL); }
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 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); }
/******************************************************************************* * 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; }
// C function:: void vgSetfv(VGParamType type, VGint count, const VGfloat * // values); JNIEXPORT jint JNICALL Java_com_example_startvg_VG11_vgSetfv( JNIEnv* env, jobject obj, jint type, jint count, jobject values ){ jarray _array = (jarray) 0; jint _remaining; char *data = (char*) 0; jint vgSetfv_ret = FALSE; data = (char*)getPointer(env, values, &_array, &_remaining); if (_remaining < 0){ env->ThrowNew(AIOOBEClass, "In vgSetfv():: Empty Buffer -- _remaining < 0."); } vgSetfv( (VGParamType) type, (VGint) count, (const VGfloat *) data ); vgSetfv_ret = SUCCESS; exit: if ( _array ){ releasePointer(env, _array, data, JNI_FALSE); } return vgSetfv_ret; }
//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(); }
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 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()); } }
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); }
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; } }
/******************************************************************************* * 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; }
void createPattern() { VGfloat tileFill[] = {0,0,1,1}; vgSetParameteri(patternFill, VG_PAINT_TYPE, VG_PAINT_TYPE_PATTERN); vgSetParameteri(patternFill, VG_PAINT_PATTERN_TILING_MODE, tile[tindex]); vgSetfv(VG_TILE_FILL_COLOR, 4, tileFill); vgPaintPattern(patternFill, patternImage); }
static void init(void) { float clear_color[4] = {1.0, 1.0, 1.0, 1.0}; vgSetfv(VG_CLEAR_COLOR, 4, clear_color); lion = lion_create(); }
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]); } }
void CHuiVg10CanvasGc::DoClearRenderBuffer( CHuiCanvasRenderBuffer& aImage, const TRect & aRect ) { HUIFX_VG_INVARIANT(); const CHuiVg10CanvasRenderBuffer* vg10RenderBuffer = (const CHuiVg10CanvasRenderBuffer*) &aImage; const TInt COLOR_COMPONENTS = 4; VGfloat savedColor[COLOR_COMPONENTS]; vgGetfv(VG_CLEAR_COLOR, COLOR_COMPONENTS, savedColor); VGfloat color[COLOR_COMPONENTS] = { 0.0f, 0.0f, 0.0f, 0.0f }; vgSetfv(VG_CLEAR_COLOR, COLOR_COMPONENTS, color); vgClearImage(vg10RenderBuffer->Image(), aRect.iTl.iX, aRect.iTl.iY, aRect.Size().iWidth, aRect.Size().iHeight); vgSetfv(VG_CLEAR_COLOR, COLOR_COMPONENTS, savedColor); HUIFX_VG_INVARIANT(); }
void applyScissorRect() { if (scissoringEnabled) { vgSeti(VG_SCISSORING, VG_TRUE); vgSetfv(VG_SCISSOR_RECTS, 4, VGRect(scissorRect).toVGfloat()); } else vgSeti(VG_SCISSORING, VG_FALSE); ASSERT_VG_NO_ERROR(); }
// 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; }
static void draw(void) { static const VGint red_pixel = 255 << 24 | 255 << 16 | 0 << 8 | 0; static const VGint blue_pixel = 255 << 24 | 0 << 16 | 0 << 8 | 255; VGint i; vgSetfv(VG_CLEAR_COLOR, 4, red_color); vgClear(0, 0, window_width(), window_height()); vgFlush(); memset(data, 0, window_width() * window_height() * sizeof(VGint)); vgReadPixels(data, window_width() * sizeof(VGint), VG_lARGB_8888, 0, 0, window_width(), window_height()); fprintf(stderr, "Red 0 = 0x%x and at 600 = 0x%x\n", data[0], data[600]); for (i = 0; i < window_width() * window_height(); ++i) { assert(data[i] == red_pixel); } vgSetfv(VG_CLEAR_COLOR, 4, blue_color); vgClear(50, 50, 50, 50); vgFlush(); memset(data, 0, window_width() * window_height() * sizeof(VGint)); vgReadPixels(data, 50 * sizeof(VGint), VG_lARGB_8888, 50, 50, 50, 50); fprintf(stderr, "Blue 0 = 0x%x and at 100 = 0x%x\n", data[0], data[100]); for (i = 0; i < 50 * 50; ++i) { assert(data[i] == blue_pixel); } }
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); }
static void init(void) { VGfloat clearColor[] = {1.0f, 1.0f, 1.0f, 1.0f};/* white color */ VGfloat fillColor[] = {1.0f, 0.0f, 0.0f, 1.0f};/* red color */ static const VGubyte segments[4] = {VG_MOVE_TO_ABS, VG_SCCWARC_TO_ABS, VG_SCCWARC_TO_ABS, VG_CLOSE_PATH}; VGfloat data[12]; const VGfloat cx = 0, cy=29, width=80, height=40; const VGfloat hw = width * 0.5f; const VGfloat hh = height * 0.5f; data[0] = cx + hw; data[1] = cy; data[2] = hw; data[3] = hh; data[4] = 0; data[5] = cx - hw; data[6] = cy; data[7] = hw; data[8] = hh; data[9] = 0; data[10] = data[0]; data[11] = cy; vgSetfv(VG_CLEAR_COLOR, 4, clearColor); vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED); path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL); if (path == VG_INVALID_HANDLE) { return; } paint = vgCreatePaint(); if (paint == VG_INVALID_HANDLE) { vgDestroyPath(path); return; } vgAppendPathData(path, 4, segments, data); vgSetParameterfv(paint, VG_PAINT_COLOR, 4, fillColor); vgSetParameteri( paint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR); vgSetPaint(paint, VG_FILL_PATH); }
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 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); }
static void draw_line(VGFT_FONT_T *font, VGfloat x, VGfloat y, const char *text, int char_count, VGbitfield paint_modes) { if (char_count == 0) return; // Set origin to requested x,y VGfloat glor[] = { x, y }; vgSetfv(VG_GLYPH_ORIGIN, 2, glor); // Draw the characters in blocks to reuse buffer memory const char *curr_text = text; int chars_left = char_count; while (chars_left > CHAR_COUNT_MAX) { draw_chars(font, curr_text, CHAR_COUNT_MAX, paint_modes, 1); chars_left -= CHAR_COUNT_MAX; curr_text += CHAR_COUNT_MAX; } // Draw the last block draw_chars(font, curr_text, chars_left, paint_modes, 0); }
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; }
static void init(void) { static const VGubyte cmds[6] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS, VG_CLOSE_PATH}; static const VGfloat coords[] = { 0, 200, 300, 200, 50, 0, 150, 300, 250, 0}; path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); vgAppendPathData(path, 6, cmds, coords); fill = vgCreatePaint(); vgSetParameterfv(fill, VG_PAINT_COLOR, 4, green_color); vgSetPaint(fill, VG_FILL_PATH); vgSetfv(VG_CLEAR_COLOR, 4, white_color); }
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); } } }