Esempio n. 1
0
/**
 * @return whether window initialization succeeded
 * @param title char* string with window title
 *
 * Initializes the game window
 */
bool SpringApp::InitWindow (const char* title)
{
	unsigned int sdlInitFlags = SDL_INIT_VIDEO | SDL_INIT_TIMER;
#ifdef WIN32
	// the crash reporter should be catching the errors
	sdlInitFlags |= SDL_INIT_NOPARACHUTE;
#endif
	if ((SDL_Init(sdlInitFlags) == -1)) {
		handleerror(NULL,"Could not initialize SDL.","ERROR",MBF_OK|MBF_EXCL);
		return false;
	}

	// Sets window manager properties
	SDL_WM_SetIcon(SDL_LoadBMP("spring.bmp"),NULL);
	SDL_WM_SetCaption(title, title);

	if (!SetSDLVideoMode ())
		return false;

	return true;
}
Esempio n. 2
0
File: main.cpp Progetto: boredzo/CCX
void ReserveMonitor( void )
{
	
#if TARGET_API_MAC_CARBON
#else
	SDL_Surface* icon;
	SDL_Surface* mask;
	
	// This icon and mask pair defines the dock icon on OS X. Without it, we get the .app's icon.
	icon = LoadPICTAsSurface( 10000, 16 );
	mask = LoadPICTAsSurface( 10001, 1 );
	SDL_WM_SetIcon( icon, (Uint8*) mask->pixels );
	SDL_FreeSurface( icon );
	SDL_FreeSurface( mask );
#endif
	SDL_ShowCursor( SDL_DISABLE );
	
	frontSurface = SDL_SetVideoMode( 640, 480, 24, SDL_SWSURFACE | SDL_FULLSCREEN );

	SDL_WM_SetCaption( "Candy Crisis", "CandyCrisis" );
}
void WindowManager::setWindowIcon(const unsigned char *data, const int size) const
{
	// prepare data buffer structure
	SDL_RWops *buffer = SDL_RWFromMem((void*) data, size);

	if(buffer != NULL) {
		// load BMP from prepared data buffer
		SDL_Surface *surface = SDL_LoadBMP_RW(buffer, 1);

		if(surface != NULL) {
			// set window icon
			SDL_WM_SetIcon(surface, NULL);
			SDL_FreeSurface(surface);
		}
		else {
			cerr << "Could not create window icon surface: " << SDL_GetError() << endl;
		}
	}
	else {
		cerr << "Could not prepare window icon data: " << SDL_GetError() << endl;
	}
}
Esempio n. 4
0
/* constructor and destructor */
CSDL_ApplicationBase::CSDL_ApplicationBase(long flags) {
    m_bIsRunning = true;
    m_pErrorBuffer = new char[256];
    m_bIsOpenGL = (flags & SDL_OPENGL) ? true : false;
    m_bIsFullscreen = false;
    m_PrimarySurface = NULL;
    ::atexit (::SDL_Quit);
    if(flags & SDL_INIT_VIDEO) {
        InitVideo();
    }

    if(flags & SDL_INIT_AUDIO) {
        InitAudio();
    }
    if(flags & SDL_OPENGL) {
//        InitOpenGL();
        SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
        SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ) ;
    }


    Uint32          colorkey;
    SDL_Surface     *image;
    image = SDL_LoadBMP("data/Orc.bmp");
    colorkey = SDL_MapRGB(image->format, 255, 0, 255);
    SDL_SetColorKey(image, SDL_SRCCOLORKEY, colorkey);
    SDL_WM_SetIcon(image,NULL);

    SetCaption("Loading...");

    SetVideoMode(800, 600, 32, ((m_bIsFullscreen) ? SDL_FULLSCREEN : 0) | ((m_bIsOpenGL) ? SDL_OPENGL : SDL_HWSURFACE|SDL_DOUBLEBUF));


    m_MouseCursorSurface = new CSDL_Surface("data/cursor.bmp");
//    m_MouseCursorSurface->SetColorKey(255, 0, 255, SDL_SRCCOLORKEY|SDL_RLEACCEL);

    FPS_Init();

} // constructor
Esempio n. 5
0
File: naev.c Progetto: ekrumme/naev
/**
 * @brief Sets the window caption.
 */
static void window_caption (void)
{
   char buf[PATH_MAX];
   SDL_RWops *rw;

   /* Set caption. */
   snprintf(buf, PATH_MAX ,APPNAME" - %s", ndata_name());
   SDL_WM_SetCaption(buf, APPNAME);

   /* Set icon. */
   rw = ndata_rwops( "gfx/icon.png" );
   if (rw == NULL) {
      WARN("Icon (gfx/icon.png) not found!");
      return;
   }
   naev_icon = IMG_Load_RW( rw, 1 );
   if (naev_icon == NULL) {
      WARN("Unable to load gfx/icon.png!");
      return;
   }
   SDL_WM_SetIcon( naev_icon, NULL );
}
Esempio n. 6
0
//bgColor is the background color (white)
//Initialize all the SDL subsystems
//Set up the screen mode, the window caption and then load all the files
//If anything fails to init, throw the relevant error
ImageCache::ImageCache() : screen(nullptr),
                            mScrWidth(800), 
							mScrHeight(600)
{
    try
    {
        SDL_putenv("SDL_VIDEO_CENTERED=center");

        if(SDL_Init(SDL_INIT_VIDEO) == -1)
        {
			throw(SDL_GetError());
		}

        if(TTF_Init() == -1)
        {
			throw(TTF_GetError());
		}

        SDL_WM_SetIcon(SDL_LoadBMP("files/images/icon.bmp"), 0);

        screen = SDL_SetVideoMode(mScrWidth, mScrHeight, 32, SDL_SWSURFACE);

        if(!screen)
        {
			throw(SDL_GetError());
		}

        SDL_WM_SetCaption("Bomber Run", 0);

        clearScreen();

        updateScreen();
    }
    catch(const char* e)
    {
        printf("Failed to create ImgCache: %s", e);
        exit(701);
    }
}
Esempio n. 7
0
SDL_Surface* init_window ()
{
	if (SDL_Init (SDL_INIT_VIDEO))
	{
		fprintf (stderr, "SDL_Init failed : %s\n", SDL_GetError());
		exit (1);
	}
	if (TTF_Init ())
	{
		fprintf (stderr, "TTF_Init failed : %s\n", SDL_GetError());
		exit (2);
	}

	SDL_WM_SetIcon (SDL_LoadBMP("ressources/ico.bmp"), NULL);
	SDL_WM_SetCaption ("HEX (...a saute !)", "");

	if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) == -1)
		fprintf(stderr, "Mix init failed : %s\n", Mix_GetError());
	Mix_AllocateChannels(3); //MIX_CHANNELS

	const SDL_VideoInfo* info = SDL_GetVideoInfo();
	int bpp;
	if (info == NULL)
	{
		fprintf (stderr, "Unable to get video information\n Trying to force BPP to 8.\n");
		bpp = 8;
	}
	else
		bpp = info->vfmt->BitsPerPixel;

	SDL_Surface* window = SDL_SetVideoMode (DWIDTH, DHEIGHT, bpp, SDL_HWSURFACE | SDL_RESIZABLE | SDL_DOUBLEBUF);
	if (window == NULL)
	{
		fprintf (stderr, "Unable to set video mode : %s\n", SDL_GetError());
		exit (3);
	}
	return window;
}
Esempio n. 8
0
int initGraphics()
{
    //init SDL
    if( SDL_Init(SDL_INIT_EVERYTHING) < 0 )
    {
        return 0;
    }

    SDL_InitSubSystem(SDL_INIT_AUDIO);

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);

    //set icon
    Uint32          colorkey;
    SDL_Surface     *icon;

    icon = SDL_LoadBMP("textures/icon.bmp");
    printf("After load icon\n");

    colorkey = SDL_MapRGB(icon->format, 255, 255, 255);
    SDL_SetColorKey(icon, SDL_SRCCOLORKEY, colorkey);
    SDL_WM_SetIcon(icon,NULL);

    //Set video mode
    if( SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_OPENGL ) == NULL )
    {
        return 0;
    }

    //init GL
    if( init_GL() == 0 )
    {
        return 0;
    }
    SDL_WM_SetCaption( "Amazing Tiny Adventures", NULL );

    return 1;
}
Esempio n. 9
0
//初始化
void GameFrame::Initial( int wid, int hei, char* wndName, char* icon, bool fullscreen )
{
	//初始化SDL库
	SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER );
	//设置窗口图标
	SDL_WM_SetIcon(SDL_LoadBMP( icon ), NULL);
	//创建窗口
	DRAW.CreateWnd( wid, hei, fullscreen );
	//设置窗口Caption
	SDL_WM_SetCaption( wndName, NULL );
	//时间初始化
	m_time= SDL_GetTicks();
	//声音系统初始化
	SND.InitDevice();
	//随机数生成器初始化
	srand( (unsigned int)time(0) );

#ifdef _DEBUG
	md_frames= 0;
	md_lastTime= 0;
