reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofCairoRenderer.h
Go to the documentation of this file.
1#pragma once
2
3#include "cairo.h"
5#include "ofPath.h"
6#include "of3dGraphics.h"
7
8#include "ofPixels.h"
9#include <deque>
10#include <stack>
11
13public:
16
17 static const std::string TYPE;
18 const std::string & getType(){ return TYPE; }
19
26
27 void setup(const of::filesystem::path & filename, Type type=ofCairoRenderer::FROM_FILE_EXTENSION, bool multiPage=true, bool b3D=false, ofRectangle outputsize = ofRectangle(0,0,0,0));
28 void setupMemoryOnly(Type _type, bool multiPage=true, bool b3D=false, ofRectangle viewport = ofRectangle(0,0,0,0));
29 void close();
30 void flush();
31
32 void startRender();
33 void finishRender();
34
36 void draw(const ofPath & shape) const;
37 void draw(const ofPath::Command & path) const;
38 void draw(const ofPolyline & poly) const;
39 void draw(const ofMesh & vertexData, ofPolyRenderMode mode, bool useColors, bool useTextures, bool useNormals) const;
40 void draw(const of3dPrimitive& model, ofPolyRenderMode renderType ) const;
41 void draw(const ofNode& node) const;
42 void draw(const std::vector<glm::vec3> & vertexData, ofPrimitiveMode drawMode) const;
43 void draw(const ofImage & img, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const;
44 void draw(const ofFloatImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const;
45 void draw(const ofShortImage & image, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const;
46 void draw(const ofBaseVideoDraws & video, float x, float y, float w, float h) const;
47 ofPath & getPath();
48
49 //--------------------------------------------
50 // transformations
51 void pushView();
52 void popView();
53
54 // setup matrices and viewport (upto you to push and pop view before and after)
55 // if width or height are 0, assume windows dimensions (ofGetWidth(), ofGetHeight())
56 // if nearDist or farDist are 0 assume defaults (calculated based on width / height)
58 void viewport(float x = 0, float y = 0, float width = -1, float height = -1, bool invertY = true);
59 void setupScreenPerspective(float width = -1, float height = -1, float fov = 60, float nearDist = 0, float farDist = 0);
60 void setupScreenOrtho(float width = -1, float height = -1, float nearDist = -1, float farDist = 1);
63 int getViewportWidth() const;
64 int getViewportHeight() const;
65
66 void setOrientation(ofOrientation orientation, bool vFlip);
67 bool isVFlipped() const;
68 void loadViewMatrix(const glm::mat4 & m);
69 void multViewMatrix(const glm::mat4 & m);
70 glm::mat4 getCurrentViewMatrix() const;
71 glm::mat4 getCurrentNormalMatrix() const;
72 glm::mat4 getCurrentOrientationMatrix() const;
73 void setCircleResolution(int);
74
75
76 void setCoordHandedness(ofHandednessType handedness);
78
79 // drawing modes
80 void setRectMode(ofRectMode mode);
82 void setFillMode(ofFillFlag fill);
84 void setLineWidth(float lineWidth);
85 void setDepthTest(bool depthTest);
86 void setBlendMode(ofBlendMode blendMode);
87 void setLineSmoothing(bool smooth);
88 void enableAntiAliasing();
90
91 //our openGL wrappers
92 void pushMatrix();
93 void popMatrix();
94 glm::mat4 getCurrentMatrix(ofMatrixMode matrixMode_) const;
95 void translate(float x, float y, float z = 0);
96 void translate(const glm::vec3 & p);
97 void scale(float xAmnt, float yAmnt, float zAmnt = 1);
98 void rotateRad(float radians, float vecX, float vecY, float vecZ);
99 void rotateXRad(float radians);
100 void rotateYRad(float radians);
101 void rotateZRad(float radians);
102 void rotateRad(float radians);
103 void matrixMode(ofMatrixMode mode);
104 void loadIdentityMatrix (void);
105 void loadMatrix (const glm::mat4 & m);
106 void loadMatrix (const float * m);
107 void multMatrix (const glm::mat4 & m);
108 void multMatrix (const float * m);
109
110 // screen coordinate things / default gl values
112 void setupScreen();
113
114 // color options
115 void setColor(int r, int g, int b); // 0-255
116 void setColor(int r, int g, int b, int a); // 0-255
117 void setColor(const ofColor & color);
118 void setColor(const ofColor & color, int _a);
119 void setColor(int gray); // new set a color as grayscale with one argument
120 void setHexColor( int hexColor ); // hex, like web 0xFF0033;
121
122 // bg color
123 void setBackgroundColor(const ofColor & c);
125 void background(const ofColor & c);
126 void background(float brightness);
127 void background(int hexColor, float _a=255.0f);
128 void background(int r, int g, int b, int a=255);
129
130 void setBackgroundAuto(bool bManual); // default is true
131 bool getBackgroundAuto();
132
133 void clear();
134 void clear(float r, float g, float b, float a=0);
135 void clear(float brightness, float a=0);
136 void clearAlpha();
137
139
140 ofStyle getStyle() const;
141 void pushStyle();
142 void popStyle();
143 void setStyle(const ofStyle & style);
144 void setCurveResolution(int resolution);
146
147 // drawing
148 void drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const;
149 void drawRectangle(float x, float y, float z, float w, float h) const;
150 void drawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) const;
151 void drawCircle(float x, float y, float z, float radius) const;
152 void drawEllipse(float x, float y, float z, float width, float height) const;
153 void drawString(std::string text, float x, float y, float z) const;
154 void drawString(const ofTrueTypeFont & font, std::string text, float x, float y) const;
155
156 // cairo specifics
157 cairo_t * getCairoContext();
158 cairo_surface_t * getCairoSurface();
161
162
163 virtual void bind(const ofCamera & camera, const ofRectangle & viewport){}
164 virtual void unbind(const ofCamera & camera){}
165
166 const of3dGraphics & get3dGraphics() const;
168
169private:
170 glm::vec3 transform(glm::vec3 vec) const;
171 static _cairo_status stream_function(void *closure,const unsigned char *data, unsigned int length);
172 void draw(const ofPixels & img, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const;
173
174 mutable std::deque<glm::vec3> curvePoints;
175 cairo_t * cr;
176 cairo_surface_t * surface;
177 bool bBackgroundAuto;
178
179 std::stack<cairo_matrix_t> matrixStack;
180
181 Type type;
182 int page;
183 bool multiPage;
184
185 // 3d transformation
186 bool b3D;
187 of3dGraphics graphics3d;
188
189 glm::mat4 projection;
190 glm::mat4 modelView;
191 ofRectangle viewportRect, originalViewport;
192
193 std::stack<glm::mat4> projectionStack;
194 std::stack<glm::mat4> modelViewStack;
195 std::stack<ofRectangle> viewportStack;
196
197 ofMatrixMode currentMatrixMode;
198
199 std::vector<glm::vec3> sphereVerts;
200 std::vector<glm::vec3> spherePoints;
201
202 of::filesystem::path filename;
203 ofBuffer streamBuffer;
204 ofPixels imageBuffer;
205
206 ofStyle currentStyle;
207 std::deque <ofStyle> styleHistory;
208 ofPath path;
209};
Definition of3dGraphics.h:445
A class representing a 3d primitive.
Definition of3dPrimitives.h:12
The base renderer interface.
Definition ofGraphicsBaseTypes.h:279
virtual void draw(const ofPolyline &poly) const =0
Draw a polyline with this renderer.
A base class representing a drawable video source.
Definition ofVideoBaseTypes.h:103
Definition ofFileUtils.h:15
Definition ofCairoRenderer.h:12
void scale(float xAmnt, float yAmnt, float zAmnt=1)
Scale this renderer's current matrix by xAmnt, yAmnt, and zAmnt.
Definition ofCairoRenderer.cpp:796
void rotateXRad(float radians)
Rotate this renderer's current matrix by degrees about the x axis.
Definition ofCairoRenderer.cpp:882
void rotateRad(float radians, float vecX, float vecY, float vecZ)
Rotate this renderer's current matrix by degrees about a euler.
Definition ofCairoRenderer.cpp:866
void setupGraphicDefaults()
setup the default graphics settings for this renderer.
Definition ofCairoRenderer.cpp:1149
ofPath & getPath()
Get a reference to the path used internally by this renderer.
Definition ofCairoRenderer.cpp:623
void setRectMode(ofRectMode mode)
Set this renderer's rect mode.
Definition ofCairoRenderer.cpp:628
void drawString(std::string text, float x, float y, float z) const
Draw text with this renderer using the current bitmap text mode.
virtual void bind(const ofCamera &camera, const ofRectangle &viewport)
Bind camera's matrices to this renderer's matrix stack.
Definition ofCairoRenderer.h:163
void setHexColor(int hexColor)
Set the global color this renderer will use when drawing.
Definition ofCairoRenderer.cpp:740
ofBuffer & getContentBuffer()
Definition ofCairoRenderer.cpp:1383
void popMatrix()
Pops this renderer's current matrix stack.
Definition ofCairoRenderer.cpp:767
void setStyle(const ofStyle &style)
Set this renderer's current style object.
Definition ofCairoRenderer.cpp:158
void setLineSmoothing(bool smooth)
Enable/disable line smoothing for this renderer if it's supported.
Definition ofCairoRenderer.cpp:707
ofStyle getStyle() const
Get this renderer's current style object.
Definition ofCairoRenderer.cpp:1192
void flush()
Definition ofCairoRenderer.cpp:116
void drawEllipse(float x, float y, float z, float width, float height) const
Draw an ellipse using a 3D point, width, and height.
Definition ofCairoRenderer.cpp:1333
ofFillFlag getFillMode()
Get this renderer's current fill flag.
Definition ofCairoRenderer.cpp:650
void clear()
Clear this renderer's current color and bit depths.
Definition ofCairoRenderer.cpp:1162
void matrixMode(ofMatrixMode mode)
Sets this renderer's current matrix mode.
Definition ofCairoRenderer.cpp:812
void drawLine(float x1, float y1, float z1, float x2, float y2, float z2) const
Draw a line between two 3D points.
Definition ofCairoRenderer.cpp:1256
ofPixels & getImageSurfacePixels()
Definition ofCairoRenderer.cpp:1376
void setBackgroundAuto(bool bManual)
Enable/disable automatic redrawing of the background each frame.
Definition ofCairoRenderer.cpp:1214
~ofCairoRenderer()
Definition ofCairoRenderer.cpp:36
void drawString(const ofTrueTypeFont &font, std::string text, float x, float y) const
Draw text with this renderer using an ofTrueType font.
void drawTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) const
Draw a triangle using three 3D points.
Definition ofCairoRenderer.cpp:1291
void multMatrix(const glm::mat4 &m)
Multiply this renderer's current matrix by m.
Definition ofCairoRenderer.cpp:850
void pushStyle()
Push this renderer's current style into its internal style stack.
Definition ofCairoRenderer.cpp:1196
void setupScreenOrtho(float width=-1, float height=-1, float nearDist=-1, float farDist=1)
Setup the renderer to use an orthographic matrix.
Definition ofCairoRenderer.cpp:1013
void setFillMode(ofFillFlag fill)
set this renderer's fill flag.
Definition ofCairoRenderer.cpp:638
ofRectangle getNativeViewport() const
Get this renderer's current native viewport.
Definition ofCairoRenderer.cpp:1076
void setPolyMode(ofPolyWindingMode mode)
Set this renderer's poly winding mode.
Definition ofCairoRenderer.cpp:1133
void setCurveResolution(int resolution)
Set the resolution used when drawing curves with this renderer.
Definition ofCairoRenderer.cpp:195
void setBackgroundColor(const ofColor &c)
Set this renderer's background color.
Definition ofCairoRenderer.cpp:1224
void loadViewMatrix(const glm::mat4 &m)
Load m into this renderer's matrix stack as a view matrix.
Definition ofCairoRenderer.cpp:1101
void rotateYRad(float radians)
Rotate this renderer's current matrix by degrees about the y axis.
Definition ofCairoRenderer.cpp:886
void popStyle()
Pop this renderer's current style from its internal style stack.
Definition ofCairoRenderer.cpp:1206
void startRender()
Starts using this renderer as the rendering surface.
Definition ofCairoRenderer.cpp:139
int getViewportWidth() const
Get the renderer's current viewport width.
Definition ofCairoRenderer.cpp:1081
void draw(const std::vector< glm::vec3 > &vertexData, ofPrimitiveMode drawMode) const
void setupScreenPerspective(float width=-1, float height=-1, float fov=60, float nearDist=0, float farDist=0)
Setup the renderer to use a perspective matrix.
Definition ofCairoRenderer.cpp:950
void rotateZRad(float radians)
Rotate this renderer's current matrix by degrees about the z axis.
Definition ofCairoRenderer.cpp:891
void setupMemoryOnly(Type _type, bool multiPage=true, bool b3D=false, ofRectangle viewport=ofRectangle(0, 0, 0, 0))
Definition ofCairoRenderer.cpp:112
void enableAntiAliasing()
Enable this renderer to use anti-aliasing if it is supported.
Definition ofCairoRenderer.cpp:1323
int getViewportHeight() const
Get the renderer's current viewport width.
Definition ofCairoRenderer.cpp:1086
void close()
Definition ofCairoRenderer.cpp:122
void disableAntiAliasing()
Disable this renderer from using anti-aliasing.
Definition ofCairoRenderer.cpp:1328
void setBitmapTextMode(ofDrawBitmapMode mode)
Set this renderer's bitmap text mode.
Definition ofCairoRenderer.cpp:1188
void finishRender()
Stop using this renderer as the rendering surface.
Definition ofCairoRenderer.cpp:154
void multViewMatrix(const glm::mat4 &m)
Multiply this renderer's view matrix by m.
Definition ofCairoRenderer.cpp:1106
void setOrientation(ofOrientation orientation, bool vFlip)
set this renderer's orientation.
Definition ofCairoRenderer.cpp:1091
static const std::string TYPE
Definition ofCairoRenderer.h:17
void popView()
Pop the current viewport from the renderer's view stack.
Definition ofCairoRenderer.cpp:914
ofHandednessType getCoordHandedness() const
Get the coordinate handidness of this renderer.
Definition ofCairoRenderer.cpp:1144
void setCoordHandedness(ofHandednessType handedness)
Set the coordinate handidness of this renderer.
Definition ofCairoRenderer.cpp:1139
const of3dGraphics & get3dGraphics() const
Get a const reference of this renderer's 3D graphics object.
Definition ofCairoRenderer.cpp:1390
void loadMatrix(const glm::mat4 &m)
Load a matrix as this renderer's current matrix.
Definition ofCairoRenderer.cpp:834
void setLineWidth(float lineWidth)
Set the line width this renderer should use when drawing lines.
Definition ofCairoRenderer.cpp:659
Type
Definition ofCairoRenderer.h:20
@ SVG
Definition ofCairoRenderer.h:22
@ PDF
Definition ofCairoRenderer.h:21
@ IMAGE
Definition ofCairoRenderer.h:23
@ FROM_FILE_EXTENSION
Definition ofCairoRenderer.h:24
cairo_surface_t * getCairoSurface()
Definition ofCairoRenderer.cpp:1372
bool getBackgroundAuto()
Get the current auto redraw background setting for this renderer.
Definition ofCairoRenderer.cpp:1219
virtual void unbind(const ofCamera &camera)
Unbind the camera from this renderer.
Definition ofCairoRenderer.h:164
void setColor(int r, int g, int b)
Set the global color this renderer will use when drawing.
Definition ofCairoRenderer.cpp:714
void drawCircle(float x, float y, float z, float radius) const
Draw a circle using a 3D point and a radius.
Definition ofCairoRenderer.cpp:1309
glm::mat4 getCurrentViewMatrix() const
Get this renderer's current view matrix.
Definition ofCairoRenderer.cpp:1111
void drawRectangle(float x, float y, float z, float w, float h) const
Draw a rectangle using a 3D point and a width and height.
Definition ofCairoRenderer.cpp:1265
ofRectangle getCurrentViewport() const
Get this renderer's current viewport.
Definition ofCairoRenderer.cpp:1071
cairo_t * getCairoContext()
Definition ofCairoRenderer.cpp:1368
void translate(float x, float y, float z=0)
Translate this renderer's current matrix by x, y, and z.
Definition ofCairoRenderer.cpp:778
void setCircleResolution(int)
Set the resolution to use when drawing ellipses with this renderer.
Definition ofCairoRenderer.cpp:1129
void setDepthTest(bool depthTest)
Enable/disable depth testing with this renderer.
Definition ofCairoRenderer.cpp:668
void pushView()
Push the current viewport into the renderer's viewport stack.
Definition ofCairoRenderer.cpp:909
ofCairoRenderer()
Definition ofCairoRenderer.cpp:21
void setBlendMode(ofBlendMode blendMode)
Set this renderer's current blend mode.
Definition ofCairoRenderer.cpp:673
glm::mat4 getCurrentNormalMatrix() const
Get this renderer's current normal matrix.
Definition ofCairoRenderer.cpp:1117
void clearAlpha()
Restore the alpha color to its full opacity value.
Definition ofCairoRenderer.cpp:1184
void setup(const of::filesystem::path &filename, Type type=ofCairoRenderer::FROM_FILE_EXTENSION, bool multiPage=true, bool b3D=false, ofRectangle outputsize=ofRectangle(0, 0, 0, 0))
Definition ofCairoRenderer.cpp:40
ofRectMode getRectMode()
Get this renderer's current rect mode.
Definition ofCairoRenderer.cpp:633
void loadIdentityMatrix(void)
Load this renderer's identity matrix.
Definition ofCairoRenderer.cpp:817
ofColor getBackgroundColor()
Get this renderer's current background color.
Definition ofCairoRenderer.cpp:1229
glm::mat4 getCurrentOrientationMatrix() const
Get this renderer's current orientation matrix.
Definition ofCairoRenderer.cpp:1123
const std::string & getType()
Get the string representation of the renderer type.
Definition ofCairoRenderer.h:18
void pushMatrix()
Pushes this renderer's matrix stack down by one.
Definition ofCairoRenderer.cpp:756
glm::mat4 getCurrentMatrix(ofMatrixMode matrixMode_) const
Get this renderer's current matrix for particular a matrix mode.
Definition ofCairoRenderer.cpp:750
bool isVFlipped() const
Returns true if the renderer's current viewport is vertically flipped.
Definition ofCairoRenderer.cpp:1096
void viewport(ofRectangle viewport)
Set this renderer's viewport using a rectangle.
Definition ofCairoRenderer.cpp:923
void draw(const ofPath &shape) const
Draw a path with this renderer.
Definition ofCairoRenderer.cpp:200
void background(const ofColor &c)
Immediately paint a background color to the screen.
Definition ofCairoRenderer.cpp:1234
void setupScreen()
setup the default screen settings for this renderer.
Definition ofCairoRenderer.cpp:901
A basic camera object for interacting with objects in 3D space.
Definition ofCamera.h:13
A generic 3d object in space with transformation (position, rotation, scale).
Definition ofNode.h:14
ofPath is a way to create a path or multiple paths consisting of points. It allows you to combine mul...
Definition ofPath.h:38
A class representing a 2D rectangle.
Definition ofRectangle.h:87
Contains general information about the style of ofGraphics elements such as color,...
Definition ofGraphicsBaseTypes.h:51
Definition ofTrueTypeFont.h:164
unsigned int height
Definition ofAppEGLWindow.cpp:125
unsigned int width
Definition ofAppEGLWindow.cpp:124
ofPrimitiveMode
Definition ofGraphicsConstants.h:20
ofDrawBitmapMode
Sets the bitmap drawing mode for text.
Definition ofGraphicsConstants.h:125
ofMatrixMode
represents the available matrix types used internally in ofMatrixStack.
Definition ofGraphicsConstants.h:119
ofHandednessType
represents the available matrix coordinate system handednesses.
Definition ofGraphicsConstants.h:116
ofRectMode
Used to represent the available rectangle drawing modes.
Definition ofGraphicsConstants.h:139
ofBlendMode
Used to represent the available blending modes for drawing.
Definition ofGraphicsConstants.h:57
ofPolyRenderMode
Definition ofGraphicsConstants.h:13
ofPolyWindingMode
represents the available polygon winding modes.
Definition ofGraphicsConstants.h:97
ofFillFlag
Used to represent the available fill modes.
Definition ofGraphicsConstants.h:41
#define a
#define c
#define b
ofOrientation
Used to represent the available screen orientations.
Definition ofWindowSettings.h:25
Definition ofPath.h:366