Пример #1
0
int main( int argc, char **argv )
{
	// Tutorial 1: Initialize SDL and L3Init
	if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER ) < 0 )
	{
	    fprintf( stderr, "SDL initialization failed: %s\n", SDL_GetError( ) );
		exit( 1 );
	}
	
	SDL_Surface* surface = Lilith3D::SetSDLVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 0, false );
	GLASSERT( surface );
	SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
	InitLilith3D();

	// Tutorial 1: Textures and Models
	ResourcePool* resourcePool = new ResourcePool();
	resourcePool->SetImportPath( "../graphics/" );	
	resourcePool->LoadRequiredAssets();

	resourcePool->SetImportPath( "../grdemo/" );	

	// Tutorial 5: Decal texture
	resourcePool->LoadTexture( "impact.tga", "impact" );


	// Tutorial 1: Engine Initialization
	Lilith3D* lilith = new Lilith3D();
	Game* game = new Game( lilith );

	bool ignoreJump = false;
	// Tutorial 1: Event Loop
	bool done = false;
	while ( !done )
	{
	    SDL_Event event;
		while ( SDL_PollEvent( &event ) )
		{
			switch( event.type )
			{
				case SDL_KEYDOWN:
					if ( event.key.keysym.sym == SDLK_ESCAPE )
					{
						done = true;
					}
					else if ( event.key.keysym.sym == SDLK_TAB )
					{
						lilith->ScreenCapture( "tutorial" );
					}
					break;

				case SDL_QUIT:
					done = true;
					break;

				// Tutorial 2: Adjust the camera.
				case SDL_MOUSEBUTTONDOWN:
					{
						if ( event.button.button == SDL_BUTTON_RIGHT )
						{
							SDL_WM_GrabInput( SDL_GRAB_ON );
							SDL_ShowCursor( SDL_DISABLE );
							ignoreJump = true;
						}
						// What did the user click?
						else if ( event.button.button == SDL_BUTTON_LEFT )
						{
							// Extra check to make sure only the left button is pressed.
							if ( SDL_GetMouseState(0, 0) == SDL_BUTTON( SDL_BUTTON_LEFT ) )
							{
								LilithObjectList oList;
								lilith->IntersectRayFromScreen( event.button.x, 
																event.button.y, 
																TEST_TERRAIN,
																&oList );

								if ( !oList.empty() ) {
									game->Click( *oList.begin(), true );
								}
							}
						}
					}
					break;

				case SDL_MOUSEBUTTONUP:
					{
						if ( event.button.button == SDL_BUTTON_RIGHT )
						{
							SDL_WM_GrabInput( SDL_GRAB_OFF );
							SDL_ShowCursor( SDL_ENABLE );
						}
					}
					break;				

				case SDL_MOUSEMOTION:
					{
						if ( event.motion.state & SDL_BUTTON (SDL_BUTTON_RIGHT) )
						{	
							if ( !ignoreJump )
							{
								Camera* camera = lilith->GetCamera();
								float xVel = (float)event.motion.xrel * 5.0f;
								float yVel = (float)event.motion.yrel * 5.0f;
								camera->MoveCameraRotation( Camera::YAW, -xVel );
								camera->MoveCameraRotation( Camera::PITCH, yVel );
							}
							ignoreJump = false;
						}
					}
					break;

				default:
					break;
			}
		}

		// Tutorial 2: Incremental move
		if ( SDL_GetMouseState(0, 0) == (SDL_BUTTON( SDL_BUTTON_LEFT ) | SDL_BUTTON( SDL_BUTTON_RIGHT ) ) )
			lilith->GetCamera()->MoveCameraAxial3D( 20.0f );

		game->DoTick();

		lilith->BeginDraw();
		lilith->Draw();
		lilith->EndDraw();
		SDL_GL_SwapBuffers();
	}

	// Tutorial 1: Cleanup
	delete game;
	delete lilith;
	delete resourcePool;

    SDL_Quit();

    return( 0 );
}
Пример #2
0
int main( int argc, char **argv )
{
	// Tutorial 1: Initialize SDL and L3Init
	if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER ) < 0 )
	{
	    fprintf( stderr, "SDL initialization failed: %s\n", SDL_GetError( ) );
		exit( 1 );
	}
	
	SDL_Surface* surface = Lilith3D::SetSDLVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 0, false );
	GLASSERT( surface );
	SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
	InitLilith3D();

	// Tutorial 1: Textures and Models
	ResourcePool* resourcePool = new ResourcePool();
	resourcePool->SetImportPath( "../graphics/" );	
	resourcePool->LoadRequiredAssets();

	resourcePool->SetImportPath( "../grdemo/" );	



	// Tutorial 1: Engine Initialization
	Lilith3D* lilith = new Lilith3D();
	Game* game = new Game( lilith );

	// Tutorial 1: Event Loop
	bool done = false;
	while ( !done )
	{
	    SDL_Event event;
		while ( SDL_PollEvent( &event ) )
		{
			switch( event.type )
			{
				case SDL_KEYDOWN:
					if ( event.key.keysym.sym == SDLK_ESCAPE )
					{
						done = true;
					}
					else if ( event.key.keysym.sym == SDLK_TAB )
					{
						lilith->ScreenCapture( "tutorial" );
					}
					break;

				case SDL_QUIT:
					done = true;
					break;


				default:
					break;
			}
		}

		game->DoTick();

		lilith->BeginDraw();
		lilith->Draw();
		lilith->EndDraw();
		SDL_GL_SwapBuffers();
	}

	// Tutorial 1: Cleanup
	delete game;
	delete lilith;
	delete resourcePool;

    SDL_Quit();

    return( 0 );
}