示例#1
0
文件: sdl_window.cpp 项目: foo/ii
bool window::setup(const int width_param, const int height_param)
{
  width = width_param;
  height = height_param;
  
  if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    std::cout << "Couldn't initialize SDL: "
	      << SDL_GetError() << std::endl;
    return false;
  }
  atexit(SDL_Quit);

  video = SDL_GetVideoInfo();
  if(video == NULL) {
    std::cout << "Couldn't get video information: "
	      << SDL_GetError() << std::endl;
    return false;
  }

  SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
  SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
  SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
  SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
  SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

  if(SDL_SetVideoMode(width, height, get_bits_per_pixel(), SDL_OPENGL | SDL_RESIZABLE) == 0) {
    std::cout << "Couldn't set video mode: "
	 << SDL_GetError() << std::endl;
    return false;
  }

  setup_opengl(width, height);

  return true;
}
示例#2
0
文件: o6.c 项目: manish05/TCR
/* Program entry point */
int main (int argc, char* argv[]) {
   debug=fopen("debug.txt","w");

    // window dimensions
    int width  = 640;
    int height = 480;
    const SDL_VideoInfo *info;

    /* initialize SDL's video subsystem */
    if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
        fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError( ) );
        return -1;
    }

    /* retrieve video information */
    info = SDL_GetVideoInfo( );
    if (!info) {
        fprintf( stderr, "Video query failed: %s\n", SDL_GetError( ) );
        return -1;
    }

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE,   8 ); /* min 8bit red */
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8 ); /* min 8bit green */
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,  8 ); /* min 8bit blue */
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); /* 16bit depth buffer */
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); /* require double buffering */

    /* Set video mode */
    SDL_Surface * surface = SDL_SetVideoMode(width, height, info->vfmt->BitsPerPixel, SDL_OPENGL);
    if (!surface) {
        fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) );
        return -1;
    }

    /* OpenGL initialization */
    setup_opengl(width, height);

    init();
    lys();
    tekstur();

    /* main event loop */
    while (running) {
      animer();
        /* Process incoming events */
        process_events();
        /* Draw the screen */
        draw_scene();

      sprett();
        SDL_Delay(1000/500); /* limit to 5fps */
    }

    SDL_Quit(); /* unload SDL */
    fclose(debug);
    return 0;
}
示例#3
0
文件: main.c 项目: johncausey/game
int main(int argc, char ** argv) {

	// Setup environment
	setup_sdl();
	setup_opengl();

	// Run main game loop
	main_loop();

	return 0;
}
示例#4
0
static void context_notification_handler(int notification, void *data) {
    if (notification == FS_GL_CONTEXT_DESTROY) {
        if (g_frame_texture != 0) {
            glDeleteTextures(1, &g_frame_texture);
            CHECK_GL_ERROR();
            g_frame_texture = 0;
        }
    }
    else if (notification == FS_GL_CONTEXT_CREATE) {
        setup_opengl();
    }
}
示例#5
0
void VoxelEditor::initializeGL()
{
    setup_opengl();

    model = voxel->get_model();
    glEnable(GL_LIGHTING);
    glDisable(GL_TEXTURE_2D);
    glEnable(GL_CULL_FACE);
    glClearColor(0.2f, 0.2f, 0.2f, 1.0f);

    pos = vec3(0.0f, 0.0f, 0.0f);
}
示例#6
0
文件: window.hpp 项目: matt-42/dige
  window::window(const std::string& title, unsigned width, unsigned height)
    : loopthread_(0)
  {
    if (!xlib_thread_initialized_)
    {
      XInitThreads(); // FIXME: SHOULD BE DONE IN SFML!!!
      xlib_thread_initialized_ = true;
    }

    currentWindow_ = new sf::Window(sf::VideoMode(width, height), title);
    currentWindow_->SetActive(true);
    currentWindow_->SetFramerateLimit(0);
    setup_opengl();
    loopthread_ = new EventLoopThread(*this);
    loopthread_->Launch();
  }
