Ejemplo n.º 1
0
void snap_screenshot()
{
	char scrname[64];
	sprintf(scrname, "%s/screenshots/shot%03d.bmp", (settings.GetSettingsDir()).c_str(), settings.GetNumShots());
	Screenshot(scrname);
	settings.SetNumShots(settings.GetNumShots() + 1);
}
Ejemplo n.º 2
0
int main( int argc, char **argv )
{
    /* Flags to pass to SDL_SetVideoMode */
    int videoFlags;
    /* main loop variable */
    int done = FALSE;
    /* used to collect events */
    SDL_Event event;
    /* this holds some info about our display */
    const SDL_VideoInfo *videoInfo;
    /* whether or not the window is active */
    int isActive = TRUE;

	surface = NULL;
	
	//load error log
	error_log.open((settings.GetSettingsDir() + "/logs/main.log").c_str());
	
	//create trig lookups
	//CreateLookupTable();

	int i;
	for (i = 0; i < argc; i++)
	{
		if (strcmp(argv[i],"-verbose") == 0)
			verbose_output = true;
	}

	//set frame stats to zero
	Frames = 0;
	T0 = 0;
	fps = 0;
	frameno = 0;
	
	
	
    /* initialize SDL */
    if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0 )
	{
	    fprintf( stderr, "SDL initialization failed: %s\n",
		     SDL_GetError( ) );
	    Quit( 1 );
	}
	
	cout << "Run with -verbose for troubleshooting." << endl;
	
	/*SDL_Joystick *joystick;
	SDL_JoystickEventState(SDL_ENABLE);
	joystick = SDL_JoystickOpen(0);
	printf("Joystick 0 opened.\n\n");*/
	
	SDL_JoystickEventState(SDL_ENABLE);
	
	SDL_WM_SetCaption("VDrift - Track Editor", NULL);
	SDL_WM_SetIcon(IMG_Load(settings.GetFullDataPath("textures/small/icons/vdrift-32x32.png").c_str()), NULL);
	SDL_ShowCursor(SDL_DISABLE);

    /* Fetch the video info */
    videoInfo = SDL_GetVideoInfo( );

    if ( !videoInfo )
	{
	    fprintf( stderr, "Video query failed: %s\n",
		     SDL_GetError( ) );
	    Quit( 1 );
	}

    /* the flags to pass to SDL_SetVideoMode */
    videoFlags  = SDL_OPENGL;          /* Enable OpenGL in SDL */
    videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
    videoFlags |= SDL_HWPALETTE;       /* Store the palette in hardware */
    videoFlags |= SDL_RESIZABLE;       /* Enable window resizing */

    /* This checks to see if surfaces can be stored in memory */
    if ( videoInfo->hw_available )
	videoFlags |= SDL_HWSURFACE;
    else
	videoFlags |= SDL_SWSURFACE;

    /* This checks if hardware blits can be done */
    if ( videoInfo->blit_hw )
	videoFlags |= SDL_HWACCEL;

    /* Sets up OpenGL double buffering */
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
    
    //set up the depth buffer to be 24 bits, 16 bits are NOT enough
    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );

/*	ifstream vconf;
	vconf.open((settings.GetSettingsDir() + "/videoconfig").c_str());
	if (vconf)
	{
		vconf >> w;
		vconf >> h;
		vconf >> bpp;
		vconf >> fs;
		vconf.close();
	}
*/
	int w, h, bpp, fs;
	w = settings.GetDisplayX();
	h = settings.GetDisplayY();
	bpp = settings.GetDisplayDepth();
	fs = settings.GetFullscreenEnabled();
	
	if (SDL_VideoModeOK(w, h, bpp, videoFlags) != 0)
	{
		ChangeDisplay(w, h, bpp, fs, true);
	}
	else
	{
		surface = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,
					videoFlags );
	}
	
    /* Verify there is a surface */
    if ( !surface )
	{
	    fprintf( stderr,  "Video mode set failed: %s\n", SDL_GetError( ) );
	    Quit( 1 );
	}

    /* initialize OpenGL */
    initGL( );

    /* resize the initial window */
    resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT );

	if (!(isExtensionSupported("GL_ARB_multitexture")))
	{
		cout << "OpenGL extensions not present." << endl;
		Quit(0);
		return(0);
	}
	
	if (verbose_output)
	{
		#ifdef HAVE_OPENAL
		cout << "Using OpenAL for sound" << endl;
		#else
		cout << "Using FMOD for sound" << endl;
		#endif
	}

	// grab & hide mouse
    //SDL_WM_GrabInput(SDL_GRAB_ON);
    //if ( SDL_ShowCursor(SDL_DISABLE) != SDL_DISABLE )
      //cerr << SDL_GetError() << endl;

	timefactor = 1.0f;
	
    /* wait for events */
    while ( !done )
	{
	    /* handle the events in the queue */

	    while ( SDL_PollEvent( &event ) )
		{
//			float v;
			
		    switch( event.type )
			{
			case SDL_ACTIVEEVENT:
			    /* Something's happend with our focus
			     * If we lost focus or we are iconified, we
			     * shouldn't draw the screen
			     */
			    if ( event.active.gain == 0 )
				isActive = FALSE;
			    else
				isActive = TRUE;
			    break;			    
			case SDL_VIDEORESIZE:
			    /* handle resize event */
			    surface = SDL_SetVideoMode( event.resize.w,
							event.resize.h,
							16, videoFlags );
			    if ( !surface )
				{
				    fprintf( stderr, "Could not get a surface after resize: %s\n", SDL_GetError( ) );
				    Quit( 1 );
				}
			    resizeWindow( event.resize.w, event.resize.h );
			    break;
			case SDL_KEYDOWN:
			    /* handle key presses */
			    handleKeyPress( &event.key.keysym );
				keyman.KeyDown(event.key.keysym.sym);
			    break;
			case SDL_KEYUP:
				keyman.KeyUp(event.key.keysym.sym);
				break;
			case SDL_QUIT:
			    /* handle quit requests */
			    done = 1;
			    break;
			case SDL_JOYBUTTONDOWN:
				break;
			case SDL_JOYAXISMOTION:
				break;
			default:
			    break;
			}
		}

	    /* do the game logic & draw the screen*/
	    //if ( isActive )
		{
			Update();
			drawGLScene( );
		}
	}
	
    /* clean ourselves up and exit */
    Quit( 0 );

    /* Should never get here */
    return( 0 );
}