ofGraphics
- ofBackground(...)
- ofBgColorPtr()
- ofSetBackgroundAuto(...)
- ofbClearBg()
- ofSetCircleResolution(...)
- ofSetRectMode(...)
- ofGetRectMode()
- ofRect(...)
- ofTriangle(...)
- ofCircle(...)
- ofEllipse(...)
- ofLine(...)
- ofCurve(...)
- ofBezier(...)
- ofSetPolyMode(...)
- ofBeginShape()
- ofVertex(...)
- ofCurveVertex(...)
- ofBezierVertex(...)
- ofNextContour(...)
- ofEndShape(...)
- ofNoFill()
- ofFill()
- ofSetColor(...)
- ofEnableAlphaBlending()
- ofDisableAlphaBlending()
- ofEnableSmoothing()
- ofDisableSmoothing()
- ofDrawBitmapString(...)
- ofRotate(...)
- ofRotateX(...)
- ofRotateY(...)
- ofRotateZ(...)
- ofPushStyle()
- ofPopStyle()
- ofSetStyle(...)
- ofGetStyle()
- ofSetLineWidth(...)
- ofPushMatrix()
- ofPopMatrix()
- ofTranslate(...)
- ofScale(...)
- ofSetCurrentRenderer(...)
- ofGetCurrentRenderer()
- ofGetGLRenderer()
- ofBeginSaveScreenAsPDF(...)
- ofEndSaveScreenAsPDF()
- ofPushView()
- ofPopView()
- ofViewport(...)
- ofSetupScreenPerspective(...)
- ofSetupScreenOrtho(...)
- ofGetCurrentViewport()
- ofGetViewportWidth()
- ofGetViewportHeight()
- ofOrientationToDegrees(...)
- ofSetCoordHandedness(...)
- ofGetCoordHandedness()
- ofTranslate(...)
- ofRotate(...)
- ofSetupScreen()
- ofSetCurveResolution(...)
- ofSetSphereResolution(...)
- ofGetFill()
- ofSetColor(...)
- ofSetHexColor(...)
- ofEnableBlendMode(...)
- ofDisableBlendMode()
- ofEnablePointSprites()
- ofDisablePointSprites()
- ofSetPolyMode(...)
- ofSetRectMode(...)
- ofBackground(...)
- ofBackgroundHex(...)
- ofSetBackgroundColor(...)
- ofSetBackgroundColorHex(...)
- ofClear(...)
- ofClearAlpha()
- ofTriangle(...)
- ofCircle(...)
- ofEllipse(...)
- ofLine(...)
- ofRect(...)
- ofCurve(...)
- ofBezier(...)
- ofVertex(...)
- ofVertexes(...)
- ofCurveVertex(...)
- ofCurveVertexes(...)
- ofBezierVertex(...)
- ofSphere(...)
- ofBox(...)
- ofSetDrawBitmapMode(...)
ofGraphics functions
ofBackground(...)
void ofBackground(int r, int g, int b)
Sets the background color. It takes as input r,g,b (0-255). The background is cleared automatically, just before the draw() command, so if the background color is not changing, you could call this inside of setup() (once, at the start of the application). If the background color is changing, you can call this inside of update().
ofBgColorPtr()
float * ofBgColorPtr()
Gets the background color. eg:
float * bgColor = ofBgColorPtr();
//lets get the individual values!
float r = bgColor[0];
float g = bgColor[1];
float b = bgColor[2];
float a = bgColor[3];
ofSetBackgroundAuto(...)
void ofSetBackgroundAuto(bool bAuto)
Sets the background clearing function to be auto (default) or not. If non-auto, then background clearing will not occur per frame (at the start of draw) but rather, whenever ofBackground is called.
ofSetCircleResolution(...)
void ofSetCircleResolution(int res)
Sets the resolution for the ofCircle command. By default, the circle is 22 points, but if you need to draw larger circles, you can adjust the resolution using this command. all circles are cached in opengl using a display list for optimization purposes.
ofSetRectMode(...)
void ofSetRectMode(int mode)
Sets the mode for drawing rectangles, if they are corner aligned, or drawn so that the x,y position is the center of the rectangle. possible options are OF_RECTMODE_CENTER and OF_RECTMODE_CORNER.
ofGetRectMode()
ofRectMode ofGetRectMode()
Tells you if rect drawing mode is set to drawn from the center or drawn from the top left corner.
ofRect(...)
void ofRect(float x1, float y1, float w, float h)
Draws an rectangle from point x,y with a given width and height.
ofTriangle(...)
void ofTriangle(float x1, float y1, float x2, float y2, float x3, float y3)
Draws a triangle, with the three points: (x1,y1),(x2, y2),(x3, y3).
ofCircle(...)
void ofCircle(float x, float y, float radius)
Draws a circle, centered at x,y, with a given radius.
ofEllipse(...)
void ofEllipse(float x, float y, float w, float h)
Draws an ellipse from point (x,y) with a given width (w) and height (h).
ofLine(...)
void ofLine(float x1, float y1, float x2, float y2)
Draws a line between two points: (x1,y1),(x2,y2).
ofCurve(...)
void ofCurve(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3)
Draws a curve from point (x1, y1) to point (x2, y2). The curve is shaped by the two control points (x0,y0) and (x3,y3).
ofBezier(...)
void ofBezier(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3)
Draws a bezier curve from point (x0, y0) to point (x3, y3). The curve is shaped by the two control points (x1,y1) and (x2,y2) in a way where they are the respective tangents for the line at either ends.
ofSetPolyMode(...)
void ofSetPolyMode(int mode)
Sets the drawing behavior for ovelapping parts of the same polygon. Possible modes are: OF_POLY_WINDING_ODD - OF_POLY_WINDING_NONZERO - OF_POLY_WINDING_POSITIVE - OF_POLY_WINDING_NEGATIVE - OF_POLY_WINDING_ABS_GEQ_TWO -
ofBeginShape()
void ofBeginShape()
Call this to start drawing a new shape. Needs to be followed by a list of vertex points and lastly a call to ofEndShape().
//draws a star
ofSetPolyMode(OF_POLY_WINDING_NONZERO);
ofBeginShape();
ofVertex(400,135);
ofVertex(215,135);
ofVertex(365,25);
ofVertex(305,200);
ofVertex(250,25);
ofEndShape();
ofVertex(...)
void ofVertex(float x, float y)
Specifies a single point of a shape. To be called between ofBeginShape() and ofEndShape().
ofCurveVertex(...)
void ofCurveVertex(float x, float y)
Specifies a single point of a shape. The difference from ofVertex is that the line describing the edge of the shape between two points will be a curve as opposed to a straight line. The curve is automatically generated using the catmull rom forumla. To be called between ofBeginShape() and ofEndShape().
ofBezierVertex(...)
void ofBezierVertex(float x1, float y1, float x2, float y2, float x3, float y3)
Describes a bezier curve through three points of a shape. To be called between ofBeginShape() and ofEndShape().
ofNextContour(...)
void ofNextContour(bool bClose)
Allows you to draw multiple contours within one shape. Call this between ofBeginShape() and ofEndShape() to create a new contour for your shape. If you set the optional argument 'bClose' to true then the previous contour will be automatically closed. 'bClose' is set to false by default.
ofEndShape(...)
void ofEndShape(bool bClose)
This tells the program that your shape is finished and that it should now draw it to the screen. If you set the optional 'bClose' argument to true it will automatically close your shape for you.'bClose' is set to false by default. This function must be called otherwise you will not see your shape.
ofSetColor(...)
void ofSetColor(int r, int g, int b)
Sets the draw color with r,g,b, 0-255. For example, red (0xff0000) would be: ofSetColor(255,0,0).
ofSetColor(...)
void ofSetColor(int r, int g, int b, int a)
sets the draw color with r,g,b,a 0-255. For alpha (transparency), you must first enable transparent blending (turned off by default for performance reasons), and draw in the proper z-order (objects in the back drawn first). For example, to draw a transparent red rectangle:
ofEnableAlphaBlending(); // turn on alpha blending
ofSetColor(255,0,0,127); // red, 50% transparent
ofRect(20,20,100,100);
ofDisableAlphaBlending(); // turn it back off, if you don't need it
ofSetColor(...)
void ofSetColor(int hexColor)
Sets the draw color with r,g,b, passed in as a hex. Hex is a conventient way to write colors. Some examples:
ofSetColor(0xffffff); // white (255,255,255)
ofSetColor(0x000000); // black (0,0,0);
ofSetColor(0x00ff00); // green (0,255,0);
ofEnableAlphaBlending()
void ofEnableAlphaBlending()
Turns on alpha blending, which is off by default for performance purposes. It simply wraps opengl commands that enable blending, and turn on a common blend mode.
ofEnableSmoothing()
void ofEnableSmoothing()
Turns on smoothing. Currently, this only works for lines. You can draw a filled object, and then draw the outline with smoothing enabled to get smoothing effects on filled shapes.
ofDisableSmoothing()
void ofDisableSmoothing()
Turns off smoothing. Currently, this only works for lines. You can draw a filled object, and then draw the outline with smoothing enabled to get smoothing effects on filled shapes.
ofDrawBitmapString(...)
void ofDrawBitmapString(string str, float x, float y)
Draws a bitmapped string, on screen, at point (x,y). For example, you can write some text on screen like this:
ofDrawBitmapString("hi!!", 100,100);
Your strings can even be multiline:
ofDrawBitmapString("a test
of multiline
text", 100,100);
you can also using dynamically generated strings. For example, to print the frame rate:
string fpsStr = "frame rate: "+ofToString(ofGetFrameRate(), 2);
ofDrawBitmapString(fpsStr, 100,100);
Please note, ofDrawBitmapString wraps a glut function that uses glDrawPixels. On some graphics cards, you may discover that glDrawPixels is slow (or even, very slow). If so, you might want to invsetigate using ofTrueTypeFont with a small typeface, non-anti-aliased, as a suitable alternative.
ofRotate(...)
void ofRotate(float degrees, float vecX, float vecY, float vecZ)
ofRotate produces a rotation of angle "degrees" around the vector (vecX,vecY,vecZ). "degrees"specifies the angle of rotation, in degrees. vecX, vecY, vecZ specify the x, y, and z coordinates of a vector, respectively. All graphics drawn after ofRotate is called are rotated. Use ofPushMatrix and ofPopMatrix to save and restore the unrotated coordinate system.
ofRotateX(...)
void ofRotateX(float degrees)
ofRotateX produces a rotation of angle "degrees" around the X-axis of our coordinate system represented by the vector (1,0,0)."degrees"specifies the angle of rotation, in degrees.
ofRotateY(...)
void ofRotateY(float degrees)
ofRotateY produces a rotation of angle "degrees" around the Y-axis of our coordinate system represented by the vector (0,1,0). "degrees"specifies the angle of rotation, in degrees.
ofRotateZ(...)
void ofRotateZ(float degrees)
ofRotateZ produces a rotation of angle "degrees" around the Z-axis of our coordinate system represented by the vector (0,0,1). "degrees"specifies the angle of rotation, in degrees.
ofPushStyle()
void ofPushStyle()
ofPushStyle saves the current style settings for the ofGraphics after its call. Usage of ofPushStyle and ofPopStyle allow users to have more control of certain graphics elements. All the style that applies to certain elements is controled using ofStyle class. See ofStyle type. In the following example the properties of being red and filled only applies to the ellipse:
void testApp::draw(){
ofCircle(10,10,5);
ofPushStyle();
ofFill();
ofsetColor(255,0,0);
ofEllipse(30,10,40,40);
ofPopStyle();
}
ofPopStyle()
void ofPopStyle()
ofPopStyle() restores the prior style settings. It needs to be called after ofPushStyle. See ofPushStyle for more info.
ofSetStyle(...)
void ofSetStyle(ofStyle style)
We use ofSetStyle to set the current style of the ofGraphics. Parameter style contains information of the graphics style such as ofColor, ofFill, polyMode and others. See ofStyle for more details.
ofSetLineWidth(...)
void ofSetLineWidth(float lineWidth)
ofSetLineWidth sets the width of the ofLines called after.
ofPushMatrix()
void ofPushMatrix()
ofPushMatrix saves the current coordinate system allowing users to develop specific movements in some graphic objects. ofPopMatrix needs to be called after. In the following example we only rotate the square.
void testApp::draw(){
ofCircle(10, 10, 5);
ofPushMatrix();
ofRotateX(90);
ofRect(10,10,40,40);
ofPopMatrix()
}
ofPopMatrix()
void ofPopMatrix()
ofPopMatrix() restores the prior coordinate system. See ofPushMatrix for more info.
ofTranslate(...)
void ofTranslate(float x, float y, float z)
ofTranslate produces a translation by (x,y,z) vector of our coordinate system. The call of ofTranslate modifies graphics positions. Use ofPushMatrix and ofPopMatrix to save and restore the untranslated coordinate system.
ofScale(...)
void ofScale(float xAmnt, float yAmnt, float zAmnt)
ofScale produces a nonuniform scaling along the x, y, and z axes. The three parameters xAmnt, yAmnt and zAmnt indicate the desired scale factor along each of the three axes. e.g:
void testApp::draw(){
ofScale(0.5,1,1);
ofRect(10,10,40,40);
}
Rectangle width will be now 20px!
ofBeginSaveScreenAsPDF(...)
void ofBeginSaveScreenAsPDF(string filename, bool bMultipage=false, bool b3D=false, ofRectangle viewport=ofRectangle(0, 0, 0, 0))
ofViewport(...)
void ofViewport(float x=0, float y=0, float width=0, float height=0, bool invertY=true)
ofSetupScreenPerspective(...)
void ofSetupScreenPerspective(float width=0, float height=0, ofOrientation orientation=OF_ORIENTATION_UNKNOWN, bool vFlip=true, float fov=60, float nearDist=0, float farDist=0)
ofSetupScreenOrtho(...)
void ofSetupScreenOrtho(float width=0, float height=0, ofOrientation orientation=OF_ORIENTATION_UNKNOWN, bool vFlip=true, float nearDist=-1, float farDist=1)
ofTriangle(...)
void ofTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3)
ofCurve(...)
void ofCurve(float x0, float y0, float z0, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3)
ofBezier(...)
void ofBezier(float x0, float y0, float z0, float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3)
ofBezierVertex(...)
void ofBezierVertex(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3)
