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 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); }
//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 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 : DoRotateOrigin * Description : Demonstrate the effect of rotating around the origin. *******************************************************************************/ void CTransforms::DoRotateOrigin() { // 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)); vgRotate((i32Zigzag - 350) / 15.0f); // 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); }
// C function:: void vgRotate(VGfloat angle); JNIEXPORT jint JNICALL Java_com_example_startvg_VG11_vgRotate( JNIEnv* env, jobject obj, jfloat angle){ vgRotate( (VGfloat) angle ); }
/******************************************************************************* * 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); }
void CNVGCSIcon::SetRotation() { if (iRotationAngle) { vgTranslate(iRotationX, iRotationY); vgRotate(iRotationAngle); vgTranslate(-iRotationX, -iRotationY); } }
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; }
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 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); }
// Rotate around angle r void Rotate(VGfloat r) { vgRotate(r); }