Posts: 8
Joined: Sun Aug 31, 2014 12:14 pm
Location: North Carolina, USA
Contact: Website

Using Polyline

Sat Oct 07, 2017 1:16 am

I am working with a Raspberry Pi B+, trying to make an interactive display for a car I am building. I can draw text and rectangles with openVG, but several days of trying to draw polygons has ended with, uh, no polygons. Pointers are not my strong suit, so it is probably the problem.
I have the usual includes - like I said, text and rectangle work, and then the code

int main()
VGfloat *LX,*LY;
VGfloat Left_X[5] = {50,100,75,100,50};
VGfloat Left_Y[5] ={100,125,100,75,100};
VGint npt = 5;
LX = &Left_X[0];
LY = &Left_Y[0];




Any help would be greatly appreciated,

User avatar
Posts: 1715
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Using Polyline

Sat Oct 07, 2017 2:48 am

You need to call StrokeWidth(VGfloat width); with the width you want strokes to be drawn (typically 1.0f). Start(); calls StrokeWidth(0.0f); which disables drawing of strokes (strokes are the edges of shapes) and lines are only drawn as strokes. You'll also want to set the colour of the stroke with Stroke(unsigned int r, unsigned int g, unsigned int b, VGfloat a); as the stroke uses a separate paint to the fill. Note that strokes are drawn half a width either side perpendicular to an edge / line.

Be aware that with StrokeWidth set >0.0f then all the shapes will have an outline drawn as well as being filled so don't forget to set it back to 0.0f if you don't want that.

StrokeWidth() also sets the stroke end cap style to butt (strokes don't extend half a width past the line ends) and the line join style to miter (so corners between two lines do extend past the line ends in a way that creates a sharp point). The libshapes library doesn't have functions for setting the end caps or join style, you'd have to use the actual OpenVG calls yourself if you want to change them.

Start(); sets the Fill and Stroke paints to a solid colour of (0, 0, 0, 1.0f) i.e. opaque black, and the StrokeWidth to 0.0f i.e. no strokes will be drawn.
She who travels light — forgot something.

Posts: 8
Joined: Sun Aug 31, 2014 12:14 pm
Location: North Carolina, USA
Contact: Website

Re: Using Polyline

Sat Oct 07, 2017 5:51 am

Egads, it works! Turns out that the default color is 0,0,0- which was the color of the background, and increasing the width from zero also helped. Adding StrokeWidth(10), and Stroke(255,0,0) fixed my problem!
Happy Pi

Return to “OpenVG”

Who is online

Users browsing this forum: No registered users and 1 guest