PDA

View Full Version : Need some input regarding drawing glyphs using vgdrawglyph



deepak.dk
12-07-2009, 05:35 AM
Hi,
I am new to openvg and currently writing some test cases for openvg1.1.
I need some help using fonts and text rendering in openvg1.1.

openvg1.1 spec says glyphs can be represented using VGPath objects or VGImage objects.
Now let us see
void vgSetGlyphToImage(VGFont font,VGuint glyphIndex,VGImage image,const VGfloat glyphOrigin[2],const VGfloat escapement[2]);
here
1. what shall be shall be contained in "glyphIndex" ?
2. Is image is obtained by calling image = vgCreateImage(VGImageFormat format,VGint width, VGint height,VGbitfield allowedQuality) ?
If so, should the image be filled using
vgImageSubData(VGImage image,const void * data, VGint dataStride,VGImageFormat dataFormat,
VGint x, VGint y, VGint width, VGint height)?

I transformed *png, *jpg .. to openvg1.1 format.(different image formats like VG_sRGBX_8888, VG_sRGBA_8888 and so on ..) using PvrTextool
but such converted data when used in vgdrawglyph() gives an image data instead of a Font or glyph! :cry:
Can some one help me as where did I go wrong?
Thank you
Deepak

Ivo Moravec
12-08-2009, 05:21 PM
There's a thread (http://www.khronos.org/message_boards/viewtopic.php?f=6&t=1385) here about how to render fonts already.

To recap.
A VGFont object is a container for "a font" and all that encompasses.
A Glyph is a single character.
so when you do vgSetGlyphToImage(), you are assigning a character to a certain glyph index.
For example - a picture of the letter 'A' (in a VGImage) to that character 'A' (ascii 0x41) - the glyphindex.
Displaying text is then a matter of telling VG to print glyph 'A' then print glyph 'B'... all for some VGFont.

So, yes, make sure your VGImage is created normally, and filled with the data for the character you want it to represent. So, yes, use vgImageSubData to upload the glyph to the VGImage you will be using for that glyph. After setting the glyph, you can free the VGImage.

deepak.dk
12-11-2009, 05:45 AM
Hi Ivo,

Thank you for your post. :D
But I need some more clarification regarding glyph rendering.

1. I used vgSetGlyphToImage() to define a glyph. Imgae data is bitmap picture of character "G".
I observe that vgDrawImage (vgimage); and vgDrawGlyph(h_vgfont, ...); would result in similar display. I mean vgDrawGlyph() is also rendering a rectangular bitmap image of the character just like vgDrawImage().

Is there a way to draw just the character out line instead of the rectangular image of the selected character? I need just the letter "G" It shall not be enclosed in a Box. But here it looks like a photcopy of the image that I used. :(

2. I tried changing the color of the glyph using VGPaint. This did not work ( My bit map image of character was black and white).

Ivo Moravec
12-11-2009, 06:31 PM
A VGImage used as a glyph, is still an image, and works exactly the same way as a vgDrawImage(). [A VGFont just takes care of the placement details for you - the rendering is done internally basically just the same as if calling vgDrawPath() and vgDrawImage() with a different transformation matrix].

If you want transparency, I suggest you edit the image and set the alpha channel to 0 for the bits of image you do not wish to display (make sure to save as RGBA - not just plain RGB). Alternatively, pre-process the VGImage image with vgLookupSingle() to change the alpha value [if your image is grayscale, then the table you could generate with "for (int i=0; i<256; i++) table[i] = (i<<24) || (i<<16) || (i<<8) || (255-i);" {I think that should do the trick...}]. The default blend mode (VG_BLEND_SRC_OVR) will handle the composition when you render it.

Alternatively, you could create a path representation of the desired letters, and set the glyph to a VGPath (which, upon rendering, would then behave like a vgDrawPath() call).

deepak.dk
01-07-2010, 03:29 AM
Hi Ivo,

Thank you for your post. :)
Regards
Deepak