Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
wiki2:cpp:libraries:openframeworks [2015/10/08 16:04] alfred |
wiki2:cpp:libraries:openframeworks [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 9: | Línea 9: | ||
| ==== Notes ==== | ==== Notes ==== | ||
| * **To add an addon after having created the project** you just need to include its name in the ''addons.make'' file. | * **To add an addon after having created the project** you just need to include its name in the ''addons.make'' file. | ||
| + | * To compile with **C++11** you need to go to ''libs/openFrameworksCompiled/project/makefileCommon'' path and edit the main makefile which is ''compile.project.mk''. You need to search for the rule that does the compilation and add: ''-std=c++0x''. | ||
| + | <code cpp> | ||
| + | $(OF_PROJECT_OBJ_OUPUT_PATH)%.o: $(PROJECT_ROOT)/%.cpp | ||
| + | @echo "Compiling" $< | ||
| + | @mkdir -p $(@D) | ||
| + | $(CXX) -c $(OPTIMIZATION_CFLAGS) $(CFLAGS) $(CXXFLAGS) -std=c++0x -MMD -MP -MF $(OF_PROJECT_OBJ_OUPUT_PATH)$*.d -MT $(OF_PROJECT_OBJ_OUPUT_PATH)$*.o -o $@ -c $< | ||
| + | </code> | ||
| + | * Muy probablemente quieras usar otras libs, las tendrías que añadir también en el makefile: | ||
| + | <code cpp> | ||
| + | $(TARGET): $(OF_PROJECT_OBJS) $(OF_PROJECT_ADDONS_OBJS) $(OF_PROJECT_LIBS) $(TARGET_LIBS) | ||
| + | @echo 'Linking $(TARGET) for $(ABI_LIB_SUBPATH)' | ||
| + | @mkdir -p $(@D) | ||
| + | $(CXX) -o $@ $(OF_PROJECT_OBJS) $(OF_PROJECT_ADDONS_OBJS) $(TARGET_LIBS) $(OF_PROJECT_LIBS) $(LDFLAGS) $(OF_CORE_LIBS) -lboost_system -lboost_timer -lboost_thread | ||
| + | </code> | ||
| + | ===== Useful data ===== | ||
| + | ==== Obtain information ==== | ||
| + | |||
| + | * Ventana | ||
| + | * ofGetWidth(), ofGetHeight() | ||
| + | * Programa | ||
| + | * ofGetElapsedTimef(), ofGetElapsedTimeMicros(), ofGetElapsedTimeMillis() | ||
| + | |||
| + | ==== Useful constants ==== | ||
| + | * TWO_PI | ||
| + | * DEG_TO_RAD (any number we multiply by DEG_TO_RAD will be converted to radians) | ||
| ===== Graphics ===== | ===== Graphics ===== | ||
| * [[wiki2:cpp:libraries:openframeworks:creating_graphics|Creating Graphics]] | * [[wiki2:cpp:libraries:openframeworks:creating_graphics|Creating Graphics]] | ||
| - | |||
| ===== Addons ===== | ===== Addons ===== | ||
| Línea 21: | Línea 45: | ||
| Crear un listener de UDP: | Crear un listener de UDP: | ||
| <code cpp> | <code cpp> | ||
| + | #include "ofxNetwork.h" | ||
| + | |||
| ofxUDPManager udpConnection; | ofxUDPManager udpConnection; | ||
| Línea 35: | Línea 61: | ||
| * https://github.com/jefftimesten/ofxJSON | * https://github.com/jefftimesten/ofxJSON | ||
| <code cpp> | <code cpp> | ||
| + | #include "ofxJSON.h" | ||
| + | ... | ||
| ofxJSONElement result; | ofxJSONElement result; | ||
| std::string url = "http://127.0.0.1:5000/sketch/1"; | std::string url = "http://127.0.0.1:5000/sketch/1"; | ||
| Línea 66: | Línea 94: | ||
| ===== Snippets ===== | ===== Snippets ===== | ||
| - | * Create image from code (color picker) | + | * [[wiki2:cpp:libraries:openframeworks:snippets|OpenFrameworks Snippets]] |
| - | + | ||
| - | <code cpp> | + | |
| - | 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(); | + | |
| - | </code> | + | |
| - | + | ||
| - | * Get color from an image: | + | |
| - | + | ||
| - | <code cpp> | + | |
| - | 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); | + | |
| - | } | + | |
| - | </code> | + | |