示例#7
0
//might want to have some parms, options for user
int InitVideo() {
  // Load SDL
  if (SDL_Init(SDL_INIT_VIDEO) != 0) {
    fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
    return false;
  }
  atexit(SDL_Quit); // Clean it up nicely :)

  //To use OpenGL, you need to get some information first,
  const SDL_VideoInfo *info = SDL_GetVideoInfo();
  if(!info) {
    /* This should never happen, if it does PANIC! */
    fprintf(stderr, "Video query failed: %s\n", SDL_GetError());
    return false;
  }
  int bpp = info->vfmt->BitsPerPixel;

  // set bits for red: (5 = 5bits for red channel)
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
  // set bits for green:
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
  // set bits for blue:
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
  // colour depth:
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
  // You want it double buffered?
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, true);

  //screen is no longer used, as openGL does all the drawing now!
  if (SDL_SetVideoMode(screen_width, screen_height, bpp, SDL_OPENGL | SDL_SWSURFACE) == 0) {
    fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError());
    return false;
  }

  //Made everything, Now we need to change opengl settings..
  return setup_opengl(screen_width, screen_height);
}
示例#8
0
ENTRYPOINT void init_jigglypuff(ModeInfo *mi)
{
    jigglystruct *js;
    int subdivs;

    if(!jss) {
        jss = (jigglystruct*)
              calloc(MI_NUM_SCREENS(mi), sizeof(jigglystruct));
        if(!jss) {
            fprintf(stderr, "%s: No..memory...must...abort..\n", progname);
            exit(1);
        }
    }

    js = &jss[MI_SCREEN(mi)];

    js->do_wireframe = MI_IS_WIREFRAME(mi);
# ifdef HAVE_JWZGLES
    js->do_wireframe = 0; /* GL_LINE unimplemented */
# endif

    js->shininess = shininess;

    subdivs = (complexity==1) ? 4 : (complexity==2) ? 5
              : (complexity==3) ? 6 : 5;

    js->spooky = spooky << (subdivs-3);

    if(!parse_color(js)) {
        fprintf(stderr, "%s: Bad color specification: '%s'.\n", progname, color);
        exit(-1);
    }

    if(random_parms)
        randomize_parameters(js);

    js->angle = frand(180);
    js->axis  = frand(M_PI);

    js->shape = tesselated_tetrahedron(1, subdivs, js);

    if(!do_tetrahedron)
        solid_spherify(js->shape, 1);

    if(js->color_style == COLOR_STYLE_CLOWNBARF)
        clownbarf_colorize(js->shape);

    calculate_parameters(js, subdivs);

    if((js->glx_context = init_GL(mi)) != NULL) {
        glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(js->glx_context));
        setup_opengl(mi, js);
        reshape_jigglypuff(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
    }
    else {
        MI_CLEARWINDOW(mi);
    }
    js->trackball = gltrackball_init();
    /*    _DEBUG("distance : %f\nhold : %f\nspherify : %f\ndamping : %f\ndfact : %f\n",
    	   js->stable_distance, js->hold_strength, js->spherify_strength,
    	   js->damping_velocity, js->damping_factor);
        _DEBUG("wire : %d\nspooky : %d\nstyle : %d\nshininess : %d\n",
    	   js->do_wireframe, js->spooky, js->color_style, js->shininess);*/
}
示例#9
0
/*****************************************************************************
 * Thread:
 *****************************************************************************/
