Example #1
0
int main( int argc, char* args[] ) {

    SDLInitializer sdlinit("Zelda",1480,850);
    //A sleepy rendering loop, wait for 3 seconds and render and present the screen each time
    bool quit=false;
    SDL_Event event;
    const Uint8* keys = SDL_GetKeyboardState(NULL);

    character_link link(sdlinit);

    while( !quit){
        //The frames per second timer

        SDL_PollEvent(&event);
        //First clear the renderer
        SDL_RenderClear(sdlinit.getRenderer());
        link.draw(keys);
        //Update the screen
        SDL_RenderPresent(sdlinit.getRenderer());

        SDL_Delay(time_left());
        next_time += TICK_INTERVAL;

        if(keys[SDL_SCANCODE_ESCAPE])
            return 0;

    }



}
Example #2
0
int main(int argc, char **argv) {

	int		r;

	__sdl_videoinit();
	if (sdlinit() != SUCCESS) {
		return(0);
	}
	r = SDL_main(argc, argv);
	sdlterm();
	return(r);
}
Example #3
0
void GW_PlatformSDL::initialize()
{
    if (!initialized_)
    {
        GWDBG_OUTPUT("SDL: Initialize");

        // initialize SDL video
        if ( SDL_Init( sdlinit(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER) ) < 0 )
            throw GW_Exception(string("Unable to init SDL: "+string(SDL_GetError())));

#ifndef GW_NO_SDL_MIXER
        if ( Mix_OpenAudio(22050, AUDIO_S16SYS, 1, audiobufsize_get()) < 0)
            throw GW_Exception(string("Unable to init SDL_mixer: "+string(Mix_GetError())));
#endif

#ifndef GW_NO_SDL_TTF
        if ( TTF_Init() < 0 )
            throw GW_Exception(string("Unable to init SDL_ttf: "+string(TTF_GetError())));
#endif

#ifndef GW_NO_SDL_MIXER
        Mix_AllocateChannels(6);
        sound_volume(75);
#endif

        custom_initialize();

        // make sure SDL cleans up before exit
        atexit(SDL_Quit);

        // set application icon
        plat_init();

        // create a new window
        window_ = SDL_CreateWindow("Game & Watch simulator - by Hitnrun / ZsoltK & Madrigal",
                                   SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                   width_, height_,
                                   fullscreen_ ?  SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_SHOWN);
        if ( !window_ )
            throw GW_Exception(string("Unable to allocate game window: " + string(SDL_GetError())));

        renderer_ = SDL_CreateRenderer(window_, -1, SDL_RENDERER_ACCELERATED);
        if ( !renderer_ )
            throw GW_Exception(string("Unable to allocate renderer: " + string(SDL_GetError())));


        // Let SDL & GPU do the scaling
        SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
        SDL_RenderSetLogicalSize(renderer_, width_, height_);

        SDL_ShowCursor(SDL_DISABLE);

#ifndef GW_NO_SDL_TTF
        // load font
        //font_=TTF_OpenFont( bf::path( bf::path(platformdata_get() ) / "andalemo.ttf" ).string().c_str(), fontsize_get() );
        string pfont(platformdata_get() + "/" + "andalemo.ttf" );
        font_=TTF_OpenFont( pfont.c_str(), fontsize_get() );
        if (!font_)
            throw GW_Exception(string("Unable to load font: "+string(TTF_GetError())));
#endif

        initialized_=true;
    }
}