#endif

}
Esempio n. 10
0
void vgainit(void)
{
    SDL_Surface *tmp = NULL;

    tmp = SDL_CreateRGBSurfaceFrom(Icon, 64, 64, 8, 64, 0, 0, 0, 0);
    SDL_SetColorKey(tmp, SDL_SRCCOLORKEY, 247);

    tmp->format->palette->colors = IconPalette;

    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
        exit(1);
    }
    SDL_WM_SetCaption("D I G G E R", NULL);
    SDL_WM_SetIcon(tmp, NULL);
    if (setmode() == false)
    {
        fprintf(stderr, "Couldn't set 640x400x8 video mode: %s\n", SDL_GetError());
        exit(1);
    }
    SDL_ShowCursor(0);
}
Esempio n. 11
0
void graphics_init()
{
	if( SDL_InitSubSystem(SDL_INIT_VIDEO) )
	{	printf("[SDL] %s\n", SDL_GetError());	assert( !"Cannot initialize SDL graphics" );	}

	/* set icon */
	SDL_Surface *icon = SDL_LoadBMP("data/icon32.bmp");
	if ( icon )
	{
		SDL_SetColorKey( icon, SDL_RLEACCEL | SDL_SRCCOLORKEY, SDL_MapRGB( icon->format, 255,255,255 ) );
		SDL_WM_SetIcon(icon, NULL);
	} else printf("[W] Cannot find icon for this window\n");

	printf("Starting GUI %dx%d %s\n",	cl.resx, cl.resy, cl.full_screen ? "full screen":"");

	/* set up window */
	if ( cl.full_screen )		w.createFullScreen( cl.resx, cl.resy, cl.bpp);
	else						w.create( cl.resx, cl.resy, cl.bpp);
	SDL_WM_SetCaption("Client", NULL);

	/* load models */
	#ifdef __USE_3DS_GRAPHICS__
	wall_model = new Ogl3dsObject("data/wall.3ds");
	apple_model = new Ogl3dsObject("data/food.3ds");
	floor_model = new Ogl3dsObject("data/floor.3ds");
	player_model = new Ogl3dsObject("data/player.3ds");
	#else
	wall_model = new OglVrmlObject("data/wall.wrl");
	apple_model = new OglVrmlObject("data/food.wrl");
	floor_model = new OglVrmlObject("data/floor.wrl");
	player_model = new OglVrmlObject("data/player.wrl");
	#endif
	assert( player_model && apple_model && wall_model && floor_model );

	/* load font */
	font = new BitmapFont("data/mainfont.bmp");		assert( font );
}
Esempio n. 12
0
static void R_SetSDLIcon (void)
{
#ifndef _WIN32
#include "../../ports/linux/ufoicon.xbm"
	SDL_Surface* icon = SDL_CreateRGBSurface(SDL_SWSURFACE, ufoicon_width, ufoicon_height, 8, 0, 0, 0, 0);
	if (icon == nullptr)
		return;
#if SDL_VERSION_ATLEAST(2,0,0)
	SDL_SetColorKey(icon, SDL_TRUE, 0);
#else
	SDL_SetColorKey(icon, SDL_SRCCOLORKEY, 0);

	SDL_Color color;
	color.r = color.g = color.b = 255;
	SDL_SetColors(icon, &color, 0, 1); /* just in case */

	color.r = color.b = 0;
	color.g = 16;
	SDL_SetColors(icon, &color, 1, 1);
#endif

	Uint8 *ptr = (Uint8 *)icon->pixels;
	for (unsigned int i = 0; i < sizeof(ufoicon_bits); i++) {
		for (unsigned int mask = 1; mask != 0x100; mask <<= 1) {
			*ptr = (ufoicon_bits[i] & mask) ? 1 : 0;
			ptr++;
		}
	}

#if SDL_VERSION_ATLEAST(2,0,0)
	SDL_SetWindowIcon(cls.window, icon);
#else
	SDL_WM_SetIcon(icon, nullptr);
#endif
	SDL_FreeSurface(icon);
#endif
}
Esempio n. 13
0
int		main(void)
{
	SDL_Surface *screen = NULL, *image = NULL, *tree = NULL;
	int			width = 800, high = 600;
	SDL_Rect	position, position_tree;

if (SDL_Init(SDL_INIT_VIDEO) == -1)
	{
		fprintf(stderr, "Erreur init SDL: %s\n", SDL_GetError());
		exit(EXIT_FAILURE);
	}
	SDL_WM_SetIcon(SDL_LoadBMP("Pictures/sdl_icone.bmp"), NULL);
	screen = SDL_SetVideoMode(width, high, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
	if (screen == NULL)
	{
		fprintf(stderr, "Erreur environnement video%s\n", SDL_GetError());
		exit(EXIT_FAILURE);
	}
	SDL_WM_SetCaption("test", 0x0);
	image = IMG_Load("Pictures/lac_en_montagne.bmp");

	tree = IMG_Load("Pictures/sapin.png");

	position.x = 0;
	position.y = 0;
	position_tree.x = 500;
	position_tree.y = 200;
	
	SDL_BlitSurface(image, NULL, screen, &position);
	SDL_BlitSurface(tree, NULL, screen, &position_tree);
	SDL_Flip(screen);
	
	pause();
	
	SDL_Quit();
	return (EXIT_SUCCESS);
}
Esempio n. 14
0
void sdlCreditsInit(sdlCredits *pSdlCredits)
{
	assert(   SDL_Init( SDL_INIT_EVERYTHING )!= -1 );
	
	
	pSdlCredits->surface_icone = SDL_LoadBMP("data/icone.bmp");
	if (pSdlCredits->surface_icone==NULL)
		pSdlCredits->surface_icone = SDL_LoadBMP("../data/icone.bmp");
	assert( pSdlCredits->surface_icone!=NULL);
	
	SDL_WM_SetIcon(pSdlCredits->surface_icone, NULL);
	

	pSdlCredits->surface_ecran = SDL_SetVideoMode( 640, 640, 32, SDL_SWSURFACE );
	assert( pSdlCredits->surface_ecran!=NULL);
	SDL_WM_SetCaption( "MHD v1.0", NULL );

	/**Chargement des surfaces*/
	
	pSdlCredits->surface_bg = SDL_LoadBMP("data/credits/bgcredits.bmp");
	if (pSdlCredits->surface_bg==NULL)
		pSdlCredits->surface_bg = SDL_LoadBMP("../data/credits/bgcredits.bmp");
	assert( pSdlCredits->surface_bg!=NULL);
	
	
	
	/**Chargement des musiques*/
	pSdlCredits->musiquecredits=Mix_LoadMUS("data/credits/musiquecredits.wav");
	if (pSdlCredits->musiquecredits==NULL)
		pSdlCredits->musiquecredits=Mix_LoadMUS("../data/credits/musiquecredits.wav");
	assert( pSdlCredits->musiquecredits!=NULL);
	
	
	/**Determination de la position de l'image*/
	pSdlCredits->positionFond.x = 0;
	pSdlCredits->positionFond.y = 0;
}
Esempio n. 15
0
void seticon(void)
{
//  int masklen;
//  Uint8 * mask;
  SDL_Surface * icon;


  /* Load icon into a surface: */

  icon = IMG_Load((datadir + "/images/icon.xpm").c_str());
  if (icon == NULL)
    {
      fprintf(stderr,
              "\nError: I could not load the icon image: %s%s\n"
              "The Simple DirectMedia error that occured was:\n"
              "%s\n\n", datadir.c_str(), "/images/icon.xpm", SDL_GetError());
      exit(1);
    }


  /* Create mask: */
/*
  masklen = (((icon -> w) + 7) / 8) * (icon -> h);
  mask = (Uint8*) malloc(masklen * sizeof(Uint8));
  memset(mask, 0xFF, masklen);
*/

  /* Set icon: */

  SDL_WM_SetIcon(icon, NULL);//mask);


  /* Free icon surface & mask: */

//  free(mask);
  SDL_FreeSurface(icon);
}
Esempio n. 16
0
void SDLWindow::setIcon(const GImage& image) {
    alwaysAssertM((image.channels == 3) ||
                  (image.channels == 4), 
                  "Icon image must have at least 3 channels.");

    #ifdef G3D_WIN32
        alwaysAssertM((image.width == 32) && (image.height == 32),
            "Icons must be 32x32 on windows.");
    #endif

    uint32 amask = 0xFF000000;
    uint32 bmask = 0x00FF0000;
    uint32 gmask = 0x0000FF00;
    uint32 rmask = 0x000000FF;

    if (image.channels == 3) {
        // Take away the 4th channel.
        amask = 0x00000000;
    }

    int pixelBitLen     = image.channels * 8;
    int scanLineByteLen = image.channels * image.width;

    SDL_Surface* surface =
        SDL_CreateRGBSurfaceFrom((void*)image.byte(), image.width, image.height,
        pixelBitLen, scanLineByteLen, 
        rmask, gmask, bmask, amask);

    alwaysAssertM((surface != NULL),
        "Icon data failed to load into SDL.");

    // Let SDL create mask from image data directly
    SDL_WM_SetIcon(surface, NULL);

    SDL_FreeSurface(surface);
}
Esempio n. 17
0
void sg_SetIcon()
{
#ifndef DEDICATED
#ifndef MACOSX
#ifdef  WIN32
    SDL_SysWMinfo	info;
    HICON			icon;
    // get the HWND handle
    SDL_VERSION( &info.version );
    if( SDL_GetWMInfo( &info ) )
    {
        icon = LoadIcon( GetModuleHandle( NULL ), MAKEINTRESOURCE( 1 ) );
        SetClassLong( info.window, GCL_HICON, (LONG) icon );
    }
#else
    rSurface tex( "desktop/icons/medium/armagetronad.png" );
    //    SDL_Surface *tex=IMG_Load( tDirectories::Data().GetReadPath( "textures/icon.png" ) );

    if (tex.GetSurface())
        SDL_WM_SetIcon(tex.GetSurface(),NULL);
#endif
#endif
#endif
}
Esempio n. 18
0
static void loadFont(int detectSize)
{
	char font[60];
	
	if (detectSize) {
		int fontWidths[13] = {112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 272, 288, 304}; // widths of the font graphics (divide by 16 to get individual character width)
		int fontHeights[13] = {176, 208, 240, 272, 304, 336, 368, 400, 432, 464, 496, 528, 528}; // heights of the font graphics (divide by 16 to get individual character height)

		const SDL_VideoInfo* vInfo = SDL_GetVideoInfo();
		int screenWidth = desktop_width = vInfo->current_w;
		int screenHeight = desktop_height = vInfo->current_h;

		// adjust for title bars and whatever -- very approximate, but better than the alternative
		screenWidth -= 6;
		screenHeight -= 48;

		if (brogueFontSize < 1 || brogueFontSize > 13) {
			for (
				brogueFontSize = 13;
				brogueFontSize > 1 && (fontWidths[brogueFontSize - 1] * COLS / 16 >= screenWidth || fontHeights[brogueFontSize - 1] * ROWS / 16 >= screenHeight);
				brogueFontSize--
			);
		}

	}

	sprintf(font, "fonts/font-%i.png", brogueFontSize);
	
	TCOD_console_set_custom_font(font, (TCOD_FONT_TYPE_GREYSCALE | TCOD_FONT_LAYOUT_ASCII_INROW), 0, 0);
	TCOD_console_init_root(COLS, ROWS, "Brogue", false, renderer);

	TCOD_console_map_ascii_codes_to_font(0, 255, 0, 0);
	TCOD_console_set_keyboard_repeat(175, 30);

	SDL_WM_SetIcon(SDL_LoadBMP("icon.bmp"), NULL);
}
Esempio n. 19
0
static void SetIcon(void)
{
    SDL_Surface *surface;
    Uint8 *mask;
    int i;

    // Generate the mask
  
    mask = malloc(setup_icon_w * setup_icon_h / 8);
    memset(mask, 0, setup_icon_w * setup_icon_h / 8);

    for (i=0; i<setup_icon_w * setup_icon_h; ++i) 
    {
        if (setup_icon_data[i * 3] != 0x00
         || setup_icon_data[i * 3 + 1] != 0x00
         || setup_icon_data[i * 3 + 2] != 0x00)
        {
            mask[i / 8] |= 1 << (7 - i % 8);
        }
    }


    surface = SDL_CreateRGBSurfaceFrom(setup_icon_data,
                                       setup_icon_w,
                                       setup_icon_h,
                                       24,
                                       setup_icon_w * 3,
                                       0xff << 0,
                                       0xff << 8,
                                       0xff << 16,
                                       0);

    SDL_WM_SetIcon(surface, mask);
    SDL_FreeSurface(surface);
    free(mask);
}
Esempio n. 20
0
	void Display::setIcon(Image* image)
	{
		if(checkInit()==false) throw Exception("Fatal error: attempt to use GameEngine library without initialization!");
		SDL_WM_SetIcon(image->implementation->sdlSurface,  null);
	}
OpenGLWindow::OpenGLWindow(const std::string& title, 
                           const Size& size, const Size& aspect, bool fullscreen, int anti_aliasing) :
  m_impl(new OpenGLWindowImpl)
{
  m_impl->m_size = size;

  //SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); // vsync
  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 

  // FIXME: Should make this configurable, as Matrox G450 can't do it,
  // but works 'fine' without it
  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_BUFFER_SIZE, 32);

  SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);

  if (anti_aliasing)
  {
    SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 ); // boolean value, either it's enabled or not
    SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, anti_aliasing ); // 0, 2, or 4 for number of samples
  }
  
  SDL_WM_SetCaption(title.c_str(), title.c_str());
  SDL_WM_SetIcon(IMG_Load(Pathname("icon.png").get_sys_path().c_str()), NULL);

  m_impl->m_window = SDL_SetVideoMode(size.width, size.height,
                                      0, SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0));

  if (!m_impl->m_window)
  {
    throw std::runtime_error("Display:: Couldn't create window");
  }
  else
  {
    GLenum err = glewInit();
    if (err != GLEW_OK) 
    {
      std::ostringstream msg;
      msg << "Display:: Couldn't initialize glew: " << glewGetString(err);
      throw std::runtime_error(msg.str());
    }
    else
    {
      std::cout << "glewInit() successfull: " << glewGetString(GLEW_VERSION) << std::endl;
      std::cout << "OpenGL " << glGetString(GL_VERSION) << " detected" << std::endl;
      std::cout << "OpenGL 3.2: " << GL_VERSION_3_2 << std::endl;
      std::cout << "GL_VERSION_3_0: " << GL_VERSION_3_0 << std::endl;

      glViewport(0, 0, m_impl->m_window->w, m_impl->m_window->h);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();

      Display::aspect_size = aspect;

      glOrtho(0.0, Display::get_width(), Display::get_height(),
              0.0, 1000.0, -1000.0);
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();

      if (0) // disabled for the moment, as it seems to do more harm then good
      { // Magic pixel center constant, without that textures drawn in
        // pixel coordinates might end up blurry       
        glTranslated(0.375f, 0.375f, 0.0);
      }

      if (anti_aliasing)
        glEnable(GL_MULTISAMPLE); 

      assert_gl("setup projection");

      OpenGLState::init();
    }
  }
}
Esempio n. 22
0
bool VideoDriver_SDL::CreateMainSurface(uint w, uint h)
{
	SDL_Surface *newscreen, *icon;
	char caption[50];
	int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
	bool want_hwpalette;

	GetAvailableVideoMode(&w, &h);

	DEBUG(driver, 1, "SDL: using mode %ux%ux%d", w, h, bpp);

	if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals");

	char icon_path[MAX_PATH];
	if (FioFindFullPath(icon_path, lengthof(icon_path), BASESET_DIR, "openttd.32.bmp") != NULL) {
		/* Give the application an icon */
		icon = SDL_CALL SDL_LoadBMP(icon_path);
		if (icon != NULL) {
			/* Get the colourkey, which will be magenta */
			uint32 rgbmap = SDL_CALL SDL_MapRGB(icon->format, 255, 0, 255);

			SDL_CALL SDL_SetColorKey(icon, SDL_SRCCOLORKEY, rgbmap);
			SDL_CALL SDL_WM_SetIcon(icon, NULL);
			SDL_CALL SDL_FreeSurface(icon);
		}
	}

	if (_use_hwpalette == 2) {
		/* Default is to autodetect when to use SDL_HWPALETTE.
		 * In this case, SDL_HWPALETTE is only used for 8bpp
		 * blitters in fullscreen.
		 *
		 * When using an 8bpp blitter on a 8bpp system in
		 * windowed mode with SDL_HWPALETTE, OpenTTD will claim
		 * the system palette, making all other applications
		 * get the wrong colours. In this case, we're better of
		 * trying to approximate the colors we need using system
		 * colors, using a shadow surface (see below).
		 *
		 * On a 32bpp system, SDL_HWPALETTE is ignored, so it
		 * doesn't matter what we do.
		 *
		 * When using a 32bpp blitter on a 8bpp system, setting
		 * SDL_HWPALETTE messes up rendering (at least on X11),
		 * so we don't do that. In this case, SDL takes care of
		 * color approximation using its own shadow surface
		 * (which we can't force in 8bpp on 8bpp mode,
		 * unfortunately).
		 */
		want_hwpalette = (bpp == 8 && _fullscreen);
	} else {
		/* User specified a value manually */
		want_hwpalette = _use_hwpalette;
	}

	if (want_hwpalette) DEBUG(driver, 1, "SDL: requesting hardware palete");

	/* Free any previously allocated shadow surface */
	if (_sdl_screen != NULL && _sdl_screen != _sdl_realscreen) SDL_CALL SDL_FreeSurface(_sdl_screen);

	if (_sdl_realscreen != NULL) {
		if (_requested_hwpalette != want_hwpalette) {
			/* SDL (at least the X11 driver), reuses the
			 * same window and palette settings when the bpp
			 * (and a few flags) are the same. Since we need
			 * to hwpalette value to change (in particular
			 * when switching between fullscreen and
			 * windowed), we restart the entire video
			 * subsystem to force creating a new window.
			 */
			DEBUG(driver, 0, "SDL: Restarting SDL video subsystem, to force hwpalette change");
			SDL_CALL SDL_QuitSubSystem(SDL_INIT_VIDEO);
			SDL_CALL SDL_InitSubSystem(SDL_INIT_VIDEO);
			ClaimMousePointer();
			SetupKeyboard();
		}
	}
	/* Remember if we wanted a hwpalette. We can't reliably query
	 * SDL for the SDL_HWPALETTE flag, since it might get set even
	 * though we didn't ask for it (when SDL creates a shadow
	 * surface, for example). */
	_requested_hwpalette = want_hwpalette;

	/* DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK */
	newscreen = SDL_CALL SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | (want_hwpalette ? SDL_HWPALETTE : 0) | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE));
	if (newscreen == NULL) {
		DEBUG(driver, 0, "SDL: Couldn't allocate a window to draw on");
		return false;
	}
	_sdl_realscreen = newscreen;

	if (bpp == 8 && (_sdl_realscreen->flags & SDL_HWPALETTE) != SDL_HWPALETTE) {
		/* Using an 8bpp blitter, if we didn't get a hardware
		 * palette (most likely because we didn't request one,
		 * see above), we'll have to set up a shadow surface to
		 * render on.
		 *
		 * Our palette will be applied to this shadow surface,
		 * while the real screen surface will use the shared
		 * system palette (which will partly contain our colors,
		 * but most likely will not have enough free color cells
		 * for all of our colors). SDL can use these two
		 * palettes at blit time to approximate colors used in
		 * the shadow surface using system colors automatically.
		 *
		 * Note that when using an 8bpp blitter on a 32bpp
		 * system, SDL will create an internal shadow surface.
		 * This shadow surface will have SDL_HWPALLETE set, so
		 * we won't create a second shadow surface in this case.
		 */
		DEBUG(driver, 1, "SDL: using shadow surface");
		newscreen = SDL_CALL SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, bpp, 0, 0, 0, 0);
		if (newscreen == NULL) {
			DEBUG(driver, 0, "SDL: Couldn't allocate a shadow surface to draw on");
			return false;
		}
	}

	/* Delay drawing for this cycle; the next cycle will redraw the whole screen */
	_num_dirty_rects = 0;

	_screen.width = newscreen->w;
	_screen.height = newscreen->h;
	_screen.pitch = newscreen->pitch / (bpp / 8);
	_screen.dst_ptr = newscreen->pixels;
	_sdl_screen = newscreen;

	/* When in full screen, we will always have the mouse cursor
	 * within the window, even though SDL does not give us the
	 * appropriate event to know this. */
	if (_fullscreen) _cursor.in_window = true;

	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
	blitter->PostResize();

	InitPalette();
	switch (blitter->UsePaletteAnimation()) {
		case Blitter::PALETTE_ANIMATION_NONE:
		case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
			UpdatePalette();
			break;

		case Blitter::PALETTE_ANIMATION_BLITTER:
			if (_video_driver != NULL) blitter->PaletteAnimate(_local_palette);
			break;

		default:
			NOT_REACHED();
	}

	snprintf(caption, sizeof(caption), "OpenTTD %s", _openttd_revision);
	SDL_CALL SDL_WM_SetCaption(caption, caption);

	GameSizeChanged();

	return true;
}
Esempio n. 23
0
/**
 * Attempts to initialize the graphical video display.  Returns 0 on
 * success, -1 on failure.
 */
