예제 #1
0
int main()
{

    RenderSystem system;

    /*!
        We need a timer to keep track of the difference in time
        between each frame. This just allows us to use the concept
        of delta time, which is beyond the scope of this example.
    */
    Timer timer;
    timer.start();

    while( system.run() )
    {
        /*!
            We'll draw some text at various locations so that you know where you're at.
        */
        system.drawText( "Top Left" , Vector2d( 0,0 ) );
        system.drawText( "Center", Vector2d( 320,240 ), Color( 255,127,127 ) );
        system.drawText( "Bottom Right", Vector2d( 640,480 ), Color( 255,0,0 ) );
        system.drawText( "Top Right", Vector2d( 640,0 ), Color( 0,255,0 ) );
        system.drawText( "Bottom Left", Vector2d( 0, 480 ), Color( 0,0,255 ) );

        /*!
            Now for view control. We'll use the time to compute how much we should move
            the view when the player holds down the key. You could also rotate and scale
            the view, but I'll leave that up to you!
        */
		if( EventReceiver::Instance()->getKey( PHK_LEFT ) ){
			system.getView().setPosition( 
				system.getView().getPosition() 
				+ ( Vector2d( -100.0f , 0.0f ) 
				* (float)timer.getTime()) 
			);
		}
		if( EventReceiver::Instance()->getKey( PHK_RIGHT ) ){ 
			system.getView().setPosition( 
				system.getView().getPosition() 
				+ ( Vector2d( 100.0f , 0.0f ) 
				* (float)timer.getTime() ) 
			);
		}
		if( EventReceiver::Instance()->getKey( PHK_UP ) ){
			system.getView().setPosition( 
				system.getView().getPosition() + 
				( Vector2d( 0.0f , -100.0f ) 
				* (float)timer.getTime() ) 
			);
		}
		if( EventReceiver::Instance()->getKey( PHK_DOWN ) ){
			system.getView().setPosition( 
				system.getView().getPosition() 
				+ ( Vector2d( 0.0f , 100.0f ) 
				* (float)timer.getTime() ) 
			);
		}

        /*!
            We reset the timer so we have an accurate measurement for the next frame.
        */
        timer.reset();
    }

    return 0;

}
예제 #2
0
int main()
{

    RenderSystem system;

    /*!
        Let's load up a texture to play with.
    */
    TexturePtr feather = system.loadTexture( std::string(PHOENIXCORE_DATA_DIR) + std::string("feather.png") );

    /*!
        let's make our group of geometry, with this
        we'll demonstrate grouping and group states.
        Grouped objects are drawn together and usually share
        some sort of state that's controlled by the group state
		object.

        The first thing we need to do is manipulate our factory:
        The RenderSystem. We can make it so that the next geometries
        that are made have specific properties. We'll set the group
        id and add the group state object.
    */
	system.getBatchRenderer().addGroupState( 1, GroupStatePtr( new AdditiveState() ) );
    system.getGraphicsFactory().setGroup( 1 );

    /*!
        Now we can draw some things, and they'll all
        be additively blended.
    */
    BatchGeometryPtr tgeom; // a temporary pointer for geometry.

    //! Here we just draw a basic scaled texture.
    tgeom = system.drawTexture( feather, Vector2d( 240,320 ), 0, Vector2d( 3.0f, 3.0f ) );
    tgeom->setImmediate( false );
    
    /*!
        Here we'll draw a rectangle centered on the origin, but we'll rotate and
        scale it then translate it to it's final position.
    */
    system.setDepth( 1.0f );
    tgeom = system.drawRectangle( Rectangle( -150,-150, 150,150 ) );
    tgeom->rotate( DegreesToRadians( 45.0f ) );
    tgeom->scale( Vector2d( 2.0f, 1.3f ) );
    tgeom->translate( Vector2d( 300, 400 ) );
    tgeom->colorize( Color( 127,200,255 ) );
    tgeom->setImmediate( false );

    /*!
        Lastly, we'll make some completely custom geometry. He'll we'll make
        a sort of circular geometry with a texture and custom tcoords

        We'll first use BatchGeometry's create function.
    */
    system.setDepth( 2.0f );
    tgeom = new BatchGeometry( system.getBatchRenderer(), GL_TRIANGLES, feather, system.getGraphicsFactory().getGroup(), system.getDepth() );
    tgeom->setImmediate( false );

    /*!
        Now we'll generate a simple circular peice of geometry. This is a 
        rather simple operation. You'll notice that we used  a different
        texture coordinate for the end, this creates a rather neat effect.
    */
    Vector2d center( 400, 200 );
    Vector2d ray( 250, 0 );
    for( int i = 0; i < 360; i+=10 )
    {
        tgeom->addVertex( Vertex( center, Color(), TextureCoords( 0.0f, 1.0f ) ) );
        tgeom->addVertex( Vertex( center + ( ray * RotationMatrix( DegreesToRadians( (float)i ) ) ), Color(), TextureCoords( 1.0f, 0.0f ) ) );
        tgeom->addVertex( Vertex( center + ( ray * RotationMatrix( DegreesToRadians( (float)i + 10.0f ) ) ), Color(), TextureCoords( 1.0f, 0.0f ) ) );
    }

    /*!
        Finally, we need to restore the properties we set. This is important
        if we draw any more geometry after this, because if we don't restore
        the properties all the rest of the geometry would have these properties
        too!
    */
    system.getGraphicsFactory().setDepth();
    system.getGraphicsFactory().setGroup();

    while( system.run() )
    {
        /*!
            Just for kicks, let make it where we can move the last geometry we
            created around with the arrow keys. This is easy achieved using
            translate.
        */
        if( EventReceiver::Instance()->getKeyPressed( PHK_UP ) ) tgeom->translate( Vector2d( 0.0f, -5.0f ) ); 
        if( EventReceiver::Instance()->getKeyPressed( PHK_DOWN ) ) tgeom->translate( Vector2d( 0.0f, 5.0f ) ); 
        if( EventReceiver::Instance()->getKeyPressed( PHK_RIGHT ) ) tgeom->translate( Vector2d( 5.0f, 0.0f ) ); 
        if( EventReceiver::Instance()->getKeyPressed( PHK_LEFT ) ) tgeom->translate( Vector2d( -5.0f, 0.0f ) ); 
    }
	
    return 0;

}
예제 #3
0
int main()
{

    RenderSystem system;

    /*!
        We need a resource manager to keep track of all of
        our resources. We could use the system's internal
        resource manager, but we'd have to check for types
        in that case, because it also stores all the textures
        and fonts.
    */
    ResourceManager examples;

    //! We'll also want to start its garbage collector.
    examples.start();

    /*!
        Now let's fill the resource manager with 10 resources.
    */
    for( int i = 0; i < 10; ++i )
    {
        new ExampleResource( examples );
    }

    while( system.run() )
    {

        /*!
            Now we'll iterate through each resource and call draw().
            Because garbage collection occurs in another thread, we
            must lock the resource manager before doing so.
        */
        examples.lock();

        /*!
            Now the iteration. The loop looks more complicated than it actually is. 
            It's just standard list iteration. sometimes it's more asthetically 
            pleasing to use this:
                BOOST_FOREACH( ResourcePtr& r, examples.getResourceList() )
            but for this example I wanted to show iterating without foreach.
        */
        for( std::list< ResourcePtr >::iterator i = examples.getList().begin(); i != examples.getList().end(); ++i )
        {
            /*!
                First, we make sure the resource hasn't been dropped. Usually it is
                still safe to use dropped resources, but it is undesirable to do so.
            */
            if( ! (*i)->dropped() )
            {
                /*!
                    Now we'll use Resource's templated grab<>() function to automatically
                    cast to an ExampleResource and then we'll call our draw function.
                */
                (*i)->grab<ExampleResource>()->draw( system );
            }
        }

        /*!
            Finally, we can unlock our resource manager and let the garbage collector
            work.
        */
        examples.unlock();

    }

    return 0;

}