lib2d = libindep and other comments

Previous    Next


I may sometimes used the name lib2d.c and sometimes libindep.c. These are the same - your DEVICE INDEPENDENT library of routines such as line_to(). For 3d I might use the name lib3d.c or lib3dindep.c or lib3indep.c at different times, again all the same. Routines in this file typically deal only with floating point coordinates.

Your DEVICE DEPENDENT routines, in a file with a name like liblpr.c or libdev.c, typically take integer arguments as is reasonable for purely device dependent routines on a device that only has integer coords.

How then can you call such a routine from libindep.c - which knows only floating point coords? One solution is to have a call such as enquire_device_(& struct device params) which exists in each device library and can be called from libindep.c. The struct device would be a structure containing quantities that are device dependent and could be of use to the device-independent library. For example:

struct device { int is_integer_device; int smin, smax; int tmin,tmax; possibly other stuff, maybe for colors };

Another solution is for libindep.c routines such as say line(x1,y1,x2,y2) to call a device dependent routine line_ndc_(u1,v1,u2,v2) which in turn calls the real routine line_(s1,t1,s2,t2) with integer coords. Here line_ndc_ would be in the device-dependent file and so would know the actual screen size and so could convert floats u,v in NDC coords to s,t in screen coords.

Other arrangements are also possible.


Previous   Next