static void Thread( vlc_object_t *p_this )
{
    galaktos_thread_t *p_thread = (galaktos_thread_t*)p_this;

    int count=0;
    double realfps=0,fpsstart=0;
    int timed=0;
    int timestart=0;
    int mspf=0;

    /* Get on OpenGL provider */
    p_thread->p_opengl =
        (vout_thread_t *)vlc_object_create( p_this, VLC_OBJECT_OPENGL );
    if( p_thread->p_opengl == NULL )
    {
        msg_Err( p_thread, "out of memory" );
        return;
    }
    vlc_object_attach( p_thread->p_opengl, p_this );

    /* Initialize vout parameters */
    vout_InitFormat( &p_thread->p_opengl->fmt_in,
                     VLC_FOURCC('R','V','3','2'),
                     p_thread->i_width, p_thread->i_height, 1 );
    p_thread->p_opengl->i_window_width = p_thread->i_width;
    p_thread->p_opengl->i_window_height = p_thread->i_height;
    p_thread->p_opengl->render.i_width = p_thread->i_width;
    p_thread->p_opengl->render.i_height = p_thread->i_width;
    p_thread->p_opengl->render.i_aspect = VOUT_ASPECT_FACTOR;
    p_thread->p_opengl->b_scale = VLC_TRUE;
    p_thread->p_opengl->b_fullscreen = VLC_FALSE;
    p_thread->p_opengl->i_alignment = 0;
    p_thread->p_opengl->fmt_in.i_sar_num = 1;
    p_thread->p_opengl->fmt_in.i_sar_den = 1;
    p_thread->p_opengl->fmt_render = p_thread->p_opengl->fmt_in;

    p_thread->p_module =
        module_Need( p_thread->p_opengl, "opengl provider", NULL, 0 );
    if( p_thread->p_module == NULL )
    {
        msg_Err( p_thread, "unable to initialize OpenGL" );
        vlc_object_detach( p_thread->p_opengl );
        vlc_object_destroy( p_thread->p_opengl );
        return;
    }

    p_thread->p_opengl->pf_init( p_thread->p_opengl );

    setup_opengl( p_thread->i_width, p_thread->i_height );
    CreateRenderTarget(512, &RenderTargetTextureID, NULL);

    timestart=mdate()/1000;

    while( !p_thread->b_die )
    {
        mspf = 1000 / 60;
        if( galaktos_update( p_thread ) == 1 )
        {
            p_thread->b_die = 1;
        }
        if( p_thread->psz_title )
        {
            free( p_thread->psz_title );
            p_thread->psz_title = NULL;
        }

        if (++count%100==0)
        {
            realfps=100/((mdate()/1000-fpsstart)/1000);
 //           printf("%f\n",realfps);
            fpsstart=mdate()/1000;
        }
        //framerate limiter
        timed=mspf-(mdate()/1000-timestart);
      //   printf("%d,%d\n",time,mspf);
        if (timed>0) msleep(1000*timed);
    //     printf("Limiter %d\n",(mdate()/1000-timestart));
        timestart=mdate()/1000;
    }

    /* Free the openGL provider */
    module_Unneed( p_thread->p_opengl, p_thread->p_module );
    vlc_object_detach( p_thread->p_opengl );
    vlc_object_destroy( p_thread->p_opengl );
}
示例#10
0
文件: least.c 项目: meridion/least
int main (int argc, char **argv) {
    fz_context *context;
    int *pageinfo = NULL;
    /* int i; */

    /* Initialises mutexes required for Fitz locking */
    init_least_context_locks();

    context = fz_new_context(NULL, &least_context_locks, FZ_STORE_DEFAULT);
    if (!context)
        fprintf(stderr, "Failed to create context\n");

    if (force_thread_count)
        thread_count = force_thread_count;
    else
        thread_count = sysconf(_SC_NPROCESSORS_ONLN);

    if (argc == 2) {
        /* Initialize OpenGL window */
        setup_sdl();

        /* Start render threads */
        init_threads(thread_count, context);

        /*
         * At this point, we should have a properly setup
         * double-buffered window for use with OpenGL.
         */
        setup_opengl(w, h);
        init_busy_texture();

        /* Check for non-power-of-two support */
        /* printf("Extensions are: %s\n", glGetString(GL_EXTENSIONS)); */
        if (strstr((const char *)glGetString(GL_EXTENSIONS),
            "GL_ARB_texture_non_power_of_two")) {
            puts("Machine supports NPOT textures.");
            power_of_two = 0;
        } else {
            puts("Machine supports POT textures only.");
            power_of_two = 1;
        }

        power_of_two |= force_power_of_two;

        /* Load textures from PDF file */
        open_pdf(context, argv[1]);

        /*
         * Now we want to begin our normal app process--
         * an event loop with a lot of redrawing.
         */

        while (1) {
            /* Process incoming events. */
            process_events();

            /* Update cache state */
            update_cache();

            if (redraw) {
                /*
                glDeleteTextures(pagec, pages);
                open_pdf(context, argv[1]);
                */
                redraw = 0;
                draw_screen();
            }

            /*
            pageinfo = NULL;
            for(i = 0; i < visible_pages(pageinfo); i++) {
                printf("%d, ", i);
            }
            printf("\n");
            */

            free(pageinfo);
        }


    }


    fz_close_document(doc);
    fz_free_context(context);

    return 0;
}
示例#11
0
int main( int argc, char* argv[] )
{
  //Initialisieren
    ZWattribute=ZWgetattribute();
    load_options();
    ZWinitparameter();
    ZWattribute->strech=stretched;
    if (fullscreen)
    {
      ZWattribute->width=resolutionx;
      ZWattribute->height=resolutiony;
      ZWattribute->sdlflags|=SDL_FULLSCREEN;
    }
    else
    {
      ZWattribute->width=windowx;
      ZWattribute->height=windowy;
    }
    ZWattribute->quit_function=quit_function;
    ZWattribute->initflags|=SDL_INIT_AUDIO;
		
		load_mapping();
		
    ZWinitsdl();
    
    int audio_rate = 44100;
    Uint16 audio_format = AUDIO_S16SYS; 
    int audio_channels = 2;
    int audio_buffers = 2048;
    if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers))
    {
      printf("Unable to open audio!\n");
      exit(1);
   }
    
    if ((ZWattribute->sdlflags & SDL_FULLSCREEN)==0) //SDL_FULLSCREEN nicht mehr gesetzt? AAAAHHHH!
    {
      fullscreen=0;
      windowx=ZWattribute->width;
      windowy=ZWattribute->height;
      resolutionx=ZWattribute->resolution[0].x;
      resolutiony=ZWattribute->resolution[0].y;
    }
    ZWinitopengl();    
    setup_opengl();
    glHint(GL_POLYGON_SMOOTH_HINT,GL_FASTEST);
    init_var();
        
  //Level laden
    if (argc<2)
    {
      printf("Not enough arguments\n");
      printf("testboard file.opxml [player]\n");
      ZWquitfont();
      ZWquitsdl();      
      return 1;
    }
    if (loadlevel(argv[1])==1)
    {
      printf("File %s not found\n",argv[1]);
      ZWquitfont();
      ZWquitsdl();   
      return 1;
    }  
    refreshsetlist();

  //Minispielliste laden
	  load_minigames();
		save_minigames();

  /*//zu Debugzwecken Set 0 bis 60 ausgeben:
  for (int a=0;a<61;a++)
  {
    if (setbynr[a]==NULL)
      printf("Set %i: NULL\n",a);
    else
      printf("Set %i: \"%s\"\n",a,setbynr[a]->type);  
  }*/

  //Debug
    if (argc>3 && argv[3][0]=='c')
      all_are_cpu=1;

  //Spielvorbereitungen
    if (argc>2)
      playernum=atoi(argv[2]);
    playernum=(playernum-1)%8+1;

		
		if (argc>3 && argv[3][1]=='2')
		{
			playernum=((playernum+1)/2)*2;
			if (playernum<4)
			  playernum=4;
			teamsize=2;
		}
		if (argc>3 && argv[3][1]=='3')
		{
			playernum=6;
			teamsize=3;
		}
		if (argc>3 && argv[3][1]=='4')
		{
			playernum=8;
			teamsize=4;
		}		

    pset startset=getsetbyname((char*)"start");
    if (startset==NULL) startset=firstset;
		prepare_game(startset,1);
		
    
  ZWreset_virtuell_joytick();
  //Controller festlegen:
  for (int a=0;a<playernum;a++)
  {
		if (all_are_cpu)
		  maindata.player[a].joystick_nr=-1;
		else		  
		  maindata.player[a].joystick_nr=a%ZWattribute->realjoystickcount;
  }
	calib_all_controllers();
  //Spiel starten
    Mix_FadeInMusic(backgroundmusic, -1,FADE_IN_TIME);
    ZWattribute->newticks=SDL_GetTicks();
    ZWschleifeex((void(*)(void*))draw_main,(int(*)(void*))calc_main_thread,(int(*)(void*))calc_main,
                 (void*)(&maindata),sizeof(tmaindata));    
    Mix_HaltMusic();
  //alles wieder freigeben
    reset_after_game();
    del_objects();
    del_sounds();
    Mix_CloseAudio();
    ZWquitfont();
    ZWquitsdl();
  return 0;
}
示例#12
0
int main (int argc, char* argv[]) {
    /* Current video settings. */
    const SDL_VideoInfo* info = NULL;
    int width = 0;
    int height = 0;
    int bpp = 0;
    int flags = 0;

    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        fprintf(stderr, "Video initialization failed: %s\n",
                SDL_GetError());
        quit(1);
    }
    info = SDL_GetVideoInfo();
    if (!info) {
        fprintf(stderr, "Video query failed: %s\n",
                SDL_GetError());
        quit(1);
    }
    width = 640;//1366;
    height = 480;//768;
    bpp = info->vfmt->BitsPerPixel;

    /* We want *at least* 5 bits of red, green
     * and blue. We also want at least a 16-bit
     * depth buffer.
     *
     * The last thing we do is request a double
     * buffered window. '1' turns on double
     * buffering, '0' turns it off.
     */
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    /* EXERCISE:
     * Handle the resize events properly with
     * glViewport.
     */
    flags = SDL_OPENGL | SDL_SWSURFACE;
    //flags = SDL_OPENGL | SDL_FULLSCREEN;

    if (SDL_SetVideoMode(width, height, bpp, flags) == 0) {
        /* 
         * This could happen for a variety of reasons,
         * including DISPLAY not being set, the specified
         * resolution not being available, etc.
         */
        fprintf (stderr, "Video mode set failed: %s\n",
                SDL_GetError());
        quit(1);
    }

    setup_opengl(width, height);
    
    /* Event loop. */
    int time;
    while(1) {
        time = SDL_GetTicks();
        process_events();
        draw_screen();
        printf("\r%.2f FPS  ", 1000.0 / (SDL_GetTicks() - time));
        if (time % 8 == 1) {
            fflush(stdout);
        }
    }

    /*
     * EXERCISE:
     * Record timings using SDL_GetTicks() and
     * and print out frames per second at program
     * end.
     */

    return 0;
}
示例#13
0
int main( int argc, char* argv[] ) {
    bool fullscreen = false;
    char* world = "world";
    for (int i=0; i<argc; i++) {
        if (strcmp(argv[i], "-win") == 0) fullscreen = false;
        if (strcmp(argv[i], "-f") == 0) fullscreen = true;
        if (strcmp(argv[i], "-w") == 0)
            world = argv[i+1];
        if (strcmp(argv[i], "-d") == 0) debug = true;
    }
    SetupWorld(world);
    you_x = getWorldX();
    you_z = getWorldZ();
    you_angle = getWorldAngle();

    const SDL_VideoInfo* info = NULL;
    int width = 0;
    int height = 0;
    int bpp = 0;
    int flags = 0;
    
    if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
        fprintf( stderr, "Video initialization failed: %s\n",
             SDL_GetError( ) );
        quit_app( 1 );
    }

    info = SDL_GetVideoInfo( );
    if( !info ) {
        fprintf( stderr, "Video query failed: %s\n",
             SDL_GetError( ) );
        quit_app( 1 );
    }

    width = 640;
    height = 480;
    bpp = info->vfmt->BitsPerPixel;

    SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
    flags = SDL_OPENGL;
    if (fullscreen)
        flags |= SDL_FULLSCREEN;
    if( SDL_SetVideoMode( width, height, bpp, flags ) == 0 ) {
        fprintf( stderr, "Video mode set failed: %s\n",
             SDL_GetError( ) );
        quit_app( 1 );
    }

    setup_opengl( width, height );
    bool init = true;
    while( 1 ) {
        process_events( );
        draw_screen( );
        if (init) { glEnable( GL_LIGHTING ); init=false; }
    }
    
    return 0;
}
示例#14
0
int main( int argc, char* argv[] )
{
    /* Information about the current video settings. */
    const SDL_VideoInfo* info = NULL;

    g_Time = InitTime();

    /* First, initialize SDL's video subsystem. */
    if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
        /* Failed, exit. */
        fprintf( stderr, "Video initialization failed: %s\n",
             SDL_GetError( ) );
        quit_tutorial( 1 );
    }

    /* Let's get some video information. */
    info = SDL_GetVideoInfo( );

    if( !info ) {
        /* This should probably never happen. */
        fprintf( stderr, "Video query failed: %s\n",
             SDL_GetError( ) );
        quit_tutorial( 1 );
    }

    g_bpp = info->vfmt->BitsPerPixel;

    SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
    SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
    SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
	SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8);
    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

	g_flags = SDL_OPENGL|SDL_HWPALETTE|/*SDL_NOFRAME|*/SDL_HWSURFACE/*|SDL_RESIZABLE*//*| SDL_FULLSCREEN*/;

    /*
     * Set the video mode
     */
    if( SDL_SetVideoMode( g_width, g_height, g_bpp, g_flags ) == 0 ) {
        /* 
         * This could happen for a variety of reasons,
         * including DISPLAY not being set, the specified
         * resolution not being available, etc.
         */
        fprintf( stderr, "Video mode set failed: %s\n",
             SDL_GetError( ) );
        quit_tutorial( 1 );
    }

    /*
     * At this point, we should have a properly setup
     * double-buffered window for use with OpenGL.
     */
    setup_opengl( g_width, g_height );


    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        
        /* Problem: glewInit failed, something is seriously wrong. */
        fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
        quit_tutorial(1);
    }

    fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
    if (!GLEW_ARB_vertex_program || !GLEW_ARB_vertex_program)
    {
        fprintf(stderr, "No shader program support\n");
        quit_tutorial(1);
    }

    if (glewIsSupported("GL_VERSION_2_0"))
        printf("Ready for OpenGL 2.0\n");
    else {
        printf("OpenGL 2.0 not supported\n");
        quit_tutorial(1);
    }

	/*
	 * Init OpenGL text driver which will 
	 * be used by GraphicsConsole
	 */
	g_pTextDriver = new OGLTextDriver();
	if( false == g_pTextDriver->init("FixedWidth.bmp", 8, 16, 16, g_width, g_height))
		quit_tutorial( 1 );


	register_commands();
	GraphicsConsole::Instance().setTextDriver(g_pTextDriver);
	SDL_EnableKeyRepeat(500, 30);

	draw_velocity = glsl_program::makeProgram("drawVelocity", DATA_PATH"quad.vs", DATA_PATH"draw_velocity.fs");
	draw_fluids = glsl_program::makeProgram("drawFluids", DATA_PATH"quad.vs", DATA_PATH"draw_fluids.fs");
	assert(draw_velocity);

	start_time = time(0);

	g_fluids.createShaders();
	g_fluids.createBuffers();
	
	UI::Init(g_width, g_height);
	g_fluids.createUI();

	SDL_WM_SetCaption("console", 0);

    /*
     * Now we want to begin our normal app process--
     * an event loop with a lot of redrawing.
     */
    while( !g_exit ) {
        UpdateTime(&g_Time);
        /* Process incoming events. */
        process_events( );
        /* Draw the screen. */
        draw_screen( );
    }

	quit_tutorial(0);

    return 0;
}
示例#15
0
文件: main_sdl.cpp 项目: alariq/dev
int main( int argc, char* argv[] )
{
    /* Information about the current video settings. */
    const SDL_VideoInfo* info = NULL;


    /* First, initialize SDL's video subsystem. */
    if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
        /* Failed, exit. */
        fprintf( stderr, "Video initialization failed: %s\n",
             SDL_GetError( ) );
        quit_tutorial( 1 );
    }

    /* Let's get some video information. */
    info = SDL_GetVideoInfo( );

    if( !info ) {
        /* This should probably never happen. */
        fprintf( stderr, "Video query failed: %s\n",
             SDL_GetError( ) );
        quit_tutorial( 1 );
    }

    g_bpp = info->vfmt->BitsPerPixel;

    SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
    SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
    SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
	SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8);
    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

	g_flags = SDL_OPENGL|SDL_HWPALETTE|/*SDL_NOFRAME|*/SDL_HWSURFACE/*|SDL_RESIZABLE*//*| SDL_FULLSCREEN*/;

    /*
     * Set the video mode
     */
    if( SDL_SetVideoMode( g_width, g_height, g_bpp, g_flags ) == 0 ) {
        /* 
         * This could happen for a variety of reasons,
         * including DISPLAY not being set, the specified
         * resolution not being available, etc.
         */
        fprintf( stderr, "Video mode set failed: %s\n",
             SDL_GetError( ) );
        quit_tutorial( 1 );
    }

    /*
     * At this point, we should have a properly setup
     * double-buffered window for use with OpenGL.
     */
    setup_opengl( g_width, g_height );

	/*
	 * Init OpenGL text driver which will 
	 * be used by GraphicsConsole
	 */
	g_pTextDriver = new OGLTextDriver();
	if( false == g_pTextDriver->init("FixedWidth.bmp", 8, 16, 16, g_width, g_height))
		quit_tutorial( 1 );


	register_commands();
	GraphicsConsole::Instance().setTextDriver(g_pTextDriver);
	SDL_EnableKeyRepeat(500, 30);

	SDL_WM_SetCaption("console", 0);

    /*
     * Now we want to begin our normal app process--
     * an event loop with a lot of redrawing.
     */
    while( !g_exit ) {
        /* Process incoming events. */
        process_events( );
        /* Draw the screen. */
        draw_screen( );
    }

	quit_tutorial(0);

    /*
     * EXERCISE:
     * Record timings using SDL_GetTicks() and
     * and print out frames per second at program
     * end.
     */

    /* Never reached. */
    return 0;
}
示例#16
0
void fs_emu_initialize_opengl() {
    setup_opengl();
    fs_emu_initialize_textures();
    fs_gl_add_context_notification(context_notification_handler, NULL);
}
示例#17
0
文件: main.cpp 项目: rsaxvc/vertifall
int main()
{
    /* Information about the current video settings. */
    const SDL_VideoInfo* info = NULL;
    /* Color depth in bits of our window. */
    int bpp = 0;
    /* Flags we will pass into SDL_SetVideoMode. */
    int flags = 0;

    /* First, initialize SDL's video subsystem. */
    if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
        /* Failed, exit. */
        fprintf( stderr, "Video initialization failed: %s\n",
             SDL_GetError( ) );
        quit_tutorial( 1 );
    }

    SDL_ShowCursor( false );

    /* Let's get some video information. */
    info = SDL_GetVideoInfo( );

    if( !info ) {
        /* This should probably never happen. */
        fprintf( stderr, "Video query failed: %s\n",
             SDL_GetError( ) );
        quit_tutorial( 1 );
    }

    /*
     * Set our width/height to 640/480 (you would
     * of course let the user decide this in a normal
     * app). We get the bpp we will request from
     * the display. On X11, VidMode can't change
     * resolution, so this is probably being overly
     * safe. Under Win32, ChangeDisplaySettings
     * can change the bpp.
     */
    width = 1200;
    height = 650;
