{"id":13542899,"url":"https://github.com/ajstarks/openvg","last_synced_at":"2025-04-05T23:11:08.057Z","repository":{"id":4116323,"uuid":"5226803","full_name":"ajstarks/openvg","owner":"ajstarks","description":"Tools for exploring OpenVG","archived":false,"fork":false,"pushed_at":"2019-10-08T13:17:10.000Z","size":6313,"stargazers_count":416,"open_issues_count":22,"forks_count":84,"subscribers_count":31,"default_branch":"master","last_synced_at":"2025-03-29T22:09:03.338Z","etag":null,"topics":["drawing","font","graphics","graphics-programming","openvg","raspberry-pi","raspberry-pi-library"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ajstarks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-07-30T00:04:23.000Z","updated_at":"2025-02-21T06:52:31.000Z","dependencies_parsed_at":"2022-08-29T11:21:59.233Z","dependency_job_id":null,"html_url":"https://github.com/ajstarks/openvg","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajstarks%2Fopenvg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajstarks%2Fopenvg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajstarks%2Fopenvg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajstarks%2Fopenvg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajstarks","download_url":"https://codeload.github.com/ajstarks/openvg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247411235,"owners_count":20934653,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["drawing","font","graphics","graphics-programming","openvg","raspberry-pi","raspberry-pi-library"],"created_at":"2024-08-01T11:00:19.500Z","updated_at":"2025-04-05T23:11:08.034Z","avatar_url":"https://github.com/ajstarks.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# Testbed for exploring OpenVG on the Raspberry Pi.\n\n\u003ca href=\"http://www.flickr.com/photos/ajstarks/7811750326/\" title=\"rotext by ajstarks, on Flickr\"\u003e\u003cimg src=\"http://farm8.staticflickr.com/7249/7811750326_614ea891ae.jpg\" width=\"500\" height=\"281\" alt=\"rotext\"\u003e\u003c/a\u003e\n\n## First program\n\nHere is the graphics equivalent of \"hello, world\"\n\n\t// first OpenVG program\n\t// Anthony Starks (ajstarks@gmail.com)\n\t#include \u003cstdio.h\u003e\n\t#include \u003cstdlib.h\u003e\n\t#include \u003cunistd.h\u003e\n\t#include \"VG/openvg.h\"\n\t#include \"VG/vgu.h\"\n\t#include \"fontinfo.h\"\n\t#include \"shapes.h\"\n\t\n\tint main() {\n\t\tint width, height;\n\t\tchar s[3];\n\t\n\t\tinit(\u0026width, \u0026height);\t\t\t\t\t// Graphics initialization\n\t\n\t\tStart(width, height);\t\t\t\t\t// Start the picture\n\t\tBackground(0, 0, 0);\t\t\t\t\t// Black background\n\t\tFill(44, 77, 232, 1);\t\t\t\t\t// Big blue marble\n\t\tCircle(width / 2, 0, width);\t\t\t// The \"world\"\n\t\tFill(255, 255, 255, 1);\t\t\t\t\t// White text\n\t\tTextMid(width / 2, height / 2, \"hello, world\", SerifTypeface, width / 10);\t// Greetings \n\t\tEnd();\t\t\t\t\t\t   \t\t\t// End the picture\n\t\n\t\tfgets(s, 2, stdin);\t\t\t\t   \t\t// look at the pic, end with [RETURN]\n\t\tfinish();\t\t\t\t\t            // Graphics cleanup\n\t\texit(0);\n\t}\n\n\u003ca href=\"http://www.flickr.com/photos/ajstarks/7828969180/\" title=\"hellovg by ajstarks, on Flickr\"\u003e\u003cimg src=\"http://farm9.staticflickr.com/8436/7828969180_b73db3bf19.jpg\" width=\"500\" height=\"281\" alt=\"hellovg\"\u003e\u003c/a\u003e\n\n## API\n\n\u003ca href=\"http://www.flickr.com/photos/ajstarks/7717370238/\" title=\"OpenVG refcard by ajstarks, on Flickr\"\u003e\u003cimg src=\"http://farm8.staticflickr.com/7256/7717370238_1d632cb179.jpg\" width=\"500\" height=\"281\" alt=\"OpenVG refcard\"\u003e\u003c/a\u003e\n\nCoordinates are VGfloat values, with the origin at the lower left, with x increasing to the right, and y increasing up.\nOpenVG specifies colors as a VGfloat array containing red, green, blue, alpha values ranging from 0.0 to 1.0, but typically colors are specified as RGBA (0-255 for RGB, A from 0.0 to 1.0)\n\n### Window (canvas) functions\n\n\tvoid WindowClear() \nWindowClear clears the window to previously set background colour\n\n\tvoid AreaClear(unsigned int x, unsigned int y, unsigned int w, unsigned int h)\nAreaClear clears a given rectangle in window coordinates\n\n\tvoid WindowOpacity(unsigned int a)\nWindowOpacity sets the  window opacity\n\n\tvoid WindowPosition(int x, int y)\nWindowPosition moves the window to given position\n\n### Setup and shutdown\n\n\tvoid init(int *w, int *h)\nInitialize the graphics: width and height of the canvas are returned.  This should begin every program.\n\n\tvoid initWindowSize(int x, int y, unsigned int w, unsigned int h)\nInitialize with specific dimensions\n\n\tvoid finish() \nShutdown the graphics. This should end every program.\n\n\tvoid Start(int width, int height)\nBegin the picture, clear the screen with a default white, set the stroke and fill to black.\n\n\tvoid End()\nEnd the picture, rendering to the screen.\n\n\tvoid SaveEnd(char *filename)\nEnd the picture, rendering to the screen, save the raster to the named file as 4-byte RGBA words, with a stride of\nwidth*4 bytes. The program raw2png converts the \"raw\" raster to png.\n\n\tvoid saveterm(), restoreterm(), rawterm()\nTerminal settings, save current settings, restore settings, put the terminal in raw mode.\n\n### Attributes\n\n\tvoid setfill(float color[4])\nSet the fill color\n\n\tvoid Background(unsigned int r, unsigned int g, unsigned int b)\nFill the screen with the background color defined from RGB values.\n\n\tvoid BackgroundRGB(unsigned int r, unsigned int g, unsigned int b, VGfloat a)\nclears the screen to a background color with alpha\n\n\tvoid StrokeWidth(float width)\nSet the stroke width.\n\n\tvoid RGBA(unsigned int r, unsigned int g, unsigned int b, VGfloat a, VGfloat color[4])\nfill a color vector from RGBA values.\n\n\tvoid RGB(unsigned int r, unsigned int g, unsigned int b, VGfloat color[4])\nfill a color vector from RGB values.\n\n\tvoid Stroke(unsigned int r, unsigned int g, unsigned int b, VGfloat a)\nSet the Stroke color using RGBA values.\n\n\tvoid Fill(unsigned int r, unsigned int g, unsigned int b, VGfloat a)\nSet the Fill color using RGBA values.\n\n\tvoid FillLinearGradient(VGfloat x1, VGfloat y1, VGfloat x2, VGfloat y2, VGfloat *stops, int n)\nSet the fill to a linear gradient bounded by (x1, y1) and (x2, y2). using offsets and colors specified in n number of stops\n\n\tvoid FillRadialGradient(VGfloat cx, VGfloat cy, VGfloat fx VGfloat fy, VGfloat r, VGfloat *stops, int n)\nSet the fill to a radial gradient centered at (cx, cy) with radius r, and focal point at (fx, ry), using offsets and colors specified in n number of stops\n\n### Shapes\n\n\tvoid Line(VGfloat x1, VGfloat y1, VGfloat x2, VGfloat y2)\nDraw a line between (x1, y1) and (x2, y2).\n\n\tvoid Rect(VGfloat x, VGfloat y, VGfloat w, VGfloat h)\nDraw a rectangle with its origin (lower left) at (x,y), and size is (width,height).\n\n\tvoid RectOutline(VGfloat x, VGfloat y, VGfloat w, VGfloat h)\nOutlined version\n\n\tvoid Roundrect(VGfloat x, VGfloat y, VGfloat w, VGfloat h, VGfloat rw, VGfloat rh)\nDraw a rounded rectangle with its origin (lower left) at (x,y), and size is (width,height).  \nThe width and height of the corners are specified with (rw,rh).\n\n\tvoid RoundrectOutline(VGfloat x, VGfloat y, VGfloat w, VGfloat h, VGfloat rw, VGfloat rh)\nOutlined version\n\n\tvoid Polygon(VGfloat *x, VGfloat *y, VGint n)\nDraw a polygon using the coordinates in arrays pointed to by x and y.  The number of coordinates is n.\n\n\tvoid Polyline(VGfloat *x, VGfloat *y, VGint n)\nDraw a polyline using the coordinates in arrays pointed to by x and y.  The number of coordinates is n.\n\n\tvoid Circle(VGfloat x, VGfloat y, VGfloat d)\nDraw a circle centered at (x,y) with diameter d.\n\n\tvoid CircleOutline(VGfloat x, VGfloat y, VGfloat r)\nOutlined version\n\n\tvoid Ellipse(VGfloat x, VGfloat y, VGfloat w, VGfloat h)\nDraw an ellipse centered at (x,y) with radii (w, h).\n\n\tvoid EllipseOutline(VGfloat x, VGfloat y, VGfloat w, VGfloat h)\nOutlined version\n\n\tvoid Qbezier(VGfloat sx, VGfloat sy, VGfloat cx, VGfloat cy, VGfloat ex, VGfloat ey)\nDraw a quadratic bezier curve beginning at (sx, sy), using control points at (cx, cy), ending at (ex, ey).\n\n\tvoid QbezierOutline(VGfloat sx, VGfloat sy, VGfloat cx, VGfloat cy, VGfloat ex, VGfloat ey)\nOutlined version\n\n\tvoid Cbezier(VGfloat sx, VGfloat sy, VGfloat cx, VGfloat cy, VGfloat px, VGfloat py, VGfloat ex, VGfloat ey)\nDraw a cubic bezier curve beginning at (sx, sy), using control points at (cx, cy) and (px, py), ending at (ex, ey).\n\n\tvoid CbezierOutline(VGfloat sx, VGfloat sy, VGfloat cx, VGfloat cy, VGfloat px, VGfloat py, VGfloat ex, VGfloat ey) \nOutlined version\n\n\tvoid Arc(VGfloat x, VGfloat y, VGfloat w, VGfloat h, VGfloat sa, VGfloat aext)\nDraw an elliptical arc centered at (x, y), with width and height at (w, h).  Start angle (degrees) is sa, angle extent is aext.\n\n\tvoid ArcOutline(VGfloat x, VGfloat y, VGfloat w, VGfloat h, VGfloat sa, VGfloat aext)\nOutlined version\n\n### Text and Images\n\n\tvoid Text(VGfloat x, VGfloat y, char* s, Fontinfo f, int pointsize)\nDraw a the text srtring (s) at location (x,y), using pointsize.\n\n\tvoid TextMid(VGfloat x, VGfloat y, char* s, Fontinfo f, int pointsize)\nDraw a the text srtring (s) at centered at location (x,y), using pointsize.\n\n\tvoid TextEnd(VGfloat x, VGfloat y, char* s, Fontinfo f, int pointsize)\nDraw a the text srtring (s) at with its lend aligned to location (x,y), using pointsize\n\n\tVGfloat TextWidth(char *s, Fontinfo f, int pointsize)\nReturn the width of text\n\n\tVGfloat TextHeight(Fontinfo f, int pointsize)\nReturn a font's height\n\n\tTextDepth(Fontinfo f, int pointsize)\nReturn a font's distance beyond the baseline.\n\n\tvoid Image(VGfloat x, VGfloat y, int w, int h, char * filename)\nplace a JPEG image with dimensions (w,h) at (x,y).\n\n\t\n### Transformations\n\n\tvoid Translate(VGfloat x, VGfloat y)\nTranslate the coordinate system to (x,y).\n\n\tvoid Rotate(VGfloat r)\nRotate the coordinate system around angle r (degrees).\n\n\tvoid Scale(VGfloat x, VGfloat y)\nScale by x,y.\n\n\tvoid Shear(VGfloat x, VGfloat y)\nShear by the angles x,y.\n\n## Clipping\n\tvoid ClipRect(VGint x, VGint y, VGint w, VGint h)\nLimit drawing the drawing area to the specified rectangle, end with ClipEnd()\n\n\tvoid ClipEnd()\nEnds clipping area\n\n## Using fonts\n\nAlso included is the font2openvg program, which turns font information into C source that \nyou can embed in your program. The Makefile makes font code from files found in /usr/share/fonts/truetype/ttf-dejavu/. \nIf you want to use other fonts, adjust the Makefile accordingly, or generate the font code on your own once the font2openvg program is built.\n\nfont2openvg takes three arguments: the TrueType font file, the output file to be included and the prefix for identifiers.\nFor example to use the DejaVu Sans font:\n\n\t./font2openvg /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf DejaVuSans.inc DejaVuSans\n\nand include the generated code in your program:\n\n\t#include \"DejaVuSans.inc\"\n\tFontinfo DejaFont\n\t\nThe loadfont function creates OpenVG paths from the font data:\n\n\tloadfont(DejaVuSans_glyphPoints, \n            DejaVuSans_glyphPointIndices, \n        \tDejaVuSans_glyphInstructions,                \n        \tDejaVuSans_glyphInstructionIndices, \n            DejaVuSans_glyphInstructionCounts, \n            DejaVuSans_glyphAdvances,\n            DejaVuSans_characterMap, \n        \tDejaVuSans_glyphCount);\n\nThe unloadfont function releases the path information:\n\t\n\tunloadfont(DejaFont.Glyphs, DejaFont.Count);\n\nNote that the location of the font files may differ.  (The current location for Jessie is /usr/share/fonts/truetype/ttf-dejavu)\nUse the FONTLIB makefile variable to adjust this location.\n\n# Build and run\n\n\u003ci\u003eNote that you will need at least 64 Mbytes of GPU RAM:\u003c/i\u003e. You will also need the DejaVu fonts, and the jpeg and freetype libraries.\nThe indent tool is also useful for code formatting.  Install them via:\n\n\tpi@raspberrypi ~ $ sudo apt-get install libjpeg8-dev indent libfreetype6-dev ttf-dejavu-core\n\nNext, build the library and test:\n\n\tpi@raspberrypi ~ $ git clone git://github.com/ajstarks/openvg\n\tpi@raspberrypi ~ $ cd openvg\n\tpi@raspberrypi ~/openvg $ make\n\tg++ -I/usr/include/freetype2 fontutil/font2openvg.cpp -o font2openvg -lfreetype\n\t./font2openvg /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf DejaVuSans.inc DejaVuSans\n\t224 glyphs written\n\t./font2openvg /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf DejaVuSansMono.inc DejaVuSansMono\n\t224 glyphs written\n\t./font2openvg /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf DejaVuSerif.inc DejaVuSerif\n\t224 glyphs written\n\tgcc -O2 -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -c libshapes.c\n\tgcc -O2 -Wall -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -c oglinit.c\n\tpi@raspberrypi ~/openvg/client $ cd client\n\tpi@raspberrypi ~/openvg/client $ make test\n\tcc -Wall -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -o shapedemo shapedemo.c ../libshapes.o ../oglinit.o -L/opt/vc/lib -lGLESv2 -ljpeg\n\t./shapedemo demo 5\n\n\nThe program \"shapedemo\" exercises a high-level API built on OpenVG found in libshapes.c. \n\n\t./shapedemo                      # show a reference card\n\t./shapedemo raspi                # show a self-portrait\n\t./shapedemo image                # show four test images\n\t./shapedemo astro                # the sun and the earth, to scale\n\t./shapedemo text                 # show blocks of text in serif, sans, and mono fonts\n\t./shapedemo rand 10              # show 10 random shapes\n\t./shapedemo rotate 10 a          # rotated and faded \"a\"\n\t./shapedemo test \"hello, world\"  # show a test pattern, with \"hello, world\" at mid-display in sans, serif, and mono.\n\t./shapedemo fontsize             # show a range of font sizes (per \u003chttps://speakerdeck.com/u/idangazit/p/better-products-through-typography\u003e)\n\t./shapedemo demo 10              # run through the demo, pausing 10 seconds between each one; contemplate the awesome.\n\t\n\nTo install the shapes library as a system-wide shared library\n\t\n\tpi@raspberrypi ~/openvg $ make library\n\tpi@raspberrypi ~/openvg $ sudo make install\n\nThe openvg shapes library can now be used in C code by including shapes.h and fontinfo.h and linking with libshapes.so:\n\n\t#include \u003cshapes.h\u003e\n\t#include \u003cfontinfo.h\u003e\n\n\tpi@raspberrypi ~ $ gcc -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads anysource.c -o anysource -lshapes\n\tpi@raspberrypi ~ $ ./anysource\n\n\u003ca href=\"http://www.flickr.com/photos/ajstarks/7883988028/\" title=\"The Raspberry Pi, drawn by the Raspberry Pi by ajstarks, on Flickr\"\u003e\u003cimg src=\"http://farm9.staticflickr.com/8442/7883988028_21fd6533e0.jpg\" width=\"500\" height=\"281\" alt=\"The Raspberry Pi, drawn by the Raspberry Pi\"\u003e\u003c/a\u003e\n\n## Go wrapper\n\nA Go programming language wrapper for the library is found in openvg.go. Sample clients are in the directory go-client.  The API closely follows the C API; here is the \"hello, world\" program in Go:\n\n\u003ca href=\"https://godoc.org/github.com/ajstarks/openvg\"\u003eThe Go API\u003c/a\u003e\n\n\tpackage main\n\n\timport (\n\t\t\"bufio\"\n\t\t\"github.com/ajstarks/openvg\"\n\t\t\"os\"\n\t)\n\n\tfunc main() {\n\t\twidth, height := openvg.Init() // OpenGL, etc initialization\n\n\t\tw2 := openvg.VGfloat(width / 2)\n\t\th2 := openvg.VGfloat(height / 2)\n\t\tw := openvg.VGfloat(width)\n\n\t\topenvg.Start(width, height)                               // Start the picture\n\t\topenvg.BackgroundColor(\"black\")                           // Black background\n\t\topenvg.FillRGB(44, 77, 232, 1)                            // Big blue marble\n\t\topenvg.Circle(w2, 0, w)                                   // The \"world\"\n\t\topenvg.FillColor(\"white\")                                 // White text\n\t\topenvg.TextMid(w2, h2, \"hello, world\", \"serif\", width/10) // Greetings \n\t\topenvg.End()                                              // End the picture\n\t\tbufio.NewReader(os.Stdin).ReadBytes('\\n')                 // Pause until [RETURN]\n\t\topenvg.Finish()                                           // Graphics cleanup\n\t}\n\n\t\nTo build the wrapper: (make sure GOPATH is set)\n\n\tpi@raspberrypi ~/openvg $ go install .\n\tpi@raspberrypi ~/openvg $ cd go-client/hellovg\n\tpi@raspberrypi ~/openvg/go-client/hellovg $ go build .\n\tpi@raspberrypi ~/openvg/go-client/hellovg $ ./hellovg \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajstarks%2Fopenvg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajstarks%2Fopenvg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajstarks%2Fopenvg/lists"}