Exemplo n.º 1
0
void RotatingCubeApp::setup()
{
	try {
		mCapture = Capture( 320, 240 );
		mCapture.start();
	}
	catch( CaptureExc &exc ) {
	    console() << "failed to initialize the webcam, what: " << exc.what() << std::endl;

	    // create a warning texture
		// if we threw in the start, we'll set the Capture to null
		mCapture.reset();
		
		TextLayout layout;
		layout.clear( Color( 0.3f, 0.3f, 0.3f ) );
		layout.setColor( Color( 1, 1, 1 ) );
		layout.setFont( Font( "Arial", 96 ) );
		layout.addCenteredLine( "No Webcam" );
		layout.addCenteredLine( "Detected" );
		mTexture = gl::Texture2d::create( layout.render() );
	}
	
	mCam.lookAt( vec3( 3, 2, -3 ), vec3( 0 ) );
	gl::enableDepthRead();
	gl::enableDepthWrite();
}
Exemplo n.º 2
0
void TextTestApp::setup()
{
    printFontNames();

#if defined( CINDER_COCOA_TOUCH )
    std::string normalFont( "Arial" );
    std::string boldFont( "Arial-BoldMT" );
    std::string differentFont( "AmericanTypewriter" );
#else
    std::string normalFont( "Arial" );
    std::string boldFont( "Arial Bold" );
    std::string differentFont( "Papyrus" );
#endif

    // Japanese
    unsigned char japanese[] = { 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, 0 };
    // this does a complicated layout
    TextLayout layout;
    layout.clear( ColorA( 0.2f, 0.2f, 0.2f, 0.2f ) );
    layout.setFont( Font( normalFont, 24 ) );
    layout.setColor( Color( 1, 1, 1 ) );
    layout.addLine( std::string( "Unicode: " ) + (const char*)japanese );
    layout.setColor( Color( 0.5f, 0.25f, 0.8f ) );
    layout.setFont( Font( boldFont, 12 ) );
    layout.addRightLine( "Now is the time" );
    layout.setFont( Font( normalFont, 22 ) );
    layout.setColor( Color( 0.75f, 0.25f, 0.6f ) );
    layout.append( " for all good men" );
    layout.addCenteredLine( "center justified" );
    layout.addRightLine( "right justified" );
    layout.setFont( Font( differentFont, 24 ) );
    layout.addCenteredLine( "A different font" );
    layout.setFont( Font( normalFont, 22 ) );
    layout.setColor( Color( 1.0f, 0.5f, 0.25f ) );
    layout.addLine( " • Point 1 " );
    layout.setLeadingOffset( -10 );
    layout.addLine( " • Other point with -10 leading offset " );
    layout.setLeadingOffset( 0 );
    layout.setColor( ColorA( 0.25f, 0.5f, 1, 0.5f ) );
    layout.addLine( " • Back to regular leading but translucent" );
    Surface8u rendered = layout.render( true, PREMULT );
    mTexture = gl::Texture( rendered );

    // Create a custom font by loading it from a resource
    Font customFont( Font( loadResource( RES_CUSTOM_FONT ), 72 ) );
    console() << "This font is called " << customFont.getFullName() << std::endl;

    TextLayout simple;
    simple.setFont( customFont );
    simple.setColor( Color( 1, 0, 0.1f ) );
    simple.addLine( "Cinder" );
    simple.addLine( "Font From Resource" );
    mSimpleTexture = gl::Texture( simple.render( true, PREMULT ) );
}
void PathSimplificationApp::draw()
{
   	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) );
    
    cairo::SurfaceImage surface( getWindowWidth(), getWindowHeight());
    cairo::Context ctx( surface );
    
    // draw each path
    for(int i=0; i<mSmPaths.size(); i++){
        // pass the cairo context to draw onto
        drawPath(ctx, mSmPaths[i], drawMode);
    }
    
    // draw the surface
    gl::Texture myTexture = surface.getSurface();
    gl::draw(myTexture);
    
    
    TextLayout layout;
    layout.clear(ColorA(0.1f,0.1f,0.1f,0.7f));
    layout.setColor( Color( 0.9f, 0.9f, 0.9f ) );
    layout.setFont( Font( "Arial", 14 ) );
    
    
    SmoothPath* lastPath;
    if(mSmPaths.size() > 0){
        lastPath = mSmPaths[mSmPaths.size()-1];
    }
    
    if(mSmPaths.size() == 0){
        layout.addCenteredLine("Click and drag to draw a line.");
        layout.addCenteredLine("Press 'R' to clear.");
    }else if(mSmPaths.size() > 0 && lastPath->inProgress){
        int segCount = (lastPath->getPathPoints().size()>0) ? lastPath->getPathPoints().size()-1 : 0;
        layout.addCenteredLine( "Segment Count: " + boost::lexical_cast<std::string>(segCount));
    }else if(mSmPaths.size() > 0 && !lastPath->inProgress){
        int oldSegCount = (lastPath->getPathPoints().size()>0) ? lastPath->getPathPoints().size()-1 : 0;
        int segCount = lastPath->getCurrentPath().getNumSegments();
        int diff = oldSegCount - segCount;
        float per = (float(diff)/float(oldSegCount)) * 100.0f;
        string msg = boost::lexical_cast<std::string>(diff) + " of " + boost::lexical_cast<std::string>(oldSegCount) + " segments were removed. Saving " +boost::lexical_cast<std::string>(per) + "%";
        layout.addCenteredLine(msg);
    }
    
    
    Surface8u rendered = layout.render( true, PREMULT );
    mTextTexture = gl::Texture( rendered );
    
    if( mTextTexture )
		gl::draw( mTextTexture,  Vec2f(10, 10)  );
}
Exemplo n.º 4
0
void QuickTimeSampleApp::loadMovieFile( const fs::path& moviePath )
{
	try {
		// load up the movie, set it to loop, and begin playing
		mMovie = qtime::MovieGl( moviePath );
		mMovie.setLoop();
		mMovie.play();
		
		// create a texture for showing some info about the movie
		TextLayout infoText;
		infoText.clear( ColorA( 0.2f, 0.2f, 0.2f, 0.5f ) );
		infoText.setColor( Color::white() );
		infoText.addCenteredLine( getPathFileName( moviePath.string() ) );
		infoText.addLine( toString( mMovie.getWidth() ) + " x " + toString( mMovie.getHeight() ) + " pixels" );
		infoText.addLine( toString( mMovie.getDuration() ) + " seconds" );
		infoText.addLine( toString( mMovie.getNumFrames() ) + " frames" );
		infoText.addLine( toString( mMovie.getFramerate() ) + " fps" );
		infoText.setBorder( 4, 2 );
		mInfoTexture = gl::Texture( infoText.render( true ) );
	}
	catch( ... ) {
		console() << "Unable to load the movie." << std::endl;
		mMovie.reset();
		mInfoTexture.reset();
	}

	mFrameTexture.reset();
}
Exemplo n.º 5
0
void QuickTimeSampleApp::loadMovieFile( const fs::path &moviePath )
{
	try {
		// load up the movie, set it to loop, and begin playing
		mMovie = qtime::MovieGl::create( moviePath );
		mMovie->setLoop();
		mMovie->play();
		
		// create a texture for showing some info about the movie
		TextLayout infoText;
		infoText.clear( ColorA( 0.2f, 0.2f, 0.2f, 0.5f ) );
		infoText.setColor( Color::white() );
		infoText.addCenteredLine( moviePath.filename().string() );
		infoText.addLine( toString( mMovie->getWidth() ) + " x " + toString( mMovie->getHeight() ) + " pixels" );
		infoText.addLine( toString( mMovie->getDuration() ) + " seconds" );
		infoText.addLine( toString( mMovie->getNumFrames() ) + " frames" );
		infoText.addLine( toString( mMovie->getFramerate() ) + " fps" );
		infoText.setBorder( 4, 2 );
		mInfoTexture = gl::Texture::create( infoText.render( true ) );
	}
	catch( ci::Exception &exc ) {
		console() << "Exception caught trying to load the movie from path: " << moviePath << ", what: " << exc.what() << std::endl;
		mMovie.reset();
		mInfoTexture.reset();
	}

	mFrameTexture.reset();
}
Exemplo n.º 6
0
void MenuObject::setTitle(string tit){
	title = tit;
	TextLayout layout;
	layout.setFont(Font(loadAsset("ArcadeClassic.ttf"), 60));
	layout.setColor(Color( 1.0f, 1.0f, 1.0f) );
	layout.clear(ColorA(1.0f, 1.0f, 1.0f, 0.0f));
	layout.addCenteredLine(title);
	renderedTitle = gl::Texture(layout.render(true, true));
}
Exemplo n.º 7
0
Quake::Quake( float aLat, float aLong, float aMag, string aTitle )
{
	mLat	= aLat;
	mLong	= aLong;
	mMag	= aMag;
	mTitle	= aTitle;
	
	TextLayout layout;
	ostringstream os;
	os << mMag;
	if( os.str().length() == 1 ){
		os << ".0";
	}
	
	
	
	if( mMag > 5.5 ){
		layout.setFont( Font( "HelveticaNeue-Bold", mMag * mMag + 26.0f ) );
		layout.setColor( Color( 1, 0, 0 ) );
	} else {
		layout.setFont( Font( "HelveticaNeue-Bold", mMag * mMag + 10.0f ) );
		layout.setColor( Color( 1, 1, 1 ) );
	}
	layout.addCenteredLine( os.str() );
	
	
	if( mMag > 5.5 ){
		layout.setLeadingOffset( -10 );
		layout.setFont( Font( "HelveticaNeue", mMag + 16 ) );
		layout.setColor( Color( 1, 1, 1 ) );
		layout.addCenteredLine( mTitle );
	}
	

	mLabel = gl::Texture( layout.render( true ) );
	
	setLoc();
}
Exemplo n.º 8
0
void CatMemeMakerApp::saveFirst()
{
	TextLayout simple;

	std::string normalFont( "Arial" );

	simple.setFont( Font(normalFont,48) );
	simple.setColor( Color( 1, 1, 1 ) );
	simple.addCenteredLine(mMessage.str());

	mFirstLine = gl::Texture( simple.render( true , false ) );

	mMessage.str(" ");
}
Exemplo n.º 9
0
void ardroneApp::setInfo(const std::string& path, const std::string& errorMessage){
    // create a texture for showing some info about the movie
    TextLayout infoText;
    infoText.clear( ColorA( 0.2f, 0.2f, 0.2f, 0.25f ) );
    infoText.setColor( Color::white() );
    infoText.addCenteredLine( path);
    if (!errorMessage.empty()) {
        infoText.addLine(errorMessage);
    } else {
        infoText.addLine( toString( mMovie->getWidth() ) + " x " + toString( mMovie->getHeight() ) + " pixels" );
        if (mMovie->getDuration() > 0.f) infoText.addLine( toString( mMovie->getDuration() ) + " seconds" );
        infoText.addLine( toString( mMovie->getNumFrames() ) + " frames" );
        infoText.addLine( toString( mMovie->getFramerate() ) + " fps" );
    }
    infoText.setBorder( 4, 2 );
    mInfoTexture = gl::Texture( infoText.render( true ) );
}
void MovieBasicApp::onReadySignal()
{    
	// create a texture for showing some info about the movie
	TextLayout infoText;
	infoText.clear( ColorA( 0.2f, 0.2f, 0.2f, 0.5f ) );
	infoText.setColor( Color::white() );
	infoText.addCenteredLine( mMoviePath.filename().string() );
	infoText.addLine( toString( mMovie->getWidth() ) + " x " + toString( mMovie->getHeight() ) + " pixels" );
	infoText.addLine( toString( mMovie->getDuration() ) + " seconds" );
	infoText.addLine( toString( mMovie->getNumFrames() ) + " frames" );
	infoText.addLine( toString( mMovie->getFramerate() ) + " fps" );
	infoText.setBorder( 4, 2 );
	mInfoTexture = gl::Texture( infoText.render( true ) );

	mMovie->setVolume(1.0f);
	mMovie->play();
}
Exemplo n.º 11
0
void CatMemeMakerApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) ); 
	gl::enableAlphaBlending();

	//Check that the url fetch was successful
	if (mImage) {
		//Draw the Cat!
		mImage.enableAndBind();
		gl::draw( mImage, getWindowBounds() );
	}

	//If we are on the second line, write what we used to have for the first line up top
	if (mFirstLine) {
		gl::draw(mFirstLine,Vec2f( getWindowSize().x/2 - mFirstLine.getWidth()/2, 10 ));
	}

	//Render the texture with the message
	TextLayout simple;

	std::string normalFont( "Arial" );

	simple.setFont( Font(normalFont,48) );
	simple.setColor( Color( 1, 1, 1 ) );

	//White looked bad on the second line... so change to black if on second line
	if (mFirstLine) {
		simple.setColor( Color( 255, 255, 255 ) );
	}
	simple.addCenteredLine(mMessage.str());

	mTexture = gl::Texture( simple.render( true , false ) );

	//Draw the message, centered!
	if (mFirstLine) {
		gl::draw(mTexture,Vec2f( getWindowSize().x/2 - mTexture.getWidth()/2, getWindowSize().y -50));
	}
	else {
		gl::draw(mTexture,Vec2f( getWindowSize().x/2 - mTexture.getWidth()/2, 10 ));
	}
}
Exemplo n.º 12
0
	void loadMovieFile( const std::string &moviePath )
	{
		glEnable(GL_TEXTURE_RECTANGLE_ARB);
		gl::Texture::Format format;
		format.setTargetRect();

		try {
			// load up the movie, set it to loop, and begin playing
			mMovie = qtime::MovieGl( moviePath );
			mMovie.setLoop();
//			mMovie.play();

			// create a texture for showing some info about the movie
			TextLayout infoText;
			infoText.clear( ColorA( 0.2f, 0.2f, 0.2f, 0.5f ) );
			infoText.setColor( Color::white() );
			infoText.addCenteredLine( getPathFileName( moviePath ) );
			infoText.addLine( toString( mMovie.getWidth() ) + " x " + toString( mMovie.getHeight() ) + " pixels" );
			infoText.addLine( toString( mMovie.getDuration() ) + " seconds" );
			infoText.addLine( toString( mMovie.getNumFrames() ) + " frames" );
			infoText.addLine( toString( mMovie.getFramerate() ) + " fps" );
			infoText.setBorder( 4, 2 );
			mInfoTexture = gl::Texture( infoText.render( true ) );
			
			setWindowSize(mMovie.getWidth(), mMovie.getHeight());
			mHasMovie = true;
		}
		catch( ... ) {
			console() << "Unable to load the movie." << std::endl;
			mMovie.reset();
			mInfoTexture.reset();
			mHasMovie = false;
			//exit(1);
		}
		mFrameTexture.reset();
	}