//    width = 1280;
//    height = 768;
    bpp = info->vfmt->BitsPerPixel;

    /*
     * Now, we want to setup our requested
     * window attributes for our OpenGL window.
     * We want *at least* 5 bits of red, green
     * and blue. We also want at least a 16-bit
     * depth buffer.
     *
     * The last thing we do is request a double
     * buffered window. '1' turns on double
     * buffering, '0' turns it off.
     *
     * Note that we do not use SDL_DOUBLEBUF in
     * the flags to SDL_SetVideoMode. That does
     * not affect the GL attribute state, only
     * the standard 2D blitting setup.
     */
//    SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
//    SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
//    SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
//    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );

    SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6 );
    SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );

    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

    /*
     * We want to request that SDL provide us
     * with an OpenGL window, in a fullscreen
     * video mode.
     *
     * EXERCISE:
     * Make starting windowed an option, and
     * handle the resize events properly with
     * glViewport.
     */
    flags = SDL_OPENGL | SDL_FULLSCREEN;
//    flags = SDL_OPENGL;

    /*
     * Set the video mode
     */
    if( SDL_SetVideoMode( width, height, bpp, flags ) == 0 ) {
        /* 
         * This could happen for a variety of reasons,
         * including DISPLAY not being set, the specified
         * resolution not being available, etc.
         */
        fprintf( stderr, "Video mode set failed: %s\n",
             SDL_GetError( ) );
        quit_tutorial( 1 );
    }

    /*
     * At this point, we should have a properly setup
     * double-buffered window for use with OpenGL.
     */
    setup_opengl( width, height );

    /*
     * Now we want to begin our normal app process--
     * an event loop with a lot of redrawing.
     */
    while( 1 ) {
        process_events();//Process incoming events.
        draw_screen();//Draw the screen.
    }

    /*
     * EXERCISE:
     * Record timings using SDL_GetTicks() and
     * and print out frames per second at program
     * end.
     */

    /* Never reached. */
    return 0;
}
示例#18
0
int main( int argc, char* argv[] )
{
    OBJSC model;
    load_objsc("./Models/Dress.objsc", &model);

    /* Information about the current video settings. */
    const SDL_VideoInfo* info = NULL;
    /* Dimensions of our window. */
    int width = 0;
    int height = 0;
    /* Color depth in bits of our window. */
    int bpp = 0;
    /* Flags we will pass into SDL_SetVideoMode. */
    int flags = 0;

    /* First, initialize SDL's video subsystem. */
    if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
        /* Failed, exit. */
        fprintf( stderr, "Video initialization failed: %s\n",
             SDL_GetError( ) );
        quit_tutorial( 1 );
    }

    /* Let's get some video information. */
    info = SDL_GetVideoInfo( );

    if( !info ) {
        /* This should probably never happen. */
        fprintf( stderr, "Video query failed: %s\n",
             SDL_GetError( ) );
        quit_tutorial( 1 );
    }

    /*
     * Set our width/height to 640/480 (you would
     * of course let the user decide this in a normal
     * app). We get the bpp we will request from
     * the display. On X11, VidMode can't change
     * resolution, so this is probably being overly
     * safe. Under Win32, ChangeDisplaySettings
     * can change the bpp.
     */
    width = 640;
    height = 480;
    bpp = info->vfmt->BitsPerPixel;

    /*
     * Now, we want to setup our requested
     * window attributes for our OpenGL window.
     * We want *at least* 5 bits of red, green
     * and blue. We also want at least a 16-bit
     * depth buffer.
     *
     * The last thing we do is request a double
     * buffered window. '1' turns on double
     * buffering, '0' turns it off.
     *
     * Note that we do not use SDL_DOUBLEBUF in
     * the flags to SDL_SetVideoMode. That does
     * not affect the GL attribute state, only
     * the standard 2D blitting setup.
     */
    SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

    /*
     * We want to request that SDL provide us
     * with an OpenGL window, in a fullscreen
     * video mode.
     *
     * EXERCISE:
     * Make starting windowed an option, and
     * handle the resize events properly with
     * glViewport.
     */
    flags = SDL_OPENGL;

    /*
     * Set the video mode
     */
    if( SDL_SetVideoMode( width, height, bpp, flags ) == 0 ) {
        /* 
         * This could happen for a variety of reasons,
         * including DISPLAY not being set, the specified
         * resolution not being available, etc.
         */
        fprintf( stderr, "Video mode set failed: %s\n",
             SDL_GetError( ) );
        quit_tutorial( 1 );
    }

    /*
     * At this point, we should have a properly setup
     * double-buffered window for use with OpenGL.
     */
    setup_opengl( width, height );



    /*
     * Now we want to begin our normal app process--
     * an event loop with a lot of redrawing.
     */
    while( 1 ) {
        /* Process incoming events. */
        process_events( );
        /* Draw the screen. */
        draw_screen( &model );

        SDL_PumpEvents();
        uint8_t * keys = SDL_GetKeyState(NULL);

        game_time += 0.4;
        float friction = (speed < 0.4) ? (speed < 0.2) ? 0.5 : 0.85 : 0.98;
        speed *= friction;

        if(keys[SDLK_w]){
            speed += 0.13*(1-speed) + 0.1*speed;
        }
        if(keys[SDLK_a]){
            angle += .1;
            speed += 0.13*(1-speed) - 0.1*speed;
        }
        if(keys[SDLK_d]){
            angle -= .1;
            speed += 0.13*(1-speed) - 0.1*speed;
        }
        if(speed > 1) speed = 1;
    }

    /*
     * EXERCISE:
     * Record timings using SDL_GetTicks() and
     * and print out frames per second at program
     * end.
     */

    /* Never reached. */
    return 0;
}