int
InitVideo(FCEUGI *gi)
{
	// XXX soules - const?  is this necessary?
	const SDL_VideoInfo *vinf;
	int error, flags = 0;
	int doublebuf, xstretch, ystretch, xres, yres, show_fps;

	FCEUI_printf("Initializing video...");

	// load the relevant configuration variables
	g_config->getOption("SDL.Fullscreen", &s_fullscreen);
	g_config->getOption("SDL.DoubleBuffering", &doublebuf);
#ifdef OPENGL
	g_config->getOption("SDL.OpenGL", &s_useOpenGL);
#endif
	g_config->getOption("SDL.SpecialFilter", &s_sponge);
	g_config->getOption("SDL.XStretch", &xstretch);
	g_config->getOption("SDL.YStretch", &ystretch);
	g_config->getOption("SDL.LastXRes", &xres);
	g_config->getOption("SDL.LastYRes", &yres);
	g_config->getOption("SDL.ClipSides", &s_clipSides);
	g_config->getOption("SDL.NoFrame", &noframe);
	g_config->getOption("SDL.ShowFPS", &show_fps);

	// check the starting, ending, and total scan lines
	FCEUI_GetCurrentVidSystem(&s_srendline, &s_erendline);
	s_tlines = s_erendline - s_srendline + 1;

	// check if we should auto-set x/y resolution

    // check for OpenGL and set the global flags
#if OPENGL
	if(s_useOpenGL && !s_sponge) {
		flags = SDL_OPENGL;
	}
#endif

	// initialize the SDL video subsystem if it is not already active
	if(!SDL_WasInit(SDL_INIT_VIDEO)) {
		error = SDL_InitSubSystem(SDL_INIT_VIDEO);
		if(error) {
			FCEUD_PrintError(SDL_GetError());
			return -1;
		}
	}
	s_inited = 1;

	// shows the cursor within the display window
	SDL_ShowCursor(1);

	// determine if we can allocate the display on the video card
	vinf = SDL_GetVideoInfo();
	if(vinf->hw_available) {
		flags |= SDL_HWSURFACE;
	}
    
	// get the monitor's current resolution if we do not already have it
	if(s_nativeWidth < 0) {
		s_nativeWidth = vinf->current_w;
	}
	if(s_nativeHeight < 0) {
		s_nativeHeight = vinf->current_h;
	}

	// check to see if we are showing FPS
	FCEUI_SetShowFPS(show_fps);
    
	// check if we are rendering fullscreen
	if(s_fullscreen) {
		int no_cursor;
		g_config->getOption("SDL.NoFullscreenCursor", &no_cursor);
		flags |= SDL_FULLSCREEN;
		SDL_ShowCursor(!no_cursor);
	}
	else {
		SDL_ShowCursor(1);
	}
    
	if(noframe) {
		flags |= SDL_NOFRAME;
	}

	// gives the SDL exclusive palette control... ensures the requested colors
	// flags |= SDL_HWPALETTE;

	// enable double buffering if requested and we have hardware support
#ifdef OPENGL
	if(s_useOpenGL) {
		FCEU_printf("Initializing with OpenGL (Disable with '--opengl 0').\n");
		if(doublebuf) {
			 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
		}
	} else
#endif
		if(doublebuf && (flags & SDL_HWSURFACE)) {
			flags |= SDL_DOUBLEBUF;
		}

	if(s_fullscreen) {
		int desbpp, autoscale;
		g_config->getOption("SDL.BitsPerPixel", &desbpp);
		g_config->getOption("SDL.AutoScale", &autoscale);
		if (autoscale)
		{
			double auto_xscale = GetXScale(xres);
			double auto_yscale = GetYScale(yres);
			double native_ratio = ((double)NWIDTH) / s_tlines;
			double screen_ratio = ((double)xres) / yres;
			int keep_ratio;
            
			g_config->getOption("SDL.KeepRatio", &keep_ratio);
            
			// Try to choose resolution
			if (screen_ratio < native_ratio)
			{
				// The screen is narrower than the original. Maximizing width will not clip
				auto_xscale = auto_yscale = GetXScale(xres);
				if (keep_ratio) 
					auto_yscale = GetYScale(yres);
			}
			else
			{
				auto_yscale = auto_xscale = GetYScale(yres);
				if (keep_ratio) 
					auto_xscale = GetXScale(xres);
			}
			s_exs = auto_xscale;
			s_eys = auto_yscale;
		}
		else
		{
			g_config->getOption("SDL.XScale", &s_exs);
			g_config->getOption("SDL.YScale", &s_eys);
		}
		g_config->getOption("SDL.SpecialFX", &s_eefx);

#ifdef OPENGL
		if(!s_useOpenGL) {
			s_exs = (int)s_exs;
			s_eys = (int)s_eys;
		} else {
			desbpp = 0;
		}
        
		// -Video Modes Tag-
		if(s_sponge) {
			if(s_sponge == 4 || s_sponge == 5) {
				s_exs = s_eys = 3;
			} else {
				s_exs = s_eys = 2;
			}
			s_eefx = 0;
			if(s_sponge == 1 || s_sponge == 4) {
				desbpp = 32;
			}
		}

		if((s_useOpenGL && !xstretch) || !s_useOpenGL)
#endif
			if(xres < (NWIDTH * s_exs) || s_exs <= 0.01) {
				FCEUD_PrintError("xscale out of bounds.");
				KillVideo();
				return -1;
			}

#ifdef OPENGL
		if((s_useOpenGL && !ystretch) || !s_useOpenGL)
#endif
			if(yres < s_tlines * s_eys || s_eys <= 0.01) {
				FCEUD_PrintError("yscale out of bounds.");
				KillVideo();
				return -1;
			}

#ifdef OPENGL
		s_screen = SDL_SetVideoMode(s_useOpenGL ? s_nativeWidth : xres,
									s_useOpenGL ? s_nativeHeight : yres,
									desbpp, flags);
#else
		s_screen = SDL_SetVideoMode(xres, yres, desbpp, flags);
#endif

		if(!s_screen) {
			FCEUD_PrintError(SDL_GetError());
			return -1;
		}
	} else {
		int desbpp;
		g_config->getOption("SDL.BitsPerPixel", &desbpp);

		g_config->getOption("SDL.XScale", &s_exs);
		g_config->getOption("SDL.YScale", &s_eys);
		g_config->getOption("SDL.SpecialFX", &s_eefx);
        
		// -Video Modes Tag-
		if(s_sponge) {
			if(s_sponge >= 4) {
				s_exs = s_eys = 3;
			} else {
				s_exs = s_eys = 2;
			}
			s_eefx = 0;
		}

#ifdef OPENGL
		if(!s_useOpenGL) {
			s_exs = (int)s_exs;
			s_eys = (int)s_eys;
		}
		if(s_exs <= 0.01) {
			FCEUD_PrintError("xscale out of bounds.");
			KillVideo();
			return -1;
		}
		if(s_eys <= 0.01) {
			FCEUD_PrintError("yscale out of bounds.");
			KillVideo();
			return -1;
		}
		if(s_sponge && s_useOpenGL) {
			FCEUD_PrintError("scalers not compatible with openGL mode.");
			KillVideo();
			return -1;
		}
#endif

#if defined(_GTK) && defined(SDL_VIDEO_DRIVER_X11)
		if(noGui == 0)
		{
			while (gtk_events_pending())
				gtk_main_iteration_do(FALSE);
        
			char SDL_windowhack[128];
			sprintf(SDL_windowhack, "SDL_WINDOWID=%u", (unsigned int)GDK_WINDOW_XID(gtk_widget_get_window(evbox)));
			SDL_putenv(SDL_windowhack);
        
			// init SDL video
			if (SDL_WasInit(SDL_INIT_VIDEO))
				SDL_QuitSubSystem(SDL_INIT_VIDEO);
			if ( SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 )
			{
				fprintf(stderr, "Couldn't init SDL video: %s\n", SDL_GetError());
				gtk_main_quit();
			}
		}
#endif
        
		s_screen = SDL_SetVideoMode((int)(NWIDTH * s_exs),
								(int)(s_tlines * s_eys),
								desbpp, flags);
		if(!s_screen) {
			FCEUD_PrintError(SDL_GetError());
			return -1;
		}

#ifdef _GTK
		if(noGui == 0)
		{
			GtkRequisition req;
			gtk_widget_size_request(GTK_WIDGET(MainWindow), &req);
			gtk_window_resize(GTK_WINDOW(MainWindow), req.width, req.height);
		 }
#endif
		 }
	s_curbpp = s_screen->format->BitsPerPixel;
	if(!s_screen) {
		FCEUD_PrintError(SDL_GetError());
		KillVideo();
		return -1;
	}

#if 0
	// XXX soules - this would be creating a surface on the video
    //              card, but was commented out for some reason...
    s_BlitBuf = SDL_CreateRGBSurface(SDL_HWSURFACE, 256, 240,
                                     s_screen->format->BitsPerPixel,
                                     s_screen->format->Rmask,
                                     s_screen->format->Gmask,
                                     s_screen->format->Bmask, 0);
#endif

	FCEU_printf(" Video Mode: %d x %d x %d bpp %s\n",
				s_screen->w, s_screen->h, s_screen->format->BitsPerPixel,
				s_fullscreen ? "full screen" : "");

	if(s_curbpp != 8 && s_curbpp != 16 && s_curbpp != 24 && s_curbpp != 32) {
		FCEU_printf("  Sorry, %dbpp modes are not supported by FCE Ultra.  Supported bit depths are 8bpp, 16bpp, and 32bpp.\n", s_curbpp);
		KillVideo();
		return -1;
	}

	// if the game being run has a name, set it as the window name
	if(gi)
	{
		if(gi->name) {
			SDL_WM_SetCaption((const char *)gi->name, (const char *)gi->name);
		} else {
			SDL_WM_SetCaption(FCEU_NAME_AND_VERSION,"FCE Ultra");
		}
	}

	// create the surface for displaying graphical messages
#ifdef LSB_FIRST
	s_IconSurface = SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data,
											32, 32, 24, 32 * 3,
											0xFF, 0xFF00, 0xFF0000, 0x00);