Exemplo n.º 13
0
void ardroneApp::update()
{
	if( mMovie )
		mFrameTexture = mMovie->getTexture();

    float s = 0.02;
    
    if(keys[cinder::app::KeyEvent::KEY_UP]) drone.controller.pitchAmount -= s;
    else if(keys[cinder::app::KeyEvent::KEY_DOWN]) drone.controller.pitchAmount += s;
    
    if(keys['a']) drone.controller.rollAmount -= s;
    else if(keys['d']) drone.controller.rollAmount += s;
    
    if(keys['w']) drone.controller.liftSpeed += s;
    else if(keys['s']) drone.controller.liftSpeed -= s;
    
    if(keys[cinder::app::KeyEvent::KEY_LEFT]) drone.controller.spinSpeed -= s;
    else if(keys[cinder::app::KeyEvent::KEY_RIGHT]) drone.controller.spinSpeed += s;
    
    // update the drone (process and send queued commands to drone, receive commands from drone and update state
    drone.update();
    
    // update position of simulator (OPTIONAL)
    droneSimulator.update();
    
    TextLayout infoText;
    infoText.clear( ColorA( 0.2f, 0.2f, 0.2f, 0.25f ) );
    infoText.setColor( Color::white() );
//    infoText.addCenteredLine( path);
//    if (!errorMessage.empty()) {
//        infoText.addLine(errorMessage);
//    } else {
//        infoText.addLine( toString( mMovie->getWidth() ) + " x " + toString( mMovie->getHeight() ) + " pixels" );
//        if (mMovie->getDuration() > 0.f) infoText.addLine( toString( mMovie->getDuration() ) + " seconds" );
//        infoText.addLine( toString( mMovie->getNumFrames() ) + " frames" );
//        infoText.addLine( toString( mMovie->getFramerate() ) + " fps" );
//    }
    infoText.setBorder( 4, 2 );


    
    string controllerString = "fps: " + toString(getFrameRate()) + "\n";
    controllerString += "millisSinceLastSend: " + toString(drone.controller.getMillisSinceLastSend()) + "\n";
    controllerString += "\n";
    controllerString += "takeOff (t)\n";
    controllerString += "land (l)\n";
    controllerString += "calibrateHorizontal (c)\n";
    controllerString += "calibrateMagnetometer (m)\n";
    controllerString += "EMERGENCY (E)\n";
    controllerString += "\n";
    controllerString += "roll (a/d)        : " + toString(drone.controller.rollAmount) + "\n";
    controllerString += "pitch (up/down)   : " + toString(drone.controller.pitchAmount) + "\n";
    controllerString += "lift (w/s)        : " + toString(drone.controller.liftSpeed) + "\n";
    controllerString += "spin (left/right) : " + toString(drone.controller.spinSpeed) + "\n";
    controllerString += "\n";
    controllerString += "reset droneSimulator (r)\n";
    controllerString += "debug history (h)\n";
    controllerString += "fullscreen (f)\n";
    controllerString += "PAUSE (p)\n";
    
    infoText.addCenteredLine( controllerString);
    
    ofxARDrone::State &state = drone.state;
    string stateString = "";
    stateString += "isFlying : " + toString(state.isFlying()) + "\n";
    stateString += "isTakingOff : " + toString(state.isTakingOff()) + ", " + toString(state.isTakingOffMillis()) + "\n";
    stateString += "isLanding : " + toString(state.isLanding()) + ", " + toString(state.isLandingMillis()) + "\n";
    stateString += "isCalibratingHorizontal : " + toString(state.isCalibratingHorizontal()) + ", " + toString(state.isCalibratingHorizontalMillis()) + "\n";
    stateString += "isCalibratingMagnetometer : " + toString(state.isCalibratingMagnetometer()) + ", " + toString(state.isCalibratingMagnetometerMillis()) + "\n";
    
    
    stateString += "\n\nisConnected: " + toString(state.isConnected()) + ", " + toString(state.isCalibratingMagnetometerMillis()) + "\n";
    stateString += "altitude: "+ toString(state.getAltitude())+"\n";
    stateString += "emergency state: "+ toString(state.inEmergencyMode())+"\n";
    stateString += "battery level: "+ toString(state.getBatteryPercentage())+"%\n";
    stateString += "vx: "+ toString(state.getVx())+" vy: "+ toString(state.getVy())+" vz: "+ toString(state.getVz())+"\n";
    
    infoText.addCenteredLine(stateString);
    mInfoTexture = gl::Texture( infoText.render( true ) );
}