1 /*
2 drvrib.cpp - Driver to output RenderMan RIB polygons
3 - written by Glenn M. Lewis <glenn_AT_gmlewis.com> - 6/18/96
4 http://www.gmlewis.com/>
5 Based on...
6
7 drvSAMPL.cpp : This file is part of pstoedit
8 Skeleton for the implementation of new backends
9
10 Copyright (C) 1993 - 2014 Wolfgang Glunz, wglunz35_AT_pstoedit.net
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
26 */
27 #include "drvrib.h"
28 #include I_fstream
29 #include I_stdio
30 #include I_stdlib
31
32
derivedConstructor(drvRIB)33 drvRIB::derivedConstructor(drvRIB):
34 //(const char * driveroptions_p,ostream & theoutStream,ostream & theerrStream): // Constructor
35 constructBase
36 {
37 // driver specific initializations
38 // and writing of header to output file
39 outf << "##RenderMan RIB-Structure 1.0" << endl;
40 outf << "version 3.03" << endl;
41 outf << "AttributeBegin" << endl;
42 }
43
44 drvRIB::~drvRIB()
45 {
46 // driver specific deallocations
47 // and writing of trailer to output file
48 outf << "AttributeEnd" << endl;
49 options=0;
50 }
51
print_coords()52 void drvRIB::print_coords()
53 {
54 outf << "PointsGeneralPolygons[1]" << endl;
55 outf << "[" << numberOfElementsInPath() << "]" << endl << "[";
56 for (unsigned int i = 0; i < numberOfElementsInPath(); i++) {
57 outf << i << " ";
58 }
59 outf << "]" << endl << "\"P\" [";
60 for (unsigned int n = 0; n < numberOfElementsInPath(); n++) {
61 const basedrawingelement & elem = pathElement(n);
62 switch (elem.getType()) {
63 case moveto:{
64 const Point & p = elem.getPoint(0);
65 // outf << "\t\tmoveto ";
66 outf << p.x_ + x_offset << " " << p.y_ + y_offset << " 0 ";
67 }
68 break;
69 case lineto:{
70 const Point & p = elem.getPoint(0);
71 // outf << "\t\tlineto ";
72 outf << p.x_ + x_offset << " " << p.y_ + y_offset << " 0 ";
73 }
74 break;
75 case closepath: // Not supported
76 // outf << "\t\tclosepath ";
77 break;
78 case curveto:{ // Not supported
79 }
80 break;
81 default:
82 errf << "\t\tFatal: unexpected case in drvpdf " << endl;
83 abort();
84 break;
85 }
86 outf << endl;
87 }
88 outf << "]" << endl;
89 }
90
91
open_page()92 void drvRIB::open_page()
93 {
94 // outf << "Opening page: " << currentPageNumber << endl;
95 }
96
close_page()97 void drvRIB::close_page()
98 {
99 // outf << "Closing page: " << (currentPageNumber) << endl;
100 }
101
show_path()102 void drvRIB::show_path()
103 {
104 outf << "Color " << currentR() << " " << currentG() << " " << currentB() << endl;
105 print_coords();
106 }
107
108
109 static DriverDescriptionT < drvRIB > D_rib("rib", "RenderMan Interface Bytestream", "","rib", false, // if backend supports subpathes, else 0
110 // if subpathes are supported, the backend must deal with
111 // sequences of the following form
112 // moveto (start of subpath)
113 // lineto (a line segment)
114 // lineto
115 // moveto (start of a new subpath)
116 // lineto (a line segment)
117 // lineto
118 //
119 // If this argument is set to 0 each subpath is drawn
120 // individually which might not necessarily represent
121 // the original drawing.
122 false, // if backend supports curves, else 0
123 false, // if backend supports elements with fill and edges
124 false, // if backend supports text, else 0
125 DriverDescription::noimage, // no support for PNG file images
126 DriverDescription::normalopen,
127 false, // if format supports multiple pages in one file
128 false /*clipping */
129 );
130