#else
	s_IconSurface = SDL_CreateRGBSurfaceFrom((void *)fceu_playicon.pixel_data,
											32, 32, 24, 32 * 3,
											0xFF0000, 0xFF00, 0xFF, 0x00);
#endif
	SDL_WM_SetIcon(s_IconSurface,0);
	s_paletterefresh = 1;

	// XXX soules - can't SDL do this for us?
	 // if using more than 8bpp, initialize the conversion routines
	if(s_curbpp > 8) {
	InitBlitToHigh(s_curbpp >> 3,
						s_screen->format->Rmask,
						s_screen->format->Gmask,
						s_screen->format->Bmask,
						s_eefx, s_sponge, 0);
#ifdef OPENGL
		if(s_useOpenGL) 
		{
			int openGLip;
			g_config->getOption("SDL.OpenGLip", &openGLip);

			if(!InitOpenGL(NOFFSET, 256 - (s_clipSides ? 8 : 0),
						s_srendline, s_erendline + 1,
						s_exs, s_eys, s_eefx,
						openGLip, xstretch, ystretch, s_screen)) 
			{
				FCEUD_PrintError("Error initializing OpenGL.");
				KillVideo();
				return -1;
			}
		}
#endif
	}
Esempio n. 24
0
/**
 * ANSI main entry point
 */
