Herramientas de usuario

Herramientas del sitio


wiki2:cpp:libraries:openframeworks

¡Esta es una revisión vieja del documento!


OpenFrameworks

Installation and use

Installation

Use in Eclipse

  • Follow the tutorial until have OpenFrameworks and Addons in your projects.

Import the generated project as “Existing code as makefile project”. You only need to add OpenFrameworks and Addons projects as references in your new project (do not forget to select “Linux GCC”).

Notes

  • To add an addon after having created the project you just need to include its name in the addons.make file.

Graphics

Addons

ofxNetwork

UDP

Crear un listener de UDP:

ofxUDPManager udpConnection;
 
udpConnection.Create();
udpConnection.Bind(5001);
udpConnection.SetNonBlocking(true);
 
char udpMessage[10000];
udpConnection.Receive(udpMessage,10000);
std::string message=udpMessage;

ofxJSON

ofxJSONElement result;
std::string url = "http://127.0.0.1:5000/sketch/1";
bool parsingSuccessful = result.open(url);
 
if (parsingSuccessful)
{
	//ofLogNotice("ofApp::setup") << "Ok!" << endl << result.getRawString() << endl;
	Json::Int64 value = result["paths"][0]["start_t"].asInt64();
	ofLogNotice("ofApp::setup") << value << endl;
	Json::ArrayIndex npoints = result["paths"][0]["points"].size();
	ofLogNotice("ofApp::setup") << npoints << endl;
 
	for (unsinged int i=0; i<result["paths"][0]["points"].size(); i++)
		ofxJSONElement point = result["paths"][0]["points"][i];
 
	ofxJSONElement result2;
	ofLogNotice("ofApp::setup") << result2.parse("{\"hola\": \"adios\"}");
	ofLogNotice("ofApp::setup") << result2["hola"].asString();
}
else
{
	ofLogNotice("ofApp::setup")  << "Failed to parse JSON" << endl;
}

Addons Repository

Snippets

  • Create image from code (color picker)
float w = ofGetWidth();
float h = ofGetHeight();
float cx = w/2;
float cy = h/2;
 
img.allocate(w,h,OF_IMAGE_COLOR);
 
for (float y=0; y<h; y++) {
    for (float x=0; x<w; x++) {
 
        float angle = atan2(y-cy,x-cy)+PI;
        float dist = ofDist(x,y,cx,cy);
        float hue = angle/TWO_PI*255;
        float sat = ofMap(dist,0,w/4,0,255,true);
        float bri = ofMap(dist,w/4,w/2,255,0,true);
 
        img.setColor(x,y,ofColor::fromHsb(hue,sat,bri));
    }
}
 
img.reloadTexture();  
  • Get color from an image:
ofColor ofxGetPixelColor(ofBaseHasPixels &img, int x, int y, int w, int h, int bpp=3) {
    ofColor c;
    int i = y*w*bpp + x*bpp;
    c.r = img.getPixels()[i+0];
    c.g = img.getPixels()[i+1];
    c.b = img.getPixels()[i+2];
    if (bpp==4) c.a = img.getPixels()[i+3];
    return c;
}
 
ofColor ofxGetPixelColor(int x, int y) {
    ofImage img;
    img.grabScreen(x,y,1,1);
    return ofxGetPixelColor(img,0,0,1,1);
}
wiki2/cpp/libraries/openframeworks.1444320261.txt.gz · Última modificación: 2020/05/09 09:25 (editor externo)