Ejemplo n.º 1
0
void RetinaSampleApp::draw()
{
	gl::clear( Color( 0.1f, 0.1f, 0.15f ) );
	gl::enableAlphaBlending();
	
	gl::pushMatrices();
		gl::color( 1.0f, 0.5f, 0.25f );
		gl::lineWidth( toPixels( 1.0f ) );
		gl::draw( mPoints );
	gl::popMatrices();
	
	// rotate a 200x200pt square at the center of the window
	gl::pushMatrices();
		gl::color( 1.0f, 0.2f, 0.15f );
		gl::translate( getWindowCenter() );
		gl::rotate( getElapsedSeconds() * 5 );
		gl::drawSolidRect( Rectf( Area( -100, -100, 100, 100 ) ) );
	gl::popMatrices();

	// draw the logo in the lower-left corner at 64x64 points
	gl::color( Color::white() );
	gl::draw( mLogo, Rectf( 0, getWindowHeight() - 64, 64, getWindowHeight() ) );

	// The font has been made double the size we need for non-Retina, so we always scale by 0.5f
	// another strategy would be to use two different TextureFonts
	std::string s = ( getWindowContentScale() > 1 ) ? "Retina" : "Non-Retina";
	float stringWidth = mFont->measureString( s ).x * 0.5f;
	mFont->drawString( s, Vec2f( getWindowWidth() - stringWidth - 12, getWindowHeight() - 12 ),
		gl::TextureFont::DrawOptions().scale( 0.5f ).pixelSnap( false ) );
}
Ejemplo n.º 2
0
void DXTencoderApp::draw()
{
    gl::clear( Color( 0, 1.0, 1.0 ) );
    gl::color(1, 1, 1, 1);

    gl::enableAlphaBlending( true );
    
    if( ( ! mMovie ) || ( ! mSurface ) || !isStarted ){

        gl::color(0, 0, 0, 1);

        gl::color(1, 1, 1, 1);
        mTextureFont->drawString("DRAG VIDEO FILE IN THIS WINDOW", getWindowCenter() - vec2(210,0));

        return;
    }
    
    if(scaledSurface.getWidth() < getWindowWidth()){
        gl::draw( gl::Texture::create( scaledSurface ),vec2(0,100) );
        gl::draw( gl::Texture::create( correctedSurface ),vec2(scaledSize.x + 10,100) );
    }else{
        gl::color(1, 1, 1, 1);
        mTextureFont->drawString("NO PREVIEW VIDEO IS TO LARGE", getWindowCenter() - vec2(210,0));

    }

    gl::color(0, 0, 0, 0.6);
    gl::drawSolidRect(Rectf(0,0,getWindowWidth(),100));

    gl::color(1, 1, 1, 1);
    mTextureFont->drawString("ENCODING FRAME: " + toString(currentFrame) + " / " + toString(endFrame), ivec2(20,35));
    
    gl::drawString("original size: " + toString(mMovie->getSize()) , ivec2(20,70));
    gl::drawString("scaled size: " + toString(scaledSize) , ivec2(20,85));
    gl::drawString("corrected %4 size: " + toString(correctedSize) , ivec2(scaledSize.x + 20,85));

    gl::color(1, 1, 1, 1);
    float width = lmap(currentFrame, 0, endFrame, 0, getWindowWidth());
    gl::drawSolidRect(Rectf(0,45,width ,60));
    

    gl::color(1, 1.0, 1.0, 1.0);

    float lineHeight = 100 + correctedSize.y;
    gl::drawLine(vec2(0,lineHeight), vec2(getWindowWidth(),lineHeight));

    gl::color(1, .4, .7, 0.8);

    gl::drawLine(vec2(0,100 + 256), vec2(getWindowWidth(),100 + 256));
    gl::drawString("screen bottom " , ivec2(scaledSize.x +correctedSize.x + 20,90 + 256 ), Color(1,0.4,0.8));
    
}
Ejemplo n.º 3
0
void TextureFontApp::draw()
{
	gl::setMatricesWindow( getWindowSize() );
	gl::enableAlphaBlending();
	gl::clear( Color( 0, 0, 0 ) );
	
	std::string str( "Granted, then, that certain transformations do happen, it is essential that we should regard them in the philosophic manner of fairy tales, not in the unphilosophic manner of science and the \"Laws of Nature.\" When we are asked why eggs turn into birds or fruits fall in autumn, we must answer exactly as the fairy godmother would answer if Cinderella asked her why mice turned into horses or her clothes fell from her at twelve o'clock. We must answer that it is MAGIC. It is not a \"law,\" for we do not understand its general formula." );
	Rectf boundsRect( 40, mTextureFont->getAscent() + 40, getWindowWidth() - 40, getWindowHeight() - 40 );

	gl::color( ColorA( 1, 0.5f, 0.25f, 1.0f ) );

#if defined( CINDER_COCOA )
	mTextureFont->drawStringWrapped( str, boundsRect );
#else
	mTextureFont->drawString( str, boundsRect );
#endif	

	// Draw FPS
	gl::color( Color::white() );
	mTextureFont->drawString( toString( floor(getAverageFps()) ) + " FPS", Vec2f( 10, getWindowHeight() - mTextureFont->getDescent() ) );
    
    // Draw Font Name
	float fontNameWidth = mTextureFont->measureString( mTextureFont->getName() ).x;
	mTextureFont->drawString( mTextureFont->getName(), Vec2f( getWindowWidth() - fontNameWidth - 10, getWindowHeight() - mTextureFont->getDescent() ) );
}
void BasicShaderIIApp::draw()
{
	gl::clear( Color::black() ); 
	// Draw FPS
	gl::color( Color::white() );
	mTextureFont->drawString( toString( floor(getAverageFps()) ) + " FPS", Vec2f( 100, getWindowHeight() - mTextureFont->getDescent() ) );
    
    gl::pushMatrices();
	gl::setMatrices( mCam );
    gl::enableAlphaBlending();
    
	// draw interface
	params::InterfaceGl::draw();
	
	if( mDoSave )
	{	// save non-conflicting image
		// includes interface to record parameters
		saveFrame();
		mDoSave = false;
	}
    
    mShader.bind();
    mShader.uniform("lightDir", mLightDir );   
    
    gl::pushMatrices();
    gl::rotate( mArcball.getQuat() );
    gl::draw( mVBO );
    gl::popMatrices();
    mShader.unbind();     
    
    gl::popMatrices();
}
void RoyalSociety_jiangy9LucyApp::draw()
{
	gl::draw(*mySurface);

	// display message to explain the controls of my application by "?"-> implement main goal 2 
	if(press%2==1){
		mFont = Font( "Times New Roman", 24 );
		mTextureFont = gl::TextureFont::create( mFont );
		std::string str("Welcome! Press '/' key can open and close this introduction. Use mouse clicking to create flowers with 3 different colors in gray rectangle between grass and river!");
		gl::color( Color8u( 0,0,0 ) );
		gl::enableAlphaBlending();
		Rectf boundsRect( 40, mTextureFont->getAscent() + 40, getWindowWidth() - 40, getWindowHeight() - 40 );
		mTextureFont->drawStringWrapped( str, boundsRect );
		gl::color(Color8u(255,255,255));
	}

}
Ejemplo n.º 6
0
void HW02App::draw()
{
	if(show_info)
	{
		gl::setMatricesWindow( getWindowSize() );
		gl::enableAlphaBlending();
		gl::clear( Color( 0, 0, 0 ) );
	
		std::string str("Press '?' to show/hide these instructions. Press 'p' to push the bottom shape to the front of the list.  Press 'r' to reverse the list.");
		Rectf boundsRect( 40, mTextureFont->getAscent() + 40, getWindowWidth() - 40, getWindowHeight() - 40 );

		gl::color( ColorA( 1, 0.5f, 0.25f, 1.0f ) );

		mTextureFont->drawStringWrapped( str, boundsRect );
	}
	else
	{
		gl::clear(Color(0,0,0));
		gl::draw(*mySurface_);
	}
}
Ejemplo n.º 7
0
void TextParticlesApp::drawTextToFbo()
{
	{
		vec2 size = mTextFbo->getSize();
		gl::ScopedFramebuffer scpFbo( mTextFbo );
		gl::clear( ColorA( 0 , 0, 0, 0 ) );
		gl::ScopedViewport scpVp( ivec2(), size );
		gl::ScopedMatrices scpMtrx;
		gl::ScopedColor scpCol( 1, 1, 1);
		
		vec2 stringSize = mTextureFont->measureString( mString );
		float descent = mTextureFont->getDescent();
		float ascent = mTextureFont->getAscent();
		mTextSize = stringSize + vec2( 0, descent );
		
		// OPTIONALLY, draw the text metrics
		/*
		// string size - RED
		gl::color(1, 0, 0);
		gl::drawSolidRect( Rectf( -10, 0, stringSize.x + 10.0, stringSize.y ) );
		// ascent - CYAN
		gl::color(0, 1, 1);
		gl::drawSolidRect( Rectf( 0, stringSize.y - ascent, stringSize.x, ascent ) );
		// descent - YELLOW
		gl::color(1, 1, 0);
		gl::drawSolidRect( Rectf( 0, stringSize.y-descent, stringSize.x, stringSize.y ) );
		// above ascent
		gl::color( 0, 1, 0 );
		gl::drawSolidRect( Rectf( 0, 0, stringSize.x, stringSize.y-ascent ) );*/
		
		// DRAW string to FBO
		gl::color(1, 1, 1);
		mTextureFont->drawString( mString, vec2( 0, stringSize.y - descent ) );
	}
	
	// GET Texture from FBO
	mTextSurf = Surface( mTextFbo->readPixels8u( mTextFbo->getBounds() ) );
}
void MPEBouncingBallApp::mpeFrameRender(bool isNewFrame)
{
    // Just for the hell of it to see if we can crash by accessing the same data on different threads.
    if (mBalls.size() > 0)
    {
        mBalls[0].manipulateInternalData();
    }

    gl::clear(Color(0,0,0));

    // Paint the Master drawable region gray if we're in step with the server, or red if our
    // draw loop is ahead of the server.
    // The App's loop will continue at the normal speed even if we're waiting for data from the
    // server, we just don't update the state.
    // A flickering background means the FPS is faster than the server data-rate.
    if (mClient->isConnected())
    {
        if (isNewFrame)
        {
            gl::color(Color(0.8, 0.75, 0.75));
        }
        else
        {
            gl::color(Color(1, 0.25, 0.25));
        }
    }
    else
    {
        // Gray if we're not connected
        gl::color(Color(0.5, 0.5, 0.5));
    }

    ivec2 masterSize = mClient->getMasterSize();
    Rectf masterFrame = Rectf(0,0,masterSize.x,masterSize.y);
    gl::drawSolidRect(masterFrame);

    gl::color(0.2,0.2,0.2);
    gl::enableAlphaBlending();
    std::ostringstream stringStream;
    stringStream << "Client ID: " << std::to_string(CLIENT_ID) << std::endl;
    stringStream << "FPS: " << std::to_string((int)getAverageFps()) << std::endl;
    stringStream << "Frame Num: " << std::to_string(mClient->getCurrentRenderFrame()) << std::endl;
    stringStream << "Updates Per Second: " << std::to_string((int)mClient->getUpdatesPerSecond());
    string str = stringStream.str();
    vec2 stringSize = mTextureFont->measureStringWrapped(str, Rectf(0,0,400,400));
    vec2 stringOffset(40,40);
    vec2 rectOffset = mClient->getVisibleRect().getUpperLeft() + stringOffset;
    gl::drawSolidRect(Rectf(rectOffset.x - 10,
                            rectOffset.y - 10,
                            rectOffset.x + 20 + stringSize.x,
                            rectOffset.y + 20 + stringSize.y - mTextureFont->getAscent()));
    gl::color(0.9,0.9,0.9);
    mTextureFont->drawStringWrapped(str,
                                    mClient->getVisibleRect(),
                                    vec2(0, mTextureFont->getAscent()) + stringOffset);

    gl::disableAlphaBlending();

    glEnable (GL_DEPTH_TEST);

    for( Ball & ball : mBalls )
    {
        ball.draw( mClient->getIsRendering3D() );
    }

    glDisable (GL_DEPTH_TEST);

}
Ejemplo n.º 9
0
void ProjectionMappingApp::draw()
{
	if (mEditMode == EditMode_RECORD) {
		//		std::string imgName = (boost::format("%s\\out_images\\image_%05d.png") % SeqImageDir % mFrame).str();
		
		std::string imgName = (boost::format("%s\\%s_%05d.png") % mOutImageFolder % mOutImageName % mFrame).str();
			
		writeImage(imgName.c_str(), mFbo.getTexture());
		++mFrame;
	}

	gl::clear(Color(0, 0, 0));
	glColor3f(1, 1, 1);

	// 画像の表示を下向きに(もとに戻す)
	gl::setMatricesWindow(getWindowSize(), true); 
	
	glPushMatrix();
	if (mScale < 1.0) {
		Vec2f wc = getWindowCenter();
		glTranslatef(wc.x/2, wc.y/2, 0.0);
		glScalef(mScale, mScale, mScale);
	}

	if (mMeshMode) {
		glColor3f(1, 1, 0);
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		gl::draw(mMesh);
	} else {
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		gl::draw(mFbo.getTexture());
	}

	if (mIsShowCtrlMesh) {
		for (int k = 0; k < mCtrlPointsNum; ++k) {
			Vec2f p = mCtrlPoints[k].pos;
			glColor3f(0, 0, 0);
			gl::drawStrokedRect(Rectf(p.x-5+1, p.y-5+1, p.x+5+1, p.y+5+1));
			if (mCtrlPoints[k].isSelected) {
				glColor3f(1, 0, 0);
			} else {
				glColor3f(1, 1, 1);
			}
			gl::drawStrokedRect(Rectf(p.x-5, p.y-5, p.x+5, p.y+5));
		}

		for (int j = 0; j < 2; ++j) {	
			for (int i = 0; i < 2; ++i) {
				float px = distpoints[j][i][0];
				float py = distpoints[j][i][1];
				glColor3f(1, 1, 0);
				gl::drawStrokedRect(Rectf(px-10, py-10, px+10, py+10));
			}
		}
	}

	glPopMatrix();

	if (mSelectionMode) gl::drawStrokedRect(mSelectRegion);
	params::InterfaceGl::draw();
	
	if (mEditMode == EditMode_RECORD) {
		gl::enableAlphaBlending();
		const int ix = 700;
		const int iy = 900;
		mTexFont->drawString((boost::format("RENDERING : [%d / %d] Done.") % mFrame % mDuration).str(), Rectf(ix, iy, ix+500, iy+200));
	}
}
Ejemplo n.º 10
0
void iosAppTestApp::draw()
{
	gl::enableAlphaBlending();
	gl::enableDepthRead();
	tester.setState( TestCallbackOrder::DRAW );
	CameraPersp mCam;
	mCam.lookAt( Vec3f( 3, 2, -3 ), Vec3f::zero() );
	mCam.setPerspective( 60, getWindowAspectRatio(), 1, 1000 );

	if( isUnplugged() )
		gl::clear( Color( 0.2f, 0.2f, 0.3f ) );
	else
		gl::clear( Color( 0.4f, 0.2f, 0.2f ) );		

	gl::enable( GL_TEXTURE_2D );
	gl::color( Color::white() );
	gl::enableDepthRead();
	mTex.bind();
	gl::setMatrices( mCam );
	glPushMatrix();
		gl::multModelView( mCubeRotation );
		gl::drawCube( Vec3f::zero(), Vec3f( 2.0f, 2.0f, 2.0f ) );
	glPopMatrix();
	gl::disable( GL_TEXTURE_2D );
	
	gl::setMatricesWindow( getWindowSize() );
	for( map<uint32_t,TouchPoint>::const_iterator activeIt = mActivePoints.begin(); activeIt != mActivePoints.end(); ++activeIt ) {
		activeIt->second.draw();
	}

	for( list<TouchPoint>::iterator dyingIt = mDyingPoints.begin(); dyingIt != mDyingPoints.end(); ) {
		dyingIt->draw();
		if( dyingIt->isDead() )
			dyingIt = mDyingPoints.erase( dyingIt );
		else
			++dyingIt;
	}
	
	// draw yellow circles at the active touch points
	gl::color( Color( 1, 1, 0 ) );
	for( auto touch : getActiveTouches() )
		gl::drawStrokedCircle( touch.getPos(), 20.0f );
			
	if( getWindow() == mSecondWindow || Display::getDisplays().size() < 2 ) {
		static Font font = Font( "Arial", 48 );
		static std::string lastMessage;
		static gl::Texture messageTex;
		if( lastMessage != mSecondWindowMessage ) {
			TextBox box = TextBox().font( font ).text( mSecondWindowMessage );
			messageTex = box.render();
			lastMessage = mSecondWindowMessage;
		}
		if( messageTex ) {
			gl::color( Color::white() );
			gl::draw( messageTex, Vec2i( ( getWindowWidth() - messageTex.getCleanWidth() ) / 2, getWindowCenter().y ) );
		}
	}
//
	gl::disableDepthRead();
	gl::color( Color( 0.0f, 1.0f, 0.0f ) );
	mFont->drawString( orientationString( getWindowOrientation() ) + "@ " + toString( getWindowContentScale() ), Vec2f( 10.0f, 60.0f ) );
//	gl::drawStringCentered( "Orientation: " + orientationString( getInterfaceOrientation() ), Vec2f( getWindowCenter().x, 30.0f ), Color( 0.0f, 1.0f, 0.0f ), Font::getDefault() ); // ???: why not centered?

	mFont->drawString( toString( floor(getAverageFps()) ) + " fps", Vec2f( 10.0f, 90.0f ) );
}
Ejemplo n.º 11
0
void Homework02App::draw()
{
	/*
	I think a better way to impliment all this code in your draw() method
	would be to have it in seperate methods that could be called more easily.
	This would also cut down the clutter in this method and make your code more readable
	*/

	gl::enableAlphaBlending();
	gl::clear(Color(120,120,120));

	//Draws the 12 squares for the background
	//Row 1
	gl::color(ColorA(255,0,0,.5f));
	gl::drawSolidRect(Rectf(0,0,200,200), false);	
	gl::color(ColorA(255,255,0,.5f));
	gl::drawSolidRect(Rectf(200,0,400,200), false);
	gl::color(ColorA(0,0,255,.5f));
	gl::drawSolidRect(Rectf(400,0,600,200), false);
	gl::color(ColorA(0,255,0,.5f));
	gl::drawSolidRect(Rectf(600,0,800,200), false);

	//Row 2
	gl::color(ColorA(0,255,0,.5f));
	gl::drawSolidRect(Rectf(0,200,200,400), false);	
	gl::color(ColorA(255,0,0,.5f));
	gl::drawSolidRect(Rectf(200,200,400,400), false);
	gl::color(ColorA(255,255,0,.5f));
	gl::drawSolidRect(Rectf(400,200,600,400), false);
	gl::color(ColorA(0,0,255,.5f));
	gl::drawSolidRect(Rectf(600,200,800,400), false);

	//Row 3
	gl::color(ColorA(0,0,255,.5f));
	gl::drawSolidRect(Rectf(0,400,200,600), false);	
	gl::color(ColorA(0,255,0,.5f));
	gl::drawSolidRect(Rectf(200,400,400,600), false);
	gl::color(ColorA(255,0,0,.5f));
	gl::drawSolidRect(Rectf(400,400,600,600), false);
	gl::color(ColorA(255,255,0,.5f));
	gl::drawSolidRect(Rectf(600,400,800,600), false);

	//Inner Row 1
	gl::color(ColorA(255,0,0,.5f));
	gl::drawSolidRect(Rectf(100,100,300,300), false);	
	gl::color(ColorA(0,255,0,.5f));
	gl::drawSolidRect(Rectf(300,100,500,300), false);
	gl::color(ColorA(0,0,255,.5f));
	gl::drawSolidRect(Rectf(500,100,700,300), false);

	//Inner Row 2
	gl::color(ColorA(0,0,255,.5f));
	gl::drawSolidRect(Rectf(100,300,300,500), false);	
	gl::color(ColorA(255,0,0,.5f));
	gl::drawSolidRect(Rectf(300,300,500,500), false);
	gl::color(ColorA(0,255,255,.5f));
	gl::drawSolidRect(Rectf(500,300,700,500), false);

	//Creates the string for instructions
	std::string str( "Click any of the rings to bring them to the front of the screen. Press 'R' to reverse the order of the rings. Press '?' to toggle these instructions on/off the screen. Mini-game: Count the number of squares displayed on the screen! (squares underneath squares count, but the border of the program is not a square) Tweet @mmarsden5 with your answer and be the first to win!");
	Rectf boundsRect( 40, mTextureFont->getAscent() + 40, getWindowWidth() - 40, getWindowHeight() - 40 );

	//Text color
	ColorA semiTransparent = ColorA(0,0,0,.9f);
	gl::color(semiTransparent);
	mTextureFont->drawStringWrapped( str, boundsRect );

	Node* current_ = sentinel -> next_;
	do{
		current_ -> draw();
		current_  = current_ -> next_;
	} while(current_ != sentinel);

}
Ejemplo n.º 12
0
void GoApp::draw()
{
	gl::clear( Color( 0.9f, 0.5f, 0.05f ) );
	
	gl::color( 0.0f, 0.0f, 0.0f );
	for (int i = 0; i < M; ++i) {
		int x  = board_x + i * board_width;
		int y1 = board_y;
		int y2 = board_y + (M-1) * board_width;
		gl::drawLine(Vec2f(x, y1), Vec2f(x, y2));

		int y  = board_y + i * board_width;
		int x1 = board_x;
		int x2 = board_x + (N-1) * board_width;
		gl::drawLine(Vec2f(x1, y), Vec2f(x2, y));
	}

	if (M == 9 && N == 9) {
		gl::color( 0.0f, 0.0f, 0.0f );
		gl::drawSolidCircle(Vec2f(board_x + 2 * board_width, board_y + 2 * board_width ), 3.0f);
		gl::drawSolidCircle(Vec2f(board_x + 6 * board_width, board_y + 6 * board_width ), 3.0f);
		gl::drawSolidCircle(Vec2f(board_x + 6 * board_width, board_y + 2 * board_width ), 3.0f);
		gl::drawSolidCircle(Vec2f(board_x + 2 * board_width, board_y + 6 * board_width ), 3.0f);
		gl::drawSolidCircle(Vec2f(board_x + 4 * board_width, board_y + 4 * board_width ), 3.0f);
	}

	for (int i = 0; i < M; ++i) {
	for (int j = 0; j < N; ++j) {
		Vec2f pos(board_x + j * board_width, board_y + i * board_width );

		if ( ! state.is_move_possible(i, j)) {
			gl::color( 1.0f, 0.0f, 0.0f );	
			gl::drawSolidCircle(pos, 4.0f );
		}

		if (state.get_pos(i, j) == GoState<M, N>::player1) {
			gl::color( 0.0f, 0.0f, 0.0f );
			gl::drawSolidCircle(pos, board_width / 2 - 1);
		}
		else if (state.get_pos(i, j) == GoState<M, N>::player2) {
			gl::color( 1.0f, 1.0f, 1.0f );
			gl::drawSolidCircle(pos, board_width / 2 - 1);
		}
	}}

	stringstream sout;
	if (game_status == WAITING_FOR_USER) {
		sout << "Make your move!" << endl;
	}
	else if (game_status == COMPUTER_THINKING) {
		sout << "Computing..." << endl;
	}
	else if (game_status == GAME_OVER) {
		sout << "Game over!" << endl;
	}
	else if (game_status == GAME_ERROR) {
		sout << "ERROR:\n" << error_string << endl;
	}

	sout << "Player 1 (black) score: " << state.get_player_score(1) << endl;
	sout << "Player 2 (white) score: " << state.get_player_score(2) << endl;

	//sout << "Board hash: " << state.previous_board_hash_value << " -> " << state.compute_hash_value() << endl;
	//for (auto move: state.get_moves()) {
	//	sout << move << " ";
	//}

	Rectf boundsRect(board_x, board_y + M * board_width + 20, 
	                 getWindowWidth() - 40, getWindowHeight() - 40 );
	gl::enableAlphaBlending();
	gl::color( ColorA( 0, 0, 0, 1.0f ) );
	mTextureFont->drawStringWrapped( sout.str(), boundsRect );
}