//======================================================================== int main( int argc, char *argv[] ){ #ifdef TARGET_LINUX if(argc==1){ ofAppGlutWindow window; ofSetupOpenGL(&window, 1024,768, OF_WINDOW); ofRunApp( new testApp()); }else{ ofAppNoWindow window; ofSetupOpenGL(&window, 1024,768, OF_WINDOW); testApp * app = new testApp; app->buildAllExamples = false; for(int i=1;i<argc;i++){ string arg = argv[i]; if(arg.find("--")==0){ arg = arg.substr(2); if(arg=="linux"){ app->targetsToMake.push_back( OF_TARGET_LINUX ); }else if(arg=="linux64"){ app->targetsToMake.push_back( OF_TARGET_LINUX64 ); }else if(arg=="win_cb"){ app->targetsToMake.push_back( OF_TARGET_WINGCC ); }else if(arg=="vs2010"){ app->targetsToMake.push_back( OF_TARGET_WINVS ); }else if(arg=="osx"){ app->targetsToMake.push_back( OF_TARGET_OSX ); }else if(arg=="ios"){ app->targetsToMake.push_back( OF_TARGET_IPHONE ); }else if(arg=="android"){ ofLogError() << "platform not supported yet" << endl; std::exit(1); }else if(arg=="allplatforms"){ app->targetsToMake.push_back( OF_TARGET_LINUX ); app->targetsToMake.push_back( OF_TARGET_LINUX64 ); app->targetsToMake.push_back( OF_TARGET_WINGCC ); app->targetsToMake.push_back( OF_TARGET_WINVS ); app->targetsToMake.push_back( OF_TARGET_OSX ); app->targetsToMake.push_back( OF_TARGET_IPHONE ); }else if(arg=="allexamples"){ app->buildAllExamples = true; }else if(arg=="help"){ cout << "OF Project Generator Usage:" << endl; cout << "projectGenerator [options] [pathToExample]" << endl; cout << "Options:" << endl; cout << "--osx: generate osx project files" << endl; cout << "--win_cb: generate windows codeblocks project files" << endl; cout << "--vs2010: generate windows vs2010 project files" << endl; cout << "--linux: generate linux project files" << endl; cout << "--linux64: generate linux 64bits project files" << endl; cout << "--ios: generate iOS project files" << endl; cout << "--allplatforms: generate all platforms project files" << endl; cout << "--allexamples: generate all examples project files" << endl; cout << endl; cout << "default: create project files for current platform for selected path" << endl; cout << "running over existing example updates project files for selected platforms" << endl; cout << "without parameters, shows gui" << endl; std::exit(0); } }else{ app->projectPath = ofFilePath::removeTrailingSlash(ofFilePath::getPathForDirectory(ofFilePath::getAbsolutePath(arg,false))); } } if(app->targetsToMake.empty()) app->targetsToMake.push_back( ofGetTargetPlatform() ); ofRunApp( app ); } #else ofAppGlutWindow window; ofSetupOpenGL(&window, 1024,768, OF_WINDOW); testApp app = new testApp; app->buildAllExamples = false; ofRunApp( app ); #endif }
//---------------------------------------------------------------- bool ofSerial::setup(string portName, int baud){ bInited = false; #if defined( TARGET_OSX ) || defined( TARGET_LINUX ) //lets account for the name being passed in instead of the device path if(portName.size() > 5 && portName.substr(0, 5) != "/dev/"){ portName = "/dev/" + portName; } ofLogNotice("ofSerial") << "opening " << portName << " @ " << baud << " bps"; fd = open(portName.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); if(fd == -1){ ofLogError("ofSerial") << "unable to open " << portName; return false; } struct termios options; tcgetattr(fd, &oldoptions); options = oldoptions; switch(baud){ case 300: cfsetispeed(&options, B300); cfsetospeed(&options, B300); break; case 1200: cfsetispeed(&options, B1200); cfsetospeed(&options, B1200); break; case 2400: cfsetispeed(&options, B2400); cfsetospeed(&options, B2400); break; case 4800: cfsetispeed(&options, B4800); cfsetospeed(&options, B4800); break; case 9600: cfsetispeed(&options, B9600); cfsetospeed(&options, B9600); break; case 14400: cfsetispeed(&options, B14400); cfsetospeed(&options, B14400); break; case 19200: cfsetispeed(&options, B19200); cfsetospeed(&options, B19200); break; case 28800: cfsetispeed(&options, B28800); cfsetospeed(&options, B28800); break; case 38400: cfsetispeed(&options, B38400); cfsetospeed(&options, B38400); break; case 57600: cfsetispeed(&options, B57600); cfsetospeed(&options, B57600); break; case 115200: cfsetispeed(&options, B115200); cfsetospeed(&options, B115200); break; case 230400: cfsetispeed(&options, B230400); cfsetospeed(&options, B230400); break; default: cfsetispeed(&options, B9600); cfsetospeed(&options, B9600); ofLogError("ofSerial") << "setup(): cannot set " << baud << " bps, setting to 9600"; break; } options.c_cflag |= (CLOCAL | CREAD); options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_iflag &= (tcflag_t) ~(INLCR | IGNCR | ICRNL | IGNBRK); options.c_oflag &= (tcflag_t) ~(OPOST); options.c_cflag |= CS8; tcsetattr(fd, TCSANOW, &options); bInited = true; ofLogNotice("ofSerial") << "opened " << portName << " sucessfully @ " << baud << " bps"; return true; #elif defined( TARGET_WIN32 ) char pn[sizeof(portName)]; int num; if(sscanf(portName.c_str(), "COM%d", &num) == 1){ // Microsoft KB115831 a.k.a if COM > COM9 you have to use a different // syntax sprintf(pn, "\\\\.\\COM%d", num); } else { strncpy(pn, (const char *)portName.c_str(), sizeof(portName)-1); } // open the serial port: // "COM4", etc... hComm = CreateFileA(pn, GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); if(hComm == INVALID_HANDLE_VALUE){ ofLogError("ofSerial") << "setup(): unable to open " << portName; return false; } // now try the settings: COMMCONFIG cfg; DWORD cfgSize; WCHAR buf[80]; cfgSize = sizeof(cfg); GetCommConfig(hComm, &cfg, &cfgSize); int bps = baud; swprintf(buf, L"baud=%d parity=N data=8 stop=1", bps); if(!BuildCommDCBW(buf, &cfg.dcb)){ ofLogError("ofSerial") << "setup(): unable to build comm dcb, (" << buf << ")"; } // Set baudrate and bits etc. // Note that BuildCommDCB() clears XON/XOFF and hardware control by default if(!SetCommState(hComm, &cfg.dcb)){ ofLogError("ofSerial") << "setup(): couldn't set comm state: " << cfg.dcb.BaudRate << " bps, xio " << cfg.dcb.fInX << "/" << cfg.dcb.fOutX; } //ofLogNotice("ofSerial") << "bps=" << cfg.dcb.BaudRate << ", xio=" << cfg.dcb.fInX << "/" << cfg.dcb.fOutX; // Set communication timeouts (NT) COMMTIMEOUTS tOut; GetCommTimeouts(hComm, &oldTimeout); tOut = oldTimeout; // Make timeout so that: // - return immediately with buffered characters tOut.ReadIntervalTimeout = MAXDWORD; tOut.ReadTotalTimeoutMultiplier = 0; tOut.ReadTotalTimeoutConstant = 0; SetCommTimeouts(hComm, &tOut); bInited = true; return true; #else ofLogError("ofSerial") << "not implemented in this platform"; return false; #endif }
//---------------------------------------------------------------- void ofSerial::buildDeviceList(){ deviceType = "serial"; devices.clear(); vector <string> prefixMatch; #ifdef TARGET_OSX prefixMatch.push_back("cu."); prefixMatch.push_back("tty."); #endif #ifdef TARGET_LINUX #ifdef TARGET_RASPBERRY_PI prefixMatch.push_back("ttyACM"); #endif prefixMatch.push_back("ttyS"); prefixMatch.push_back("ttyUSB"); prefixMatch.push_back("rfc"); #endif #if defined( TARGET_OSX ) || defined( TARGET_LINUX ) DIR *dir; dir = opendir("/dev"); string deviceName = ""; if(dir == nullptr){ ofLogError("ofSerial") << "buildDeviceList(): error listing devices in /dev"; } else { int deviceCount = 0; //for each device struct dirent *entry; while((entry = readdir(dir)) != nullptr){ deviceName = (char *)entry->d_name; //we go through the prefixes for(int k = 0; k < (int)prefixMatch.size(); k++){ //if the device name is longer than the prefix if(deviceName.size() > prefixMatch[k].size()){ //do they match ? if(deviceName.substr(0, prefixMatch[k].size()) == prefixMatch[k].c_str()){ devices.push_back(ofSerialDeviceInfo("/dev/"+deviceName, deviceName, deviceCount)); deviceCount++; break; } } } } closedir(dir); } #endif #ifdef TARGET_WIN32 enumerateWin32Ports(); ofLogNotice("ofSerial") << "found " << nPorts << " devices"; for(int i = 0; i < nPorts; i++){ //NOTE: we give the short port name for both as that is what the user should pass and the short name is more friendly devices.push_back(ofSerialDeviceInfo(string(portNamesShort[i]), string(portNamesShort[i]), i)); } #endif //here we sort the device to have the aruino ones first. partition(devices.begin(), devices.end(), isDeviceArduino); //we are reordering the device ids. too! for(int k = 0; k < (int)devices.size(); k++){ devices[k].deviceID = k; } bHaveEnumeratedDevices = true; }
bool ofGstVideoPlayer::allocate(){ if(bIsAllocated){ return true; } guint64 durationNanos = videoUtils.getDurationNanos(); nFrames = 0; if(GstPad* pad = gst_element_get_static_pad(videoUtils.getSink(), "sink")){ #if GST_VERSION_MAJOR==0 int width,height; if(gst_video_get_size(GST_PAD(pad), &width, &height)){ if(!videoUtils.allocate(width,height,internalPixelFormat)) return false; }else{ ofLogError("ofGstVideoPlayer") << "allocate(): couldn't query width and height"; return false; } const GValue *framerate = gst_video_frame_rate(pad); fps_n=0; fps_d=0; if(framerate && GST_VALUE_HOLDS_FRACTION (framerate)){ fps_n = gst_value_get_fraction_numerator (framerate); fps_d = gst_value_get_fraction_denominator (framerate); nFrames = (float)(durationNanos / (float)GST_SECOND) * (float)fps_n/(float)fps_d; ofLogVerbose("ofGstVideoPlayer") << "allocate(): framerate: " << fps_n << "/" << fps_d; }else{ ofLogWarning("ofGstVideoPlayer") << "allocate(): cannot get framerate, frame seek won't work"; } bIsAllocated = true; #else if(GstCaps *caps = gst_pad_get_current_caps (GST_PAD (pad))){ GstVideoInfo info; gst_video_info_init (&info); if (gst_video_info_from_caps (&info, caps)){ ofPixelFormat format = ofGstVideoUtils::getOFFormat(GST_VIDEO_INFO_FORMAT(&info)); if(format!=internalPixelFormat){ ofLogVerbose("ofGstVideoPlayer") << "allocating as " << info.width << "x" << info.height << " " << info.finfo->description << " " << info.finfo->name; internalPixelFormat = format; } if(!videoUtils.allocate(info.width,info.height,format)) return false; }else{ ofLogError("ofGstVideoPlayer") << "allocate(): couldn't query width and height"; return false; } fps_n = info.fps_n; fps_d = info.fps_d; nFrames = (float)(durationNanos / (float)GST_SECOND) * (float)fps_n/(float)fps_d; gst_caps_unref(caps); bIsAllocated = true; }else{ ofLogError("ofGstVideoPlayer") << "allocate(): cannot get pipeline caps"; bIsAllocated = false; } #endif gst_object_unref(GST_OBJECT(pad)); }else{ ofLogError("ofGstVideoPlayer") << "allocate(): cannot get sink pad"; bIsAllocated = false; } return bIsAllocated; }
//------------------------------------------- void ofxAssimpModelLoader::loadGLResources(){ ofLogVerbose("ofxAssimpModelLoader") << "loadGLResources(): starting"; // create new mesh helpers for each mesh, will populate their data later. modelMeshes.resize(scene->mNumMeshes,ofxAssimpMeshHelper()); // create OpenGL buffers and populate them based on each meshes pertinant info. for (unsigned int i = 0; i < scene->mNumMeshes; ++i){ ofLogVerbose("ofxAssimpModelLoader") << "loadGLResources(): loading mesh " << i; // current mesh we are introspecting aiMesh* mesh = scene->mMeshes[i]; // the current meshHelper we will be populating data into. ofxAssimpMeshHelper & meshHelper = modelMeshes[i]; //ofxAssimpMeshHelper meshHelper; //meshHelper.texture = NULL; // Handle material info aiMaterial* mtl = scene->mMaterials[mesh->mMaterialIndex]; aiColor4D dcolor, scolor, acolor, ecolor; if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_DIFFUSE, &dcolor)){ meshHelper.material.setDiffuseColor(aiColorToOfColor(dcolor)); } if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_SPECULAR, &scolor)){ meshHelper.material.setSpecularColor(aiColorToOfColor(scolor)); } if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_AMBIENT, &acolor)){ meshHelper.material.setAmbientColor(aiColorToOfColor(acolor)); } if(AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_EMISSIVE, &ecolor)){ meshHelper.material.setEmissiveColor(aiColorToOfColor(ecolor)); } float shininess; if(AI_SUCCESS == aiGetMaterialFloat(mtl, AI_MATKEY_SHININESS, &shininess)){ meshHelper.material.setShininess(shininess); } int blendMode; if(AI_SUCCESS == aiGetMaterialInteger(mtl, AI_MATKEY_BLEND_FUNC, &blendMode)){ if(blendMode==aiBlendMode_Default){ meshHelper.blendMode=OF_BLENDMODE_ALPHA; }else{ meshHelper.blendMode=OF_BLENDMODE_ADD; } } // Culling unsigned int max = 1; int two_sided; if((AI_SUCCESS == aiGetMaterialIntegerArray(mtl, AI_MATKEY_TWOSIDED, &two_sided, &max)) && two_sided) meshHelper.twoSided = true; else meshHelper.twoSided = false; // Load Textures int texIndex = 0; aiString texPath; // TODO: handle other aiTextureTypes if(AI_SUCCESS == mtl->GetTexture(aiTextureType_DIFFUSE, texIndex, &texPath)){ ofLogVerbose("ofxAssimpModelLoader") << "loadGLResource(): loading image from \"" << texPath.data << "\""; string modelFolder = file.getEnclosingDirectory(); string relTexPath = ofFilePath::getEnclosingDirectory(texPath.data,false); string texFile = ofFilePath::getFileName(texPath.data); string realPath = modelFolder + relTexPath + texFile; if(ofFile::doesFileExist(realPath) == false) { ofLogError("ofxAssimpModelLoader") << "loadGLResource(): texture doesn't exist: \"" << file.getFileName() + "\" in \"" << realPath << "\""; } ofxAssimpTexture * assimpTexture = NULL; bool bTextureAlreadyExists = false; for(int j=0; j<textures.size(); j++) { assimpTexture = textures[j]; if(assimpTexture->getTexturePath() == realPath) { bTextureAlreadyExists = true; break; } } if(bTextureAlreadyExists) { meshHelper.assimpTexture = assimpTexture; ofLogVerbose("ofxAssimpModelLoader") << "loadGLResource(): texture already loaded: \"" << file.getFileName() + "\" from \"" << realPath << "\""; } else { ofTexture * texture = new ofTexture(); bool bTextureLoadedOk = ofLoadImage(*texture, realPath); if(bTextureLoadedOk) { textures.push_back(new ofxAssimpTexture(texture, realPath)); assimpTexture = textures.back(); meshHelper.assimpTexture = assimpTexture; ofLogVerbose("ofxAssimpModelLoader") << "loadGLResource(): texture loaded, dimensions: " << texture->getWidth() << "x" << texture->getHeight(); } else { delete texture; ofLogError("ofxAssimpModelLoader") << "loadGLResource(): couldn't load texture: \"" << file.getFileName() + "\" from \"" << realPath << "\""; } } } meshHelper.mesh = mesh; aiMeshToOfMesh(mesh, meshHelper.cachedMesh, &meshHelper); meshHelper.cachedMesh.setMode(OF_PRIMITIVE_TRIANGLES); meshHelper.validCache = true; meshHelper.hasChanged = false; meshHelper.animatedPos.resize(mesh->mNumVertices); if(mesh->HasNormals()){ meshHelper.animatedNorm.resize(mesh->mNumVertices); } int usage; if(getAnimationCount()){ #ifndef TARGET_OPENGLES if(!ofIsGLProgrammableRenderer()){ usage = GL_STATIC_DRAW; }else{ usage = GL_STREAM_DRAW; } #else usage = GL_DYNAMIC_DRAW; #endif }else{ usage = GL_STATIC_DRAW; } meshHelper.vbo.setVertexData(&mesh->mVertices[0].x,3,mesh->mNumVertices,usage,sizeof(aiVector3D)); if(mesh->HasVertexColors(0)){ meshHelper.vbo.setColorData(&mesh->mColors[0][0].r,mesh->mNumVertices,GL_STATIC_DRAW,sizeof(aiColor4D)); } if(mesh->HasNormals()){ meshHelper.vbo.setNormalData(&mesh->mNormals[0].x,mesh->mNumVertices,usage,sizeof(aiVector3D)); } if (meshHelper.cachedMesh.hasTexCoords()){ meshHelper.vbo.setTexCoordData(meshHelper.cachedMesh.getTexCoordsPointer()[0].getPtr(),mesh->mNumVertices,GL_STATIC_DRAW,sizeof(ofVec2f)); } meshHelper.indices.resize(mesh->mNumFaces * 3); int j=0; for (unsigned int x = 0; x < mesh->mNumFaces; ++x){ for (unsigned int a = 0; a < mesh->mFaces[x].mNumIndices; ++a){ meshHelper.indices[j++]=mesh->mFaces[x].mIndices[a]; } } meshHelper.vbo.setIndexData(&meshHelper.indices[0],meshHelper.indices.size(),GL_STATIC_DRAW); //modelMeshes.push_back(meshHelper); } int numOfAnimations = scene->mNumAnimations; for(int i=0; i<numOfAnimations; i++) { aiAnimation * animation = scene->mAnimations[i]; animations.push_back(ofxAssimpAnimation(scene, animation)); } ofLogVerbose("ofxAssimpModelLoader") << "loadGLResource(): finished"; }
bool ofxOpenNI2Grabber::setup(ofxOpenNI2GrabberSettings settings_) { settings = settings_; Status status = STATUS_OK; status = OpenNI::initialize(); if (status == STATUS_OK) { ofLogVerbose() << "initialize PASS"; deviceController.setup(settings); }else { ofLog(OF_LOG_ERROR, "initialize FAIL:\n%s\n", OpenNI::getExtendedError()); } if (status == STATUS_OK) { ofLogVerbose() << "Device open PASS"; }else { ofLogError() << "Device open FAIL: " << OpenNI::getExtendedError(); deviceController.close(); return false; } if (settings.doDepth) { if (depthSource.setup(deviceController)) { streams.push_back(&depthSource.videoStream); }else { settings.doDepth = false; } } if (settings.doColor) { if (rgbSource.setup(deviceController)) { streams.push_back(&rgbSource.videoStream); }else { settings.doColor = false; } } else if(settings.doIr){ if(irSource.setup(deviceController)) { streams.push_back(&irSource.videoStream); } else{ settings.doIr = false; } } if(settings.doRegisterDepthToColor) { if (settings.doDepth && settings.doColor) { deviceController.registerDepthToColor(); } } isReady = true; startThread(false, false); return isReady; }