Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

ShapeGen: C++ implementation of a 2-D polygonal shape generator

Author: Jerry R. VanAken
Date: 9/19/2020

The core of a 2-D graphics library is the polygonal shape generator, which takes a graphical shape specified in terms of curves, arcs, and line segments, and converts this shape to a list of nonoverlapping trapezoids that can be passed to a renderer and filled on a graphics display.

This GitHub project contains the C++ source code for the ShapeGen class, which is a portable, lightweight polygonal shape generator. The ShapeGen class implementation is neither platform-specific nor device-dependent, and is readily ported to any computing environment for which a C++ compiler is available.

To form a fully functioning graphics library, the shape generator must be paired with a renderer, which draws the shapes on the graphics output device. Whereas the renderer is necessarily device-dependent and/or platform-specific, the shape generator should be free of such dependencies.

The demonstration software in this GitHub project contains example renderers that run in Linux and Windows. For either operating system, the project includes examples of both basic renderers (with no antialiasing) and antialiasing renderers.

Developers can easily replace the example renderers in this project with custom renderers that conform to a simple, well-defined interface. The ShapeGen object performs all clipping of shapes before passing them to the renderer to be drawn.

The geometric primitives in the ShapeGen graphics library are similar to the path-construction operators in the PostScript language. The ShapeGen graphics library has these features:

  • Shape boundaries can be specified with any combination of line segments, rectangles, ellipses, elliptic arcs, and Bezier curves (both quadratic and cubic).

  • Shapes can be filled or stroked.

  • Shapes can be filled according to either the even-odd (aka parity) fill rule, or the nonzero-winding-number fill rule.

  • Stroked shapes can be constructed with user-specified line widths, dashed line patterns, join styles, and line caps.

  • Both filled and stroked shapes are automatically clipped before they are rendered.

  • Clipping regions can be set to arbitrarily shaped areas. In addition, arbitrarily shaped areas can be masked off from the clipping region.

By default, ShapeGen library users specify shapes with integer x-y coordinates. But shapes can optionally be specified with fixed-point coordinate values if additional precision is required. Thus, developers can test their custom algorithms for drawing curves and arcs free of coordinate round-off or truncation errors.

Demo program

Included with the source code in this GitHub project is a demo program that shows off ShapeGen features. The demo code is configured to build and run in any of the following environments:

  • SDL2 (Simple DirectMedia Layer) in Linux

  • SDL2 in Windows

  • Win32 API in Windows

The make files and platform-specific code for these environments are included in the linux-sdl, windows-sdl, and windows-gdi subdirectories in this project. Each subdirectory contains a README file with instructions for setting up the build environment and making the demo.

The window size for the demo is set at 1280-by-960.

ShapeGen documentation

The userdoc.pdf file in this GitHub project contains the ShapeGen User's Guide. This guide discusses general principles of operation, describes the functions in the ShapeGen programming interface, and includes numerous code examples. The source code for these code examples is also included in the demo.cpp file, and is executed at the end of the demo program.

For a high-level overview of ShapeGen capabilities and internal operation, see ShapeGen: A lightweight, open-source 2−D graphics library written in C++ on the ResearchGate website.

For an in-depth discussion of the parametric ellipse algorithm that ShapeGen uses to draw circles, ellipses, elliptic arcs, elliptic splines, and rounded rectangles, see A Fast Parametric Ellipse Algorithm on the arXiv website.

Project files

The source files in the main directory of this GitHub project contain no platform-specific code. The small amount of platform-specific code needed for the demo program is relegated to the linux-sdl, windows-sdl, and windows-gdi subdirectories.

This GitHub project includes the following files and directories.

Main directory

  • README.md – This README file

  • userdoc.pdfShapeGen User's Guide

  • arc.cpp – ShapeGen member functions for adding ellipses, elliptic arcs, elliptic splines, and rounded rectangles to paths

  • curve.cpp – ShapeGen member functions for adding quadratic and cubic Bezier spline curves to paths

  • demo.cpp – ShapeGen application code called by the demo program

  • edge.cpp – ShapeGen member functions for converting paths to lists of polygonal edges, for clipping shapes defined by polygonal edge lists, and for feeding shape information to renderers

  • path.cpp – ShapeGen member functions for managing path construction, for setting path attributes, and for adding line segments and rectangles to paths

  • stroke.cpp – ShapeGen member functions for stroking paths, and for setting the attributes of stroked paths

  • textapp.cpp – Application code that uses the ShapeGen functions to construct the simple graphical text used in the demo program

  • thinline.cpp – ShapeGen internal code for constructing thin, stroked line segments that mimic the appearance of lines drawn by the Bresenham line algorithm

  • demo.h – Header file for the demo program

  • shapegen.h – ShapeGen public header file

  • shapepri.h – ShapeGen private header file

linux-sdl subdirectory

  • README.md – Instructions for installing the build environment and making the version of the ShapeGen demo that runs on SDL2 in Linux

  • Makefile – The make file that builds the ShapeGen demo for SDL2 in Linux

  • sdlmain.cpp – Contains the SDL2 main program, two example renderers, and all the platform-specific code needed to run the ShapeGen demo on SDL2 in Linux

windows-sdl subdirectory

  • README.md – Instructions for installing the build environment and making the version of the ShapeGen demo that runs on SDL2 in Windows

  • Makefile – The make file that builds the ShapeGen demo for SDL2 in Windows

  • sdlmain.cpp – Contains the SDL2 main program, two example renderers, and all the platform-specific code needed to run the ShapeGen demo on SDL2 in Windows

  • sdlpath.cmd – Adds the directory containing the SDL2 DLL files to the path environment variable in Windows

windows-gdi subdirectory

  • README.md – Instructions for installing the build environment and making the version of the ShapeGen demo that runs on the Win32 API in Windows

  • Makefile – The make file that builds the ShapeGen demo for the Win32 API in Windows

  • winmain.cpp – Contains the WinMain program, two example renderers, and all the platform-specific code needed to run the ShapeGen demo on the Win32 API in Windows

.

.

.

.

.

About

ShapeGen: A C++ implementation of a 2-D polygonal shape generator

Resources

License

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.