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); }
void InitializeOpenVGContext() { vgSeti(VG_PIXEL_LAYOUT, vgGeti(VG_SCREEN_LAYOUT)); vgSetf(VG_STROKE_LINE_WIDTH, 4); vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_SQUARE); vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_BEVEL); }
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); }
static bool rpi_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { rpi_t *rpi = (rpi_t*)data; if (width != rpi->mRenderWidth || height != rpi->mRenderHeight) { rpi->mRenderWidth = width; rpi->mRenderHeight = height; rpi_calculate_quad(rpi); vguComputeWarpQuadToQuad( rpi->x1, rpi->y1, rpi->x2, rpi->y1, rpi->x2, rpi->y2, rpi->x1, rpi->y2, // needs to be flipped, Khronos loves their bottom-left origin 0, height, width, height, width, 0, 0, 0, rpi->mTransformMatrix); vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgLoadMatrix(rpi->mTransformMatrix); } vgSeti(VG_SCISSORING, VG_FALSE); vgClear(0, 0, rpi->mScreenWidth, rpi->mScreenHeight); vgSeti(VG_SCISSORING, VG_TRUE); vgImageSubData(rpi->mImage, frame, pitch, rpi->mTexType, 0, 0, width, height); vgDrawImage(rpi->mImage); #ifdef HAVE_FREETYPE if (msg && rpi->mFontsOn) rpi_draw_message(rpi, msg); #else (void)msg; #endif eglSwapBuffers(rpi->mDisplay, rpi->mSurface); return true; }
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); }
void HbNvgEnginePrivate::restoreClientMatrices() { vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadMatrix(mPathMatrix); vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgLoadMatrix(mImageMatrix); vgSeti(VG_MATRIX_MODE, mMatrixMode); }
void CNVGCSIcon::RestoreClientMatrices() { vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgLoadMatrix(iPathMatrix); vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgLoadMatrix(iImageMatrix); vgSeti(VG_MATRIX_MODE, iMatrixMode); }
void CNVGCSIcon::UpdateClientMatrices() { iMatrixMode = vgGeti(VG_MATRIX_MODE); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgGetMatrix(iPathMatrix); vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgGetMatrix(iImageMatrix); vgSeti(VG_MATRIX_MODE, iMatrixMode); }
void SubtitleRenderer::initialize_vg() { // get an EGL display connection display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY); ENFORCE(display_); // initialize the EGL display connection ENFORCE(eglInitialize(display_, NULL, NULL)); // get an appropriate EGL frame buffer configuration static const EGLint attribute_list[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE }; EGLConfig config{}; EGLint num_config{}; ENFORCE(eglChooseConfig(display_, attribute_list, &config, 1, &num_config)); ENFORCE(num_config); ENFORCE(eglBindAPI(EGL_OPENVG_API)); static EGL_DISPMANX_WINDOW_T nativewindow; nativewindow.element = dispman_element_; nativewindow.width = buffer_width_; nativewindow.height = buffer_height_; surface_ = eglCreateWindowSurface(display_, config, &nativewindow, NULL); ENFORCE(surface_); // create an EGL rendering context context_ = eglCreateContext(display_, config, EGL_NO_CONTEXT, NULL); ENFORCE(context_); auto result = eglMakeCurrent(display_, surface_, surface_, context_); assert(result); vgSeti(VG_FILTER_FORMAT_LINEAR, VG_TRUE); assert(!vgGetError()); vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_NONANTIALIASED); assert(!vgGetError()); auto create_vg_font = [](VGFont& font) { font = vgCreateFont(64); ENFORCE(font); }; create_vg_font(vg_font_); create_vg_font(vg_font_border_); // VGfloat color[4] = { 1.0f, 0.0f, 0.0f, 1.0f }; // vgSetfv(VG_CLEAR_COLOR, 4, color); }
void HbNvgEnginePrivate::updateClientMatrices() { mMatrixMode = vgGeti(VG_MATRIX_MODE); vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); vgGetMatrix(mPathMatrix); vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgGetMatrix(mImageMatrix); vgSeti(VG_MATRIX_MODE, mMatrixMode); }
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(); }
static bool vg_frame(void *data, const void *frame, unsigned frame_width, unsigned frame_height, uint64_t frame_count, unsigned pitch, const char *msg) { unsigned width, height; vg_t *vg = (vg_t*)data; static struct retro_perf_counter vg_fr = {0}; static struct retro_perf_counter vg_image = {0}; rarch_perf_init(&vg_fr, "vg_fr"); retro_perf_start(&vg_fr); video_driver_get_size(&width, &height); if (frame_width != vg->mRenderWidth || frame_height != vg->mRenderHeight || vg->should_resize) { vg->mRenderWidth = frame_width; vg->mRenderHeight = frame_height; vg_calculate_quad(vg); matrix_3x3_quad_to_quad( vg->x1, vg->y1, vg->x2, vg->y1, vg->x2, vg->y2, vg->x1, vg->y2, /* needs to be flipped, Khronos loves their bottom-left origin */ 0, frame_height, frame_width, frame_height, frame_width, 0, 0, 0, &vg->mTransformMatrix); vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE); vgLoadMatrix(vg->mTransformMatrix.data); vg->should_resize = false; } vgSeti(VG_SCISSORING, VG_FALSE); vgClear(0, 0, width, height); vgSeti(VG_SCISSORING, VG_TRUE); rarch_perf_init(&vg_image, "vg_image"); retro_perf_start(&vg_image); vg_copy_frame(vg, frame, frame_width, frame_height, pitch); retro_perf_stop(&vg_image); vgDrawImage(vg->mImage); #if 0 if (msg && vg->mFontsOn) vg_draw_message(vg, msg); #endif gfx_ctx_update_window_title(vg); retro_perf_stop(&vg_fr); gfx_ctx_swap_buffers(vg); return true; }
void PainterOpenVG::setAntialiasingEnabled(bool enabled) { ASSERT(m_state); m_surface->makeCurrent(); m_state->antialiasingEnabled = enabled; if (enabled) vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_FASTER); else vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED); }
void SubtitleRenderer:: initialize_fonts(const std::string& font_path, float font_size) { ENFORCE(!FT_Init_FreeType(&ft_library_)); ENFORCE2(!FT_New_Face(ft_library_, font_path.c_str(), 0, &ft_face_), "Unable to open font"); ENFORCE(!FT_Set_Pixel_Sizes(ft_face_, 0, font_size*screen_height_)); auto get_bbox = [this](char32_t cp) { auto glyph_index = FT_Get_Char_Index(ft_face_, cp); ENFORCE(!FT_Load_Glyph(ft_face_, glyph_index, FT_LOAD_NO_HINTING)); FT_Glyph glyph; ENFORCE(!FT_Get_Glyph(ft_face_->glyph, &glyph)); SCOPE_EXIT {FT_Done_Glyph(glyph);}; FT_BBox bbox; FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_PIXELS, &bbox); return bbox; }; constexpr float padding_factor = 0.05f; int y_min = get_bbox('g').yMin; int y_max = get_bbox('M').yMax; y_max += -y_min*0.7f; line_height_ = y_max - y_min; const int v_padding = line_height_*padding_factor + 0.5f; line_height_ += v_padding*2; box_offset_ = y_min-v_padding; box_h_padding_ = line_height_/5.0f + 0.5f; constexpr float border_thickness = 0.045f; ENFORCE(!FT_Stroker_New(ft_library_, &ft_stroker_)); FT_Stroker_Set(ft_stroker_, line_height_*border_thickness*64.0f, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0); vgSeti(VG_FILTER_FORMAT_LINEAR, VG_TRUE); assert(!vgGetError()); vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_NONANTIALIASED); assert(!vgGetError()); auto create_vg_font = [](VGFont& font) { font = vgCreateFont(128); ENFORCE(font); }; create_vg_font(vg_font_); create_vg_font(vg_font_border_); }
HbNvgEnginePrivate::HbNvgEnginePrivate(): mCurrentBufferSize(1, 1), mRotateAngle(0.0), mCentreX(0.0), mCentreY(0.0), mPreserveAspectSetting(HbNvgEngine::NvgPreserveAspectRatioXmidYmid), mSmilFitSetting(HbNvgEngine::NvgMeet), mCurrentNvgIcon(0), mLastError(HbNvgEngine::NvgErrNone), mMirrored(false) { vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER); vgSeti(VG_FILL_RULE, VG_NON_ZERO); }
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 : 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; }
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()); } }
//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 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); }
void OpenVG_SVGHandler::draw() { vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); // clear out the transform stack _transform_stack.clear(); float m[9]; vgGetMatrix( m ); // assume the current openvg matrix is like the camera matrix and should always be applied first Transform2d top; Transform2d::multiply( top, Transform2d(m), rootTransform() ); // multiply by the root transform pushTransform( top ); // SVG is origin at the top, left (openvg is origin at the bottom, left) // so need to flip // Transform2d flip; // flip.setScale( 1, -1 ); // pushTransform( flip ); if( _batch ) { vgLoadMatrix( topTransform().m ); vgDrawBatchMNK( _batch ); } else { draw_recursive( _root_group ); } vgLoadMatrix( m ); // restore matrix _transform_stack.clear(); }
/******************************************************************************* * 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); }
/******************************************************************************* * 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); }
/******************************************************************************* * 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 : 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; }
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 PainterOpenVG::setLineJoin(LineJoin lineJoin) { ASSERT(m_state); m_surface->makeCurrent(); m_state->strokeLineJoin = lineJoin; vgSeti(VG_STROKE_JOIN_STYLE, toVGJoinStyle(lineJoin)); ASSERT_VG_NO_ERROR(); }
/******************************************************************************* * 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); }