1 //
2 // "$Id: glp.h,v 1.3 2005/05/31 11:28:13 vierinen Exp $"
3 //
4 //   Header file for the GLP library, an OpenGL printing toolkit.
5 //
6 //   The GLP library is distributed under the terms of the GNU Library
7 //   General Public License which is described in the file "COPYING.LIB".
8 //   If you use this library in your program, please include a line reading
9 //   "OpenGL Printing Toolkit by Michael Sweet" in your version or copyright
10 //   output.
11 //
12 // Revision History:
13 //
14 //   $Log: glp.h,v $
15 //   Revision 1.3  2005/05/31 11:28:13  vierinen
16 //   ads
17 //
18 //   Revision 1.2  2005/05/31 10:39:03  vierinen
19 //   apple?
20 //
21 //   Revision 1.1.1.1  2005/05/31 06:29:21  vierinen
22 //   ads
23 //
24 //   Revision 1.1  2003/02/06 09:37:54  jpr
25 //   *** empty log message ***
26 //
27 //   2003/02/01  Juha Ruokolainen CSC
28 //   Added protos for binary tree handling in GLPcontex
29 //   Revision 1.2  1996/07/13  12:52:02  mike
30 //   Changed the public methods to 'virtual'.
31 //
32 //   Revision 1.1  1996/06/27  03:07:13  mike
33 //   Initial revision
34 //
35 
36 #ifndef _GL_GLP_H_
37 #  define _GL_GLP_H_
38 #include "../../config.h"
39 
40 #if defined(WIN32) ||defined(MINGW32)
41 #include <windows.h>
42 #include <direct.h>
43 #include <wingdi.h>
44 #include <windef.h>
45 #endif
46 
47 
48 //
49 // Include necessary headers.
50 //
51 #include <GL/gl.h>
52 #include "../../config.h"
53 
54 
55 
56 #  include <iostream>
57 #  include <fstream>
58 
59 
60 //
61 // Printing options...
62 //
63 
64 #  define GLP_FIT_TO_PAGE	1	// Fit the output to the page
65 #  define GLP_AUTO_CROP		2	// Automatically crop to geometry
66 #  define GLP_GREYSCALE		4	// Output greyscale rather than color
67 #  define GLP_REVERSE		8	// Reverse grey shades
68 #  define GLP_DRAW_BACKGROUND	16	// Draw the background color
69 
70 //
71 // OpenGL configuration options...
72 //
73 
74 #  define GLP_RGBA		0	// RGBA mode window
75 #  define GLP_COLORINDEX	1	// Color index mode window
76 
77 //
78 // Error codes...
79 //
80 
81 #  define GLP_SUCCESS		0	// Success - no error occurred
82 #  define GLP_OUT_OF_MEMORY	-1	// Out of memory
83 #  define GLP_NO_FEEDBACK	-2	// No feedback data available
84 #  define GLP_ILLEGAL_OPERATION	-3	// Illegal operation of some kind
85 
86 
87 //
88 // Various structures used for sorting feedback data prior to printing...
89 //
90 
91 typedef GLfloat GLPrgba[4];	// GLPrgba array structure for sanity
92 typedef GLfloat GLPxyz[3];	// GLPxyz array structure for sanity
93 
94 struct GLPvertex	//// GLPvertex structure
95 {
96   GLPxyz	xyz;		// Location of vertex
97   GLPrgba	rgba;		// Color of vertex (alpha may be used later)
98 };
99 
100 struct GLPprimitive	//// GLPprimitive structure
101 {
102   GLPprimitive	*left, *right;  // left right pointers of the depth sort tree
103   GLboolean	shade;		// GL_TRUE if this primitive should be shaded
104   GLfloat	zmin, zmax;	// Min and max depth values
105   int		num_verts;	// Number of vertices used
106   GLPvertex	verts[3];	// Up to 3 vertices
107 };
108 
109 struct GLPbbox		//// GLPbbox structure
110 {
111   GLPbbox	*next,		// Next bounding box in list
112 		*prev;		// Previous bounding box in list
113   GLPprimitive	*primitives,	// Primitives inside this box
114                 *lastprim;
115   GLfloat	min[3],		// Minimum X, Y, Z coords
116 		max[3];		// Maximum X, Y, Z coords
117 };
118 
119 //
120 // The GLPcontext class provides all the basic functionality to support
121 // OpenGL feedback-based printing to vector/polygon printing devices or
122 // file formats.  For raster-only devices you are probably better off with
123 // an off-screen bitmap.
124 //
125 
126 class GLPcontext	//// GLPcontext class
127 {
128   protected:
129 	  int		options;	// Printing options
130 	  GLPbbox	*bboxes;	// Primitive data
131 	  GLPprimitive  *tree;		// Primitive data
132 	  int		feedsize;	// Feedback buffer size
133 	  GLfloat	*feedback;	// Feedback data
134 	  int		feedmode;	// Feedback mode (RGBA or colormap)
135 	  int		colorsize;	// Colormap size
136           GLPrgba	*colormap;	// Colorindex mapping to RGBA vals
137 
138           void add_primitive(GLboolean depth, GLboolean shade,
139                              int num_verts, GLPvertex *verts);
140           void sort_primitive(GLboolean depth, GLPbbox *bbox,
141                               GLPprimitive *newprim);
142           void add_tree( GLPprimitive **tree, GLPprimitive *prim);
143           void add_subtree( GLPprimitive **tree, GLPprimitive *prim);
144           int  get_vertex(GLPvertex *v, GLfloat *p);
145           void delete_all(void);
146           void delete_tree(GLPprimitive *tree);
147 
148   public:
149           virtual ~GLPcontext(void);
150 
151           virtual int StartPage(int mode = GLP_RGBA);
152           virtual int StartPage(int     mode,
153                         	int     size,
154                         	GLPrgba *rgba);
155 	  virtual int UpdatePage(GLboolean more);
156 	  virtual int EndPage(void);
157 
158 	  virtual void SetOptions(int print_options);
159 };
160 
161 #endif // !_GL_GLP_H_
162 
163 //
164 // End of "$Id: glp.h,v 1.3 2005/05/31 11:28:13 vierinen Exp $".
165 //
166