Exemplo n.º 1
0
	void TestStage::onRender( float dFrame )
	{
		glDisable( GL_DEPTH_TEST );
		glDisable( GL_CULL_FACE );
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
		glEnable( GL_STENCIL_TEST );

		GameWindow& window = Global::getDrawEngine()->getWindow();
		int w = window.getWidth();
		int h = window.getHeight();

	
		for ( LightList::iterator iter = lights.begin(), itEnd = lights.end();
			  iter != itEnd ; ++iter )
		{
			Light& light = *iter;

#if 1
			glColorMask(false, false, false, false);
			glStencilFunc(GL_ALWAYS, 1, 1);
			glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

			for( BlockList::iterator iter = blocks.begin(), itEnd = blocks.end();
				 iter != itEnd ; ++iter )
			{
				Block& block = *iter;
				renderPolyShadow( light , block.pos , block.getVertices() , block.getVertexNum() );
			}
			
			glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
			glStencilFunc(GL_EQUAL, 0, 1);
			glColorMask(true, true, true, true);
#endif

			glEnable(GL_BLEND);
			glBlendFunc(GL_ONE, GL_ONE);

			glUseProgram(program);

			glUniform2f( loc_lightLocation , light.pos.x , light.pos.y );
			glUniform3f( loc_lightColor , light.color.x , light.color.y , light.color.z );
			glUniform3f( loc_lightAttenuation , 0 , 1 / 5.0 , 0 );

			glBegin( GL_QUADS );
			glVertex2i( 0 , 0 );
			glVertex2i( w , 0 );
			glVertex2i( w , h );
			glVertex2i( 0 , h );
			glEnd();

			glUseProgram(0);
			glDisable(GL_BLEND);
			glClear(GL_STENCIL_BUFFER_BIT);
		}

		glDisable( GL_STENCIL_TEST );


		GLGraphics2D& g = ::Global::getDrawEngine()->getGLGraphics();

		g.beginRender();

		RenderUtility::setFont( g , FONT_S8 );
		FixString< 256 > str;
		Vec2i pos = Vec2i( 10 , 10 );
		g.drawText( pos , str.format( "Lights Num = %u" , lights.size() ) );

		g.endRender();
	}
Exemplo n.º 2
0
void Game::run()
{
	using std::cout;
	using std::endl;

	int prevTime = Platform::getTickCount();
	int64 timeFrame = Platform::getTickCount();
	int frameCount = 0;

	IText* text = IText::create( mFonts[0] , 18 , Color(255,255,25) );

	static int const NUM_FPS_SAMPLES = 12;
	float fpsSamples[NUM_FPS_SAMPLES];
	int   NumFramePerSample = 10;
	std::fill_n( fpsSamples , NUM_FPS_SAMPLES , 60.0f );
	int  idxSample = 0;

	while( !mNeedEnd )
	{
		int64 curTime = Platform::getTickCount();
		float deltaT = ( curTime - prevTime ) / 1000.0f;
		prevTime = curTime;

		while ( mStageAdd )
		{
			if( mbRemovePrevStage )
			{
				mStageStack.back()->onExit();
				delete mStageStack.back();
				mStageStack.pop_back();
				cout << "Old stage deleted." << endl;
			}

			GameStage* stage = mStageAdd;
			mStageAdd = NULL;
			mStageStack.push_back( stage );
			cout << "Setup new state..." << endl;
			if ( !stage->onInit() )
			{
				cout << "Stage Can't Init !" << endl;
			}
			cout << "Stage Init !" << endl;
		}

		GameStage* stage = mStageStack.back();

		mSoundMgr->update( deltaT );
		stage->onUpdate( deltaT );

		if ( mRenderSystem->prevRender() )
		{
			stage->onRender();

			++frameCount;
			if ( frameCount > NumFramePerSample )
			{
				int64 temp = Platform::getTickCount();
				fpsSamples[idxSample] = 1000.0f * ( frameCount ) / (  temp - timeFrame );
				timeFrame = temp;
				frameCount = 0;

				++idxSample;
				if ( idxSample == NUM_FPS_SAMPLES )
					idxSample = 0;

				mFPS = 0;
				for (int i = 0; i < NUM_FPS_SAMPLES; i++)
					mFPS += fpsSamples[i];

				mFPS /= NUM_FPS_SAMPLES;
#if 0
				std::cout << "FPS =" << mFPS << std::endl;
#endif
			}

			FixString< 256 > str;
			str.format( "FPS = %f" , mFPS );
			text->setString( str.c_str() );

			mRenderSystem->drawText( text , 
				Vec2i( getGame()->getScreenSize().x - 100 , 10 ) , 
				TEXT_SIDE_LEFT | TEXT_SIDE_TOP );

			mRenderSystem->postRender();
		}

		if( stage->needStop() )
		{
			mStageStack.pop_back();
			stage->onExit();
			delete stage;
			cout << "Stage Exit !" << endl;
		}
		if( mStageStack.empty() )		
			mNeedEnd=true;
	}

	text->release();
}