int main(int argc, char* argv[])
{
	unsigned long lvl_id;
	level::size lvl_sz;
	bool lvl_wrap;
	if (parse_cmd_params(argc, argv, lvl_id, lvl_sz, lvl_wrap))
		return 0;	//Help or version was shown

	//Initialization
	if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO) != 0) {
		fprintf(stderr, "Critical error\nSDL_Init failed: %s\n", SDL_GetError());
		return 1;
	}
#ifdef USE_OPENGLES
       	if (EGL_Open()){
		fprintf(stderr, "Critical error\nUnable to open egl\n");
		return 1;
	}
#endif
	//Let's get some video information
	const SDL_VideoInfo* vinfo = SDL_GetVideoInfo();
	if (!vinfo) {
		fprintf(stderr, "Critical error\nUnable to get video information: %s\n", SDL_GetError());
		return 1;
	}

	//Save desktop size
	const int desktop_width = vinfo->current_w;
	const int desktop_height = vinfo->current_h;

	//Calculate minimum window sizes
	const int wnd_min_width =  PW_SCREEN_WIDTH  / 3;
	const int wnd_min_height = PW_SCREEN_HEIGHT / 3;

	//Create window
#if USE_OPENGLES
	if (!SDL_SetVideoMode(800, 480, 0, SDL_FULLSCREEN)) {
		fprintf(stderr, "Critical error\nUnable to set video mode: %s\n", SDL_GetError());
		return 1;
	}
	int prevcursorstate=SDL_ShowCursor(SDL_QUERY);
	SDL_ShowCursor(SDL_DISABLE);
	EGL_Init();
#else
	if (!SDL_SetVideoMode(PW_SCREEN_WIDTH, PW_SCREEN_HEIGHT, 0, SDL_OPENGL | SDL_RESIZABLE)) {
		fprintf(stderr, "Critical error\nUnable to set video mode: %s\n", SDL_GetError());
		return 1;
	}
#endif
	SDL_WM_SetCaption(PACKAGE_NAME, PACKAGE_NAME);
	image wnd_icon;
	if (wnd_icon.load_XPM(pipewalker_xpm, sizeof(pipewalker_xpm) / sizeof(pipewalker_xpm[0])))
		SDL_WM_SetIcon(wnd_icon.get_surface(), NULL);

	game& game_instance = game::instance();
	if (!game_instance.initialize(lvl_id, lvl_sz, lvl_wrap))
		return 1;

	//Timer - about 25 fps
	SDL_SetTimer(40, &timer_callback);

#ifdef WIN32
	SDL_SysWMinfo wmi;
	SDL_VERSION(&wmi.version);
	if (SDL_GetWMInfo(&wmi)) {
		//Set own window procedure
		sdl_wnd_proc = reinterpret_cast<WNDPROC>(SetWindowLongPtr(wmi.window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&pw_win32_wnd_proc)));
		//Set normal icon
		static HICON icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(0));
		if (icon)
			SetClassLongPtr(wmi.window, GCL_HICON, reinterpret_cast<LONG>(icon));
	}
#endif // WIN32

	bool done = false;
	Uint8 last_mouse_state = 0;

	while (!done) {
		SDL_Event event;
		if (SDL_WaitEvent(&event) == 0) {
			fprintf(stderr, "Critical error\nSDL_WaitEvent failed: %s\n", SDL_GetError());
			return 1;
		}
		switch (event.type) {
			case SDL_MOUSEMOTION:
				{
					Sint32 x, y;
					SDL_GetMouseState(&x, &y);
					game_instance.on_mouse_move(x, y);
				}
				break;
			case SDL_MOUSEBUTTONDOWN:
				//We need to save buttons state - in the SDL_MOUSEBUTTONUP event doesn't have this information
				last_mouse_state = SDL_GetMouseState(NULL, NULL);
				break;
			case SDL_MOUSEBUTTONUP:
				if (last_mouse_state) {
					game_instance.on_mouse_click(last_mouse_state);
					last_mouse_state = 0;
				}
				break;
			case SDL_KEYDOWN:
				if (event.key.keysym.sym == SDLK_F4 && (SDL_GetModState() == KMOD_LALT || SDL_GetModState() == KMOD_RALT))
					done = true;	//Alt+F4 pressed
				else
					done = game_instance.on_key_press(event.key.keysym.sym);
				break;
			case SDL_QUIT:
				done = true;
				break;
			case SDL_VIDEOEXPOSE:
				game_instance.draw_scene();
				break;
			case SDL_VIDEORESIZE:
				if (event.resize.w && event.resize.h) {
					int wnd_width = event.resize.w;
					int wnd_height = event.resize.h;

					//Set correct aspect ratio
					if (wnd_width != desktop_width && wnd_height != desktop_height) {
						if (wnd_height != vinfo->current_h)
							wnd_width = static_cast<int>(static_cast<float>(wnd_height) / PW_ASPECT_RATIO);
						else if (wnd_width != vinfo->current_w)
							wnd_height = static_cast<int>(static_cast<float>(wnd_width) * PW_ASPECT_RATIO);
						if (wnd_width < wnd_min_width || wnd_height < wnd_min_height) {
							//Set minimum window size
							wnd_width = wnd_min_width;
							wnd_height = wnd_min_height;
						}
					}

					SDL_SetVideoMode(wnd_width, wnd_height, 0, SDL_OPENGL | SDL_RESIZABLE);
					game_instance.on_window_resize(wnd_width, wnd_height);
					SDL_Event expose_event;
					expose_event.type = SDL_VIDEOEXPOSE;
					SDL_PushEvent(&expose_event);
				}
				break;
		}
	}

	game_instance.finalize();
