예제 #1
0
파일: video.c 프로젝트: aaronjer/SPARToR
void setvideo(int w,int h,int go_full,int quiet)
{
  Uint32 flags = 0;
  if( !w || !h ) { //default to previous res
    w = prev_w;
    h = prev_h;
  }
  if( go_full && !v_fullscreen ) { // record previous res when changing to fullscreen
    prev_w = screen_w;
    prev_h = screen_h;
  }
  v_fullscreen = go_full;
  flags |= (go_full ? SDL_FULLSCREEN : SDL_RESIZABLE);
  screen = SDL_SetVideoMode(w,h,SDL_GetVideoInfo()->vfmt->BitsPerPixel,SDL_OPENGL|flags);
  if( !screen ){
    v_fullscreen = 0;
    screen = SDL_SetVideoMode(NATIVEW,NATIVEH,SDL_GetVideoInfo()->vfmt->BitsPerPixel,SDL_OPENGL|SDL_RESIZABLE);
    SJC_Write("Error changing video mode. Using safe defaults.");
    if( !screen ) {
      fprintf(stderr,"Fatal error setting video mode!");
      exit(-4);
    }
  }
  const SDL_VideoInfo *vidinfo = SDL_GetVideoInfo();
  screen_w = w = vidinfo->current_w;
  screen_h = h = vidinfo->current_h;
  scale = (h/NATIVEH < w/NATIVEW) ? h/NATIVEH : w/NATIVEW;
  if( scale<1 )
    scale = 1;
  SJF_Init();
  mod_setvideo(w,h);
  if( !quiet )
    SJC_Write("Video mode set to %d x %d",w,h);
}
예제 #2
0
int main( int argc, char* argv[] )
{
    SDL_Event event;
    Uint32 u;
    Uint32 v;
    int i;
    int w = W;
    int h = H;
    int multis = MULTIS;
    int threads = THREADS;
    int photons = PHOTONS;
    unsigned seed = (unsigned)-1;
    bool preview = true;

    NICEME;

    // Process cmd line args
    for(i=1; i<argc; i++)
    {
        if( argv[i][0]=='-' ) switch( argv[i][1] )
            {
            case 'w':
                w = atoi(argv[i]+2);
                break;
            case 'h':
                h = atoi(argv[i]+2);
                break;
            case 'm':
                multis = atoi(argv[i]+2);
                break;
            case 't':
                threads = atoi(argv[i]+2);
                break;
            case 'p':
                photons = atoi(argv[i]+2);
                break;
            case '-':
                printf( "Usage: [OPTION]... [SEED]\nRender ray-traced 3D images generated randomly with seed number SEED.\n\n  option default description\n  -wNUM  %7d Set image output width to NUM\n  -hNUM  %7d Set image output height to NUM\n  -mNUM  %7d Set multisampling level to NUM (level 2 recommended)\n  -tNUM  %7d Parallelize with NUM threads\n  -pNUM  %7d Simulate lighting with NUM million photons!\n",W,H,MULTIS,THREADS,PHOTONS ), exit(0);
            default:
                fprintf( stderr, "Halt! -%c isn't one of my options!\nUse --help for help.\n", argv[i][1] ), exit(-1);
            }
        else if( seed==(unsigned)-1 )
        {
            seed = atoi(argv[i]);
            if( !seed )
                fprintf( stderr, "Halt! SEED ought to be a positive number, not %s\n", argv[i] ), exit(-1);
        }
        else
            fprintf( stderr, "Halt! I'm confused by cmd line argument #%d: %s\n", i, argv[i] ), exit(-1);
    }
    if( w<1 ) w=W;
    if( h<1 ) h=H;
    if( multis<1 ) multis=MULTIS;
    if( threads<1 ) threads=THREADS;
    if( photons<1 ) photons=PHOTONS;

    // Use time as seed if not otherwise specified
    if( seed==(unsigned)-1 )
        seed = (unsigned)time(NULL);

    // Init SDL
    if( SDL_Init( SDL_INIT_TIMER|SDL_INIT_AUDIO|SDL_INIT_VIDEO ) < 0 || !SDL_GetVideoInfo() )
        return 0;

    // Create Window
    SetVideo( w, h );
    SDL_WM_SetCaption("PixelMachine", NULL);

    pinfo = SDL_GetVideoInfo();

    // font init
    SJF_Init(pinfo);

    //ui setup
    ui.init();
    h_menu = ui.new_control(0,0,0,0);
    h_render = ui.new_control(h_menu,80,15,SJUIF_EXTENDSV);
    ui.set_caption(h_menu,"Click to render...");
    ui.set_caption(h_render,"Loading");

    //pm preview render setup
    pixelmachine = new PIXELMACHINE;
    pixelmachine->init(seed,100,75,1,threads,(photons?1:0));
    thread = SDL_CreateThread(run_pixel_machine,NULL);

    // MAIN LOOP
    while( 1 )
    {
        while( SDL_PollEvent(&event) ) switch(event.type)
            {
            case SDL_VIDEOEXPOSE:
                ;
                break;
            case SDL_VIDEORESIZE:
                SetVideo( event.resize.w, event.resize.h );
                break;
            case SDL_MOUSEBUTTONDOWN:
                if( preview )
                {
                    //pm full render go!
                    preview = false;
                    pixelmachine->cancel = true;
                    SDL_WaitThread(thread,NULL); //BUG: thread may not be valid?
                    delete pixelmachine;
                    pixelmachine = new PIXELMACHINE;
                    pixelmachine->init(seed,w,h,multis,threads,photons);
                    thread = SDL_CreateThread(run_pixel_machine,NULL);
                }
                break;
            case SDL_KEYDOWN:
                ;
                break;
            case SDL_QUIT:
                pixelmachine->cancel = true;
                SDL_WaitThread(thread,NULL); //BUG: thread may not be valid?
                delete pixelmachine;
                Cleanup();
                break;
            }

        gutimenow = SDL_GetTicks();
        if( (Uint32)(gutimenow-gutime)>50 )
        {
            Render();
            gutime = gutimenow;
        }

        // chill out for a bit
        SDL_Delay(10);
    }

    return 0;
}