Herramientas de usuario

Herramientas del sitio


wiki2:cpp:libraries:openframeworks:creating_graphics

¡Esta es una revisión vieja del documento!


Creating graphics in OpenFrameworks

Traditional way and primitives

This is the traditional way to draw:

ofFill();
ofSetColor(255,0,0);
ofBeginShape();
ofVertex(20,20);
ofVertex(40,20);
ofVertex(40,40);
ofVertex(20,40);
ofEndShape(true);

However we have several functions to draw primitives like…

  • ofRect

How does it work? and how it should work?

The tradictional way is deprecated because internally, the openFrameworks version is tessellating the shape (converting it into triangles), then storing all the triangles in an ofMesh, and then drawing that ofMesh. It doesn't make much sense to send them to the graphics card every frame.

If you are using openGL 3+ instead of an ofMesh that will be drawn through a VBO using an ofVboMesh, since that's the only possible way of drawing in newer openGL. The paradigm that newer versions of openGL use is something like this: create the shape once, upload it to the graphics card, and then draw it every frame without having to reupload again, this is usually don through some kind of buffer in the graphics card, usually vbo's. In openFrameworks, the ofPolyline and ofPath classes do this in 2D and ofVboMesh for 3D.

Poly lines, paths and meshes

ofPolyLine

ofPolyline, allows us to represent the contour of a shape.

ofPolyline polyline;
 
void ofApp::setup(){
    polyline.lineTo(20,20);
    polyline.lineTo(40,20);
    polyline.lineTo(40,40);
    polyline.lineTo(20,40);
    polyline.close();
}
 
void ofApp::draw(){
    polyline.draw();
}

ofPolyline is really a class meant to be used to do operations over polylines, like simplifications, smoothing… Also ofPolyline can only draw outlines, not filled shapes.

wiki2/cpp/libraries/openframeworks/creating_graphics.1444322572.txt.gz · Última modificación: 2020/05/09 09:25 (editor externo)