#if USE_OPENGLES
	EGL_Close();
	SDL_ShowCursor(prevcursorstate);
#endif

	SDL_Quit();
	return 0;
}
Esempio n. 25
0
void sys_create_display(int width,int height,int _fullscreen)
{
	 fullscreen = _fullscreen;
  /* Information about the current video settings. */
  const SDL_VideoInfo* info = NULL;
  int vidmode_flags=0, samplingerror = 0;

  /* First, initialize SDL's video subsystem. */
#ifdef USE_SOUND
  if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0 ) {
    error_print("Video or Audio initialization failed: %s",SDL_GetError());
#else
  if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) < 0 ) {
    error_print("Video initialization failed: %s",SDL_GetError());
#endif
    sys_exit(1);
  }

  sdl_on = 1 ; 

  /* Let's get some video information. */
  info = SDL_GetVideoInfo( );
  
  if( !info ) {
    /* This should probably never happen. */
    error_print("Video query failed: %s",SDL_GetError());
    sys_exit(1);
  }
  
  vidmode_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 VMfloat
   * buffered window. '1' turns on VMfloat
   * 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 );
  if (SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ) <0) {
  	 fprintf(stderr, "SDL_GL_DOUBLEBUFFER error: %s\n", SDL_GetError());
  	 options_vsync = 0;
  } else {
#ifdef __APPLE__
  const GLint swapInterval = 1;
	 CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &swapInterval);
#endif
//compile without errors, if SDL is < Version 1.2.10 at compile time
// on windows with patchlevel 15 only, rest of the world with higher 9
#ifdef USE_WIN
  #define CHECK_LEVEL 14
#else
  #define CHECK_LEVEL 9
#endif
#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2 && SDL_PATCHLEVEL > CHECK_LEVEL
// The next works only with fsaa options off!!! and not stable on win Patchlevel < 15
#ifndef USE_WIN
  if(!options_fsaa_value) {
    if(SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 ) < 0 ) {
       fprintf( stderr, "Unable to guarantee accelerated visual with libSDL < 1.2.10\n");
	  }
  }
#endif
  if(vsync_supported()) {
  	 if(options_vsync) {
      if (SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1) < 0) { // since SDL v1.2.10
        fprintf(stderr, "SDL_GL_SWAP_CONTROL error: %s\n", SDL_GetError());
        options_vsync = 0;
      }
  	 }
  } else {
    fprintf(stderr,"SDL-System without control of vsync. Scrolling may stutter\n");
  }
#endif
  }

#ifndef WETAB
  if(options_fsaa_value) {
    samplingerror = SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1);
    if(!samplingerror) {
      samplingerror = SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES,options_fsaa_value);
    }
  }
  if (samplingerror == -1) {
#endif
    options_fsaa_value = 0;
    fprintf(stderr,"FSAA Multisample not available\n");
#ifndef WETAB
  }
#endif
  SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );
  /* key repeat caused problem when toggling fullscreen !!! */

  vidmode_flags = SDL_OPENGL;

  if ( info->hw_available ) {
    vidmode_flags |= SDL_HWSURFACE;
    vidmode_flags |= SDL_HWPALETTE; /* Store the palette in hardware */
  } else {
    vidmode_flags |= SDL_SWSURFACE;
  }

  if ( info->blit_hw ) { /* checks if hardware blits can be done */
    vidmode_flags |= SDL_HWACCEL;
  }
#ifndef WETAB
  if (fullscreen) {
      vidmode_flags |= SDL_FULLSCREEN;
  } else {
#ifndef __APPLE__
      vidmode_flags |= SDL_RESIZABLE;
#endif
  }
#else
  vidmode_flags |= SDL_FULLSCREEN;
#endif

  //Set the window icon
  SDL_WM_SetIcon(SDL_LoadBMP("icon.bmp"),NULL);

#ifndef WETAB
  if(options_fsaa_value > options_maxfsaa) {
  	options_fsaa_value = options_maxfsaa;
  }
  while (vid_surface == NULL) {
#endif
   if((vid_surface=SDL_SetVideoMode( width, height, vidmode_bpp, vidmode_flags )) == NULL) {
    if(!options_fsaa_value) {
       error_print("Video mode set failed. Please restart Foobillard++",NULL);
       sys_exit(1);
    }
#ifndef WETAB
    fprintf( stderr, "Video mode set failed: %s\nSwitch to other mode\n", SDL_GetError());
    if(options_fsaa_value) {
      options_fsaa_value >>= 1;
      fprintf(stderr,"FSAA %i\n",options_fsaa_value);
      SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, options_fsaa_value);
    } else {
      SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,0);
    }
#endif
   }
#ifndef WETAB
  }
Esempio n. 26
0
void SDL_COMPAT_WM_SetIcon(SDL_Surface *icon, Uint8 *mask)
{
  SDL_WM_SetIcon(icon, mask);
}
Esempio n. 27
0
/*
===============
GLimp_SetMode
===============
*/
static int GLimp_SetMode( int mode, int fullscreen, int noborder )
{
	int                 sdlcolorbits;
	int                 colorbits, depthbits, stencilbits;
	int                 tcolorbits, tdepthbits, tstencilbits;
	int                 i = 0;
	SDL_Surface         *vidscreen = NULL;
	Uint32              flags = 0;
	const SDL_VideoInfo *videoInfo;

	ri.Printf( PRINT_ALL, "Initializing Direct3D display\n" );

	if ( r_allowResize->integer )
	{
		flags |= SDL_RESIZABLE;
	}

	if ( displayAspect == 0.0f )
	{
#if !SDL_VERSION_ATLEAST(1, 2, 10)
		// 1.2.10 is needed to get the desktop resolution
		displayAspect = 4.0f / 3.0f;
#else
		// Guess the display aspect ratio through the desktop resolution
		// by assuming (relatively safely) that it is set at or close to
		// the display's native aspect ratio
		videoInfo = SDL_GetVideoInfo();
		displayAspect = ( float ) videoInfo->current_w / ( float ) videoInfo->current_h;
#endif

		ri.Printf( PRINT_ALL, "Estimated display aspect: %.3f\n", displayAspect );
	}

	ri.Printf( PRINT_ALL, "...setting mode %d:", mode );

	if ( !R_GetModeInfo( &glConfig.vidWidth, &glConfig.vidHeight, &glConfig.windowAspect, mode ) )
	{
		ri.Printf( PRINT_ALL, " invalid mode\n" );
		return RSERR_INVALID_MODE;
	}

	ri.Printf( PRINT_ALL, " %d %d\n", glConfig.vidWidth, glConfig.vidHeight );

	if ( fullscreen )
	{
		flags |= SDL_FULLSCREEN;
		glConfig.isFullscreen = qtrue;
	}
	else
	{
		glConfig.isFullscreen = qfalse;
	}

	if ( !r_colorbits->value )
	{
		colorbits = 24;
	}
	else
	{
		colorbits = r_colorbits->value;
	}

	if ( !r_depthbits->value )
	{
		depthbits = 24;
	}
	else
	{
		depthbits = r_depthbits->value;
	}

	stencilbits = r_stencilbits->value;

	for ( i = 0; i < 16; i++ )
	{
		// 0 - default
		// 1 - minus colorbits
		// 2 - minus depthbits
		// 3 - minus stencil
		if ( ( i % 4 ) == 0 && i )
		{
			// one pass, reduce
			switch ( i / 4 )
			{
				case 2:
					if ( colorbits == 24 )
					{
						colorbits = 16;
					}

					break;

				case 1:
					if ( depthbits == 24 )
					{
						depthbits = 16;
					}
					else if ( depthbits == 16 )
					{
						depthbits = 8;
					}

				case 3:
					if ( stencilbits == 24 )
					{
						stencilbits = 16;
					}
					else if ( stencilbits == 16 )
					{
						stencilbits = 8;
					}
			}
		}

		tcolorbits = colorbits;
		tdepthbits = depthbits;
		tstencilbits = stencilbits;

		if ( ( i % 4 ) == 3 )
		{
			// reduce colorbits
			if ( tcolorbits == 24 )
			{
				tcolorbits = 16;
			}
		}

		if ( ( i % 4 ) == 2 )
		{
			// reduce depthbits
			if ( tdepthbits == 24 )
			{
				tdepthbits = 16;
			}
			else if ( tdepthbits == 16 )
			{
				tdepthbits = 8;
			}
		}

		if ( ( i % 4 ) == 1 )
		{
			// reduce stencilbits
			if ( tstencilbits == 24 )
			{
				tstencilbits = 16;
			}
			else if ( tstencilbits == 16 )
			{
				tstencilbits = 8;
			}
			else
			{
				tstencilbits = 0;
			}
		}

		sdlcolorbits = 4;

		if ( tcolorbits == 24 )
		{
			sdlcolorbits = 8;
		}

		SDL_GL_SetAttribute( SDL_GL_RED_SIZE, sdlcolorbits );
		SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, sdlcolorbits );
		SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, sdlcolorbits );
		SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, tdepthbits );
		SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, tstencilbits );
		SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

		if ( SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, r_swapInterval->integer ) < 0 )
		{
			ri.Printf( PRINT_ALL, "r_swapInterval requires libSDL >= 1.2.10\n" );
		}

#ifdef USE_ICON
		{
			SDL_Surface *icon = SDL_CreateRGBSurfaceFrom( ( void * ) CLIENT_WINDOW_ICON.pixel_data,
			                    CLIENT_WINDOW_ICON.width,
			                    CLIENT_WINDOW_ICON.height,
			                    CLIENT_WINDOW_ICON.bytes_per_pixel * 8,
			                    CLIENT_WINDOW_ICON.bytes_per_pixel * CLIENT_WINDOW_ICON.width,
#ifdef Q3_LITTLE_ENDIAN
			                    0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
#else
			                    0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
#endif
			                                            );

			SDL_WM_SetIcon( icon, NULL );
			SDL_FreeSurface( icon );
		}
#endif

		SDL_WM_SetCaption( CLIENT_WINDOW_TITLE, CLIENT_WINDOW_MIN_TITLE );
		SDL_ShowCursor( 0 );

		if ( !( vidscreen = SDL_SetVideoMode( glConfig.vidWidth, glConfig.vidHeight, colorbits, flags ) ) )
		{
			ri.Printf( PRINT_DEVELOPER, "SDL_SetVideoMode failed: %s\n", SDL_GetError() );
			continue;
		}

		//GLimp_GetCurrentContext();

		ri.Printf( PRINT_ALL, "Using %d/%d/%d Color bits, %d depth, %d stencil display.\n",
		           sdlcolorbits, sdlcolorbits, sdlcolorbits, tdepthbits, tstencilbits );

		glConfig.colorBits = tcolorbits;
		glConfig.depthBits = tdepthbits;
		glConfig.stencilBits = tstencilbits;
		break;
	}

	GLimp_DetectAvailableModes();

	if ( !vidscreen )
	{
		ri.Printf( PRINT_ALL, "Couldn't get a visual\n" );
		return RSERR_INVALID_MODE;
	}

	screen = vidscreen;

	//glstring = (char *)qglGetString(GL_RENDERER);
	//ri.Printf(PRINT_ALL, "GL_RENDERER: %s\n", glstring);

	return RSERR_OK;
}
Esempio n. 28
0
/*
===============
GLimp_SetMode
===============
*/
static int GLimp_SetMode(int mode, qboolean fullscreen, qboolean noborder)
{
	const char*   glstring;
	int sdlcolorbits;
	int colorbits, depthbits, stencilbits;
	int tcolorbits, tdepthbits, tstencilbits;
	int samples;
	int i = 0;
	SDL_Surface *vidscreen = NULL;
	Uint32 flags = SDL_OPENGL;

	ri.Printf( PRINT_ALL, "Initializing OpenGL display\n");

	if ( r_allowResize->integer )
		flags |= SDL_RESIZABLE;

	if( videoInfo == NULL )
	{
		static SDL_VideoInfo sVideoInfo;
		static SDL_PixelFormat sPixelFormat;

		videoInfo = SDL_GetVideoInfo( );

		// Take a copy of the videoInfo
		Com_Memcpy( &sPixelFormat, videoInfo->vfmt, sizeof( SDL_PixelFormat ) );
		sPixelFormat.palette = NULL; // Should already be the case
		Com_Memcpy( &sVideoInfo, videoInfo, sizeof( SDL_VideoInfo ) );
		sVideoInfo.vfmt = &sPixelFormat;
		videoInfo = &sVideoInfo;

		if( videoInfo->current_h > 0 )
		{
			// Guess the display aspect ratio through the desktop resolution
			// by assuming (relatively safely) that it is set at or close to
			// the display's native aspect ratio
			displayAspect = (float)videoInfo->current_w / (float)videoInfo->current_h;

			ri.Printf( PRINT_ALL, "Estimated display aspect: %.3f\n", displayAspect );

#ifdef __ANDROID__
			R_SetNativeModeInfo( videoInfo->current_w, videoInfo->current_h );
#endif
		}
		else
		{
			ri.Printf( PRINT_ALL,
					"Cannot estimate display aspect, assuming 1.333\n" );
		}
	}

	ri.Printf (PRINT_ALL, "...setting mode %d:", mode );

	if (mode == -2)
	{
		// use desktop video resolution
		if( videoInfo->current_h > 0 )
		{
			glConfig.vidWidth = videoInfo->current_w;
			glConfig.vidHeight = videoInfo->current_h;
		}
		else
		{
			glConfig.vidWidth = 640;
			glConfig.vidHeight = 480;
			ri.Printf( PRINT_ALL,
					"Cannot determine display resolution, assuming 640x480\n" );
		}

		glConfig.windowAspect = (float)glConfig.vidWidth / (float)glConfig.vidHeight;
	}
	else if ( !R_GetModeInfo( &glConfig.vidWidth, &glConfig.vidHeight, &glConfig.windowAspect, mode ) )
	{
		ri.Printf( PRINT_ALL, " invalid mode\n" );
		return RSERR_INVALID_MODE;
	}
	ri.Printf( PRINT_ALL, " %d %d\n", glConfig.vidWidth, glConfig.vidHeight);

	if (fullscreen)
	{
		flags |= SDL_FULLSCREEN;
		glConfig.isFullscreen = qtrue;
	}
	else
	{
		if (noborder)
			flags |= SDL_NOFRAME;

		glConfig.isFullscreen = qfalse;
	}

	colorbits = r_colorbits->value;
	if ((!colorbits) || (colorbits >= 32))
		colorbits = 24;

	if (!r_depthbits->value)
		depthbits = 24;
	else
		depthbits = r_depthbits->value;
	stencilbits = r_stencilbits->value;
	samples = r_ext_multisample->value;

	for (i = 0; i < 16; i++)
	{
		// 0 - default
		// 1 - minus colorbits
		// 2 - minus depthbits
		// 3 - minus stencil
		if ((i % 4) == 0 && i)
		{
			// one pass, reduce
			switch (i / 4)
			{
				case 2 :
					if (colorbits == 24)
						colorbits = 16;
					break;
				case 1 :
					if (depthbits == 24)
						depthbits = 16;
					else if (depthbits == 16)
						depthbits = 8;
				case 3 :
					if (stencilbits == 24)
						stencilbits = 16;
					else if (stencilbits == 16)
						stencilbits = 8;
			}
		}

		tcolorbits = colorbits;
		tdepthbits = depthbits;
		tstencilbits = stencilbits;

		if ((i % 4) == 3)
		{ // reduce colorbits
			if (tcolorbits == 24)
				tcolorbits = 16;
		}

		if ((i % 4) == 2)
		{ // reduce depthbits
			if (tdepthbits == 24)
				tdepthbits = 16;
			else if (tdepthbits == 16)
				tdepthbits = 8;
		}

		if ((i % 4) == 1)
		{ // reduce stencilbits
			if (tstencilbits == 24)
				tstencilbits = 16;
			else if (tstencilbits == 16)
				tstencilbits = 8;
			else
				tstencilbits = 0;
		}

		sdlcolorbits = 4;
		if (tcolorbits == 24)
			sdlcolorbits = 8;

#ifdef __sgi /* Fix for SGIs grabbing too many bits of color */
		if (sdlcolorbits == 4)
			sdlcolorbits = 0; /* Use minimum size for 16-bit color */

		/* Need alpha or else SGIs choose 36+ bit RGB mode */
		SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 1);
#endif

		SDL_GL_SetAttribute( SDL_GL_RED_SIZE, sdlcolorbits );
		SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, sdlcolorbits );
		SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, sdlcolorbits );
		SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, tdepthbits );
		SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, tstencilbits );

		SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, samples ? 1 : 0 );
		SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, samples );

		if(r_stereoEnabled->integer)
		{
			glConfig.stereoEnabled = qtrue;
			SDL_GL_SetAttribute(SDL_GL_STEREO, 1);
		}
		else
		{
			glConfig.stereoEnabled = qfalse;
			SDL_GL_SetAttribute(SDL_GL_STEREO, 0);
		}
		
		SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

#if 0 // See http://bugzilla.icculus.org/show_bug.cgi?id=3526
		// If not allowing software GL, demand accelerated
		if( !r_allowSoftwareGL->integer )
		{
			if( SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 ) < 0 )
			{
				ri.Printf( PRINT_ALL, "Unable to guarantee accelerated "
						"visual with libSDL < 1.2.10\n" );
			}
		}
#endif

		if( SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, r_swapInterval->integer ) < 0 )
			ri.Printf( PRINT_ALL, "r_swapInterval requires libSDL >= 1.2.10\n" );

#ifdef USE_ICON
		{
			SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(
					(void *)CLIENT_WINDOW_ICON.pixel_data,
					CLIENT_WINDOW_ICON.width,
					CLIENT_WINDOW_ICON.height,
					CLIENT_WINDOW_ICON.bytes_per_pixel * 8,
					CLIENT_WINDOW_ICON.bytes_per_pixel * CLIENT_WINDOW_ICON.width,
#ifdef Q3_LITTLE_ENDIAN
					0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
#else
					0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
#endif
					);

			SDL_WM_SetIcon( icon, NULL );
			SDL_FreeSurface( icon );
		}
#endif

		SDL_WM_SetCaption(CLIENT_WINDOW_TITLE, CLIENT_WINDOW_MIN_TITLE);
		SDL_ShowCursor(0);

		if (!(vidscreen = SDL_SetVideoMode(glConfig.vidWidth, glConfig.vidHeight, colorbits, flags)))
		{
			ri.Printf( PRINT_DEVELOPER, "SDL_SetVideoMode failed: %s\n", SDL_GetError( ) );
			continue;
		}

		opengl_context = GLimp_GetCurrentContext();

		ri.Printf( PRINT_ALL, "Using %d/%d/%d Color bits, %d depth, %d stencil display.\n",
				sdlcolorbits, sdlcolorbits, sdlcolorbits, tdepthbits, tstencilbits);

		glConfig.colorBits = tcolorbits;
		glConfig.depthBits = tdepthbits;
		glConfig.stencilBits = tstencilbits;
		break;
	}

	GLimp_DetectAvailableModes();

	if (!vidscreen)
	{
		ri.Printf( PRINT_ALL, "Couldn't get a visual\n" );
		return RSERR_INVALID_MODE;
	}

	screen = vidscreen;

	glstring = (char *) qglGetString (GL_RENDERER);
	ri.Printf( PRINT_ALL, "GL_RENDERER: %s\n", glstring );

	return RSERR_OK;
}
Esempio n. 29
0
	bool Initialize (int w, int h, bool fullScreen, System::State* StartingState, int FrameRate, std::string windowTitle, std::string iconFile){
	
	    // Initiate SDL
	    if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0 ){
			fprintf( stderr, "Video query failed: %s\n", SDL_GetError());
			exit(1);
	        return false;
		}
	    
	    atexit(SDL_Quit); // At quit, destroy SDL
		
		int flags;
		if(fullScreen)
			flags = SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | SDL_FULLSCREEN;
		else
			flags = SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF;

		Screen = SDL_SetVideoMode(w, h, 32, flags);
		if(Screen == NULL){
			fprintf( stderr, "Video mode set failed: %s\nWidth(%d), Height(%d)\n", SDL_GetError(), w, h);
			exit(1);
			return false;
		}

		/*
	    // Set up the window and video mode
	    if(fullScreen)
	        Screen = SDL_SetVideoMode(w,h,32,SDL_OPENGL|SDL_HWSURFACE|SDL_NOFRAME|SDL_DOUBLEBUF|SDL_FULLSCREEN|SDL_OPENGL);
	    else
	        Screen = SDL_SetVideoMode(w,h,32,SDL_OPENGL|SDL_HWSURFACE|SDL_NOFRAME|SDL_DOUBLEBUF|SDL_OPENGL);
	    if ( Screen == NULL )
	        return false;
		*/





		
	    
		// Set the caption of the window
		SDL_WM_SetCaption(windowTitle.c_str(), NULL);
		
		// Set the window icon
		if(iconFile != ""){
			SDL_Surface* WindowIcon = IMG_Load(iconFile.c_str());
			if(WindowIcon){
				SDL_SetColorKey(WindowIcon, SDL_SRCCOLORKEY, 
					SDL_MapRGB(WindowIcon->format, 255, 0, 255));
				SDL_WM_SetIcon(WindowIcon, NULL);
				SDL_FreeSurface(WindowIcon);
			} else {
				fprintf( stderr, "Error loading window icon file \"%s\"\n", iconFile.c_str());
			}
		}

		// Input
		System::Input::Initialize();

		// Math
		System::Math::Initialize();

		// Text
		if(System::Text::Initialize() == false){
			fprintf( stderr, "Error initializing text\n");
		}
		

		// Framerate
		SDL_initFramerate(&fpsm);
		if(FrameRate < 0) FrameRate = 1;
		SDL_setFramerate(&fpsm, FrameRate);
	    
	    // Default values
	    Width = w;
	    Height = h;
		Title = windowTitle;
		SetState(StartingState);
		Going = true;
	    
	    return true;
	}
Esempio n. 30
0
//----------------------------------------------------------------------------
bool Video::init( void)
{
    XTRACE();

    LOG_INFO << "Initializing Video..." << endl;

    if( SDL_InitSubSystem( SDL_INIT_VIDEO) < 0 )
    {
        LOG_ERROR << "Init Video: failed # " << SDL_GetError() << endl;
        return false;
    }
    LOG_INFO << "Video: OK" << endl;

    ConfigS::instance()->getInteger( "maxFPS", _maxFPS);
    if( _maxFPS)
    {
        LOG_INFO << "Video: Restricting FPS to " << _maxFPS << endl;
        _fpsStepSize = 1.0f/(float)_maxFPS;
    }

    ConfigS::instance()->getBoolean( "fullscreen", _isFullscreen);

    LOG_INFO << "Setting program icon" << endl;
    SDL_Surface *icon = SDL_LoadBMP("icon.bmp");
    if (!icon)
    {
        LOG_ERROR << "Unable to load Icon" << endl;
        return false;
    }
    SDL_WM_SetIcon(icon, NULL);

    if( !setVideoMode())
    {
        return false;
    }

    _smallFont = FontManagerS::instance()->getFont( "bitmaps/arial-small");
    if( !_smallFont)
    {
        LOG_ERROR << "Unable to get font... (arial-small)" << endl;
        SDL_QuitSubSystem( SDL_INIT_VIDEO);
        return false;
    }

    _scoreFont = FontManagerS::instance()->getFont( "bitmaps/vipnaUpper");
    if( !_scoreFont)
    {
        LOG_ERROR << "Unable to get font... (vipnaUpper)" << endl;
        SDL_QuitSubSystem( SDL_INIT_VIDEO);
        return false;
    }

    _gameOFont = FontManagerS::instance()->getFont( "bitmaps/gameover");
    if( !_gameOFont)
    {
        LOG_ERROR << "Unable to get font... (gameover)" << endl;
        SDL_QuitSubSystem( SDL_INIT_VIDEO);
        return false;
    }

    _board = BitmapManagerS::instance()->getBitmap( "bitmaps/board");
    if( !_board)
    {
        LOG_ERROR << "Unable to load CritterBoard" << endl;
        SDL_QuitSubSystem( SDL_INIT_VIDEO);
        return false;
    }
    _boardIndex = _board->getIndex( "CritterBoard");

    _titleA = ResourceManagerS::instance()->getTexture("bitmaps/titleA.png");
    if (!_titleA)
        return false;
    _titleB = ResourceManagerS::instance()->getTexture("bitmaps/titleB.png");
    if (!_titleB)
        return false;

    grabAndWarpMouse();

    LOG_INFO << "OpenGL info follows..." << endl;
    string vendor = (char*)glGetString( GL_VENDOR);
    if( vendor.find( "Brian Paul") != string::npos)
    {
        LOG_WARNING << "*** Using MESA software rendering." << endl;
    }
    LOG_INFO << "  Vendor  : " << vendor << endl;
    LOG_INFO << "  Renderer: " <<  glGetString( GL_RENDERER) << endl;
    LOG_INFO << "  Version : " << glGetString( GL_VERSION) << endl;

    glViewport(0,0, _width, _height);

#if 0
    GLfloat mat_ambient[]  = { 0.7f, 0.7f, 0.7f, 0.0f };
    GLfloat mat_diffuse[]  = { 0.6f, 0.6f, 0.6f, 0.0f };
    GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 0.0f };
#else
    GLfloat mat_ambient[]  = { 0.5f, 0.5f, 0.5f, 0.5f };
    GLfloat mat_diffuse[]  = { 0.4f, 0.4f, 0.4f, 0.5f };
    GLfloat mat_specular[] = { 0.6f, 0.6f, 0.6f, 0.5f };
#endif
    GLfloat mat_shininess[] = { 60.0f };
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);

    GLfloat mat_diffuse_b[]  = { 0.5f, 0.5f, 0.5f, 0.5f };
    GLfloat mat_ambient_b[]  = { 0.3f, 0.3f, 0.3f, 0.5f };
    GLfloat mat_specular_b[] = { 0.2f, 0.2f, 0.2f, 0.5f };
    GLfloat mat_shininess_b[] = { 10.0f };
    glMaterialfv(GL_BACK, GL_SPECULAR, mat_specular_b);
    glMaterialfv(GL_BACK, GL_SHININESS, mat_shininess_b);
    glMaterialfv(GL_BACK, GL_AMBIENT, mat_ambient_b);
    glMaterialfv(GL_BACK, GL_DIFFUSE, mat_diffuse_b);

    glClearColor(0.0, 0.0, 0.0, 0.0);

    return true;
}