• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ IMG_GetError函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中IMG_GetError函数的典型用法代码示例。如果您正苦于以下问题:C++ IMG_GetError函数的具体用法?C++ IMG_GetError怎么用?C++ IMG_GetError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了IMG_GetError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

int 
main(int argc, char* args[]) {
	
	if ( is_window_created() ) 
	{
		
		// for "libpng warning: iCCP: known incorrect sRGB profile"	
		// http://stackoverflow.com/questions/22745076/libpng-warning-iccp-known-incorrect-srgb-profile
		// load sdl2_image
		int image_flags = IMG_INIT_PNG;
		
		if ( !(IMG_Init(image_flags) & image_flags) ) 
		{
			printf("main: sdl2_image err: %s\n", IMG_GetError());
			return 1;
		}
		
		// http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_11.html
		if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
		{	
     	printf( "main: SDL_mixer Error: %s\n", Mix_GetError() );
			return 1;
    }
		
		// load sdl ttf: https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_8.html
		// if ( TTF_Init() == -1 ) {
		// 			printf("sdl2_ttf err: %s\n", TTF_GetError());
		// 			return 1;
		// 		}

		if ( !load_media() ) 
		{
			user_quit = true;
		}
		
		// the LOOP
		while	 ( !user_quit ) {
			process_events(&g_event);
			game_update();
		}
	}
	
	/** closing **/

	// Deallocate textures
	texture_free(&g_current_texture);
	
	// joystick
	// SDL_JoystickClose(g_gamepad);
	// 	g_gamepad = 0;
	
	// sfx
  Mix_FreeChunk( g_scratch );
  Mix_FreeChunk( g_hig );
  Mix_FreeChunk( g_med );
  Mix_FreeChunk( g_low );
  g_scratch = 0;
  g_hig = 0;
  g_med = 0;
  g_low = 0;

  // music
  Mix_FreeMusic( g_music );
  g_music = 0;

	SDL_DestroyRenderer(g_render);
	SDL_DestroyWindow(g_window);
	g_window = 0;
	g_render = 0;

	// https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf_10.html
	// TTF_Quit();
	Mix_Quit();
	IMG_Quit();
	SDL_Quit();
	return 0;
}
开发者ID:ofauno,项目名称:sdl2-exercises-in-c,代码行数:77,代码来源:aud.c


示例2: init

bool init()
{
	//Initialization flag
	bool success = true;

	//Initialize SDL
	if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
	{
		printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
		success = false;
	}
	else
	{
		//Set texture filtering to linear
		if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
		{
			printf( "Warning: Linear texture filtering not enabled!" );
		}

		//Create window
		gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
		if( gWindow == NULL )
		{
			printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
			success = false;
		}
		else
		{
			//Create vsynced renderer for window
			gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
//			gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED  );

			if( gRenderer == NULL )
			{
				printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
				success = false;
			}
			else
			{
				//Initialize renderer color
				SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );

				//Initialize PNG loading
				int imgFlags = IMG_INIT_PNG;
				if( !( IMG_Init( imgFlags ) & imgFlags ) )
				{
					printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
					success = false;
				}

				 //Initialize SDL_ttf
				if( TTF_Init() == -1 )
				{
					printf( "SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError() );
					success = false;
				}
			}
		}
	}

	return success;
}
开发者ID:cvg256,项目名称:SDLTestGame,代码行数:62,代码来源:24_calculating_frame_rate.cpp


示例3: SDL_GetError

	//====================
	// Methods
	//==================== 
	////////////////////////////////////////////////////////////
	bool Window::create(const std::string& title, const Vector2i& position, const Vector2i& size, const ContextSettings_t& settings)
	{
		m_title = title;
		m_position = position;
		m_size = size;

		if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO))
		{
			log.error(log.function(__FUNCTION__, title, position, size), "SDL failed to initialize:", SDL_GetError());
			return false;
		}

		if (IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG) == 0)
		{
			log.error(log.function(__FUNCTION__, title, position, size), "SDL image failed to initialize:", IMG_GetError());
			return false;
		}

		m_pWindow = SDL_CreateWindow(m_title.c_str(),
			                         m_position.x,
			                         m_position.y,
			                         m_size.x,
			                         m_size.y,
			                         SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);

		if (!m_pWindow)
		{
			log.error(log.function(title, position, size), "Failed to create window:", SDL_GetError());
			return false;
		}

		m_context = SDL_GL_CreateContext(m_pWindow);

		SDL_GL_SetSwapInterval(1);
		SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
		SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
		SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, m_settings.depthBits);
		SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, m_settings.stencilBits);
		SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, m_settings.majorVersion);
		SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, m_settings.minorVersion);

		m_running = true;
		if (!m_pMain)
		{
            glewExperimental = GL_TRUE; 
			GLenum error = glewInit();

			if (error != GLEW_OK)
			{
				log.error(log.function(__FUNCTION__, title, position, size), "GLEW failed to initialize:", glewGetErrorString(error));
				return false;
			}

			glEnable(GL_BLEND);
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

            log.debug(log.function(__FUNCTION__, title, position, size), "Main window set.");
			m_pMain = this;
		}

		glEnable(GL_DEPTH_TEST);

		log.debug(log.function(__FUNCTION__, title, position, size), "Created successfully.");
		return true;
	}
开发者ID:ShadowArkitecht,项目名称:Jackal-Engine,代码行数:70,代码来源:window.cpp


示例4: tacAssert

void TextureResource::Load()
{
    tacAssert( GetFileName() != "" );

    // load an image

    LogInfo( std::string("Loading image: ") + GetFileName() );
    mSurface = IMG_Load( (IMG_DIR + GetFileName()).c_str() );

    tacAssert( mSurface );
    if ( !mSurface )
    {
        LogError( std::string("Unable to load bitmap: ") + GetFileName() + std::string(" SDL_image error: ") + std::string( IMG_GetError() ) );
    }
}
开发者ID:cebuking0,项目名称:undefined,代码行数:15,代码来源:TextureResource.cpp


示例5: initialize

//! initialize sdl window
bool initialize()
{
  // Initialization flag
  bool success = true;

  // Initialize SDL
  if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
  {
    std::cerr << "SDL could not initialize. SDL_Error: "
	      << SDL_GetError()
	      << std::endl;
    success = false;
  }
  else
  {
    // Set texture filtering to linear
    if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
    {
      std::cerr << "Warning: Linear texture filtering not enabled!" 
		<< std::endl;
    }
    
    // Create window
    g_window = SDL_CreateWindow( "SDL Tutorial",
				 SDL_WINDOWPOS_UNDEFINED,
				 SDL_WINDOWPOS_UNDEFINED,
				 screen_width_height[0],
				 screen_width_height[1],
				 SDL_WINDOW_SHOWN );
    if( g_window == NULL )
    {
      std::cerr << "Window could not be created. SDL_Error: "
		<< SDL_GetError()
		<< std::endl;
      success = false;
    }
    else
    {
      // Create the renderer for the window
      g_renderer = SDL_CreateRenderer( g_window, -1, SDL_RENDERER_ACCELERATED);
      
      if( g_renderer == NULL )
      {
	std::cerr << "Renderer could not be created! SDL_Error: "
		  << SDL_GetError()
		  << std::endl;
	success = false;
      }
      else
      {
	// Initialize renderer color
	SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );

	// Initialize PNG loading
	int img_flags = IMG_INIT_PNG;

	if( !( IMG_Init( img_flags ) & img_flags ) )
	{
	  std::cerr << "SDL_image extension could not initialize! "
		    << "SDL_image Error: " << IMG_GetError()
		    << std::endl;
	  success = false;
	}
      }
    }
  }
  
  return success;
}
开发者ID:aprobinson,项目名称:GDev,代码行数:70,代码来源:sdl_test_12_sean.cpp


示例6: cacheLookup

Image *SDLHardwareRenderDevice::loadImage(const std::string& filename, int error_type) {
	// lookup image in cache
	Image *img;
	img = cacheLookup(filename);
	if (img != NULL) return img;

	// load image
	SDLHardwareImage *image = new SDLHardwareImage(this, renderer);
	if (!image) return NULL;

	image->surface = IMG_LoadTexture(renderer, mods->locate(filename).c_str());

	if(image->surface == NULL) {
		delete image;
		if (error_type != ERROR_NONE)
			Utils::logError("SDLHardwareRenderDevice: Couldn't load image: '%s'. %s", filename.c_str(), IMG_GetError());

		if (error_type == ERROR_EXIT) {
			Utils::logErrorDialog("SDLHardwareRenderDevice: Couldn't load image: '%s'.\n%s", filename.c_str(), IMG_GetError());
			mods->resetModConfig();
			Utils::Exit(1);
		}

		return NULL;
	}

	// store image to cache
	cacheStore(filename, image);
	return image;
}
开发者ID:clintbellanger,项目名称:flare-engine,代码行数:30,代码来源:SDLHardwareRenderDevice.cpp


示例7: cacheLookup

Image *SDLHardwareRenderDevice::loadImage(std::string filename, std::string errormessage, bool IfNotFoundExit) {
	// lookup image in cache
	Image *img;
	img = cacheLookup(filename);
	if (img != NULL) return img;

	// load image
	SDLHardwareImage *image = new SDLHardwareImage(this, renderer);
	if (!image) return NULL;

	image->surface = IMG_LoadTexture(renderer, mods->locate(filename).c_str());

	if(image->surface == NULL) {
		delete image;
		if (!errormessage.empty())
			logError("SDLHardwareRenderDevice: [%s] %s: %s", filename.c_str(), errormessage.c_str(), IMG_GetError());
		if (IfNotFoundExit) {
			Exit(1);
		}
		return NULL;
	}

	// store image to cache
	cacheStore(filename, image);
	return image;
}
开发者ID:cllpyl,项目名称:flare-engine,代码行数:26,代码来源:SDLHardwareRenderDevice.cpp


示例8: SDL_GetError

bool ColorKeyingApp::initApp()
{
	// flag to return
	bool success = true;
	
	/*****
	 * Use this function to initialize the SDL library. This must be called before using any other SDL function.
	 * INFO: http://wiki.libsdl.org/SDL_Init?highlight=%28\bCategoryAPI\b%29|%28SDLFunctionTemplate%29
	 *****/
	// Initialize SDL
	// see following for remarks on flag http://wiki.libsdl.org/SDL_Init#Remarks
	if (SDL_Init( SDL_INIT_VIDEO) < 0)
	{ 
		std::cout << "SDL ould not initalize! SDLError: " << SDL_GetError() << std::endl;
		success = false;
	}
	else 
	{
		
		//Set texture filtering to linear
		// INFO ON SDL_SetHint: see https://wiki.libsdl.org/SDL_SetHint 
		// INFO ON SDL_HINT_RENDER_SCALE_QUALITY: see https://wiki.libsdl.org/SDL_HINT_RENDER_SCALE_QUALITY?highlight=%28\bCategoryDefine\b%29|%28CategoryHints%29
		if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
		{
			std::cout << "Warning: Linear texture filtering not enabled!" << std::endl;
		}

		/*****
		 * Returns the window that was created or NULL on failure
		 * INFO: http://wiki.libsdl.org/SDL_CreateWindow?highlight=%28\bCategoryAPI\b%29|%28SDLFunctionTemplate%29
		 ******/
		// Create Window
		// INFO: see following for remarks on flags http://wiki.libsdl.org/SDL_CreateWindow#flags
		
		gWindow = SDL_CreateWindow("SDL Tutorial 10", // the title of the window in UTF-8 encoding
							SDL_WINDOWPOS_UNDEFINED, // the x position of the window
							SDL_WINDOWPOS_UNDEFINED, // the y position of the window
							SCREEN_WIDTH, // the width of the window
							SCREEN_HEIGHT, // the height of the window
							SDL_WINDOW_SHOWN // 0 or more SDL_WindowFlags OR'd together
							);
		
		if (gWindow == nullptr)
		{
			std::cout << "Window could not be created! SDL_Error:" << SDL_GetError() << std::endl;
			success = false;
		}
		else
		{
			// Get window surface
			// INFO: http://wiki.libsdl.org/SDL_GetWindowSurface?highlight=%28\bCategoryAPI\b%29|%28SDLFunctionTemplate%29
			// gScreenSurface = SDL_GetWindowSurface(gWindow);
			gCurrentRenderer = SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED);
			if (gCurrentRenderer == nullptr)
			{
				std::cout << "Renderer could not be created! SDL Error: " << SDL_GetError() << std::endl;
			}
			else
			{
				// Initalize renderer color
				SDL_SetRenderDrawColor(gCurrentRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
				
				// initialize the SDL image
				auto imgFlags = IMG_INIT_PNG;
				if (!(IMG_Init(imgFlags) && imgFlags))
				{
					std::cout << "SDL Image could not be initialized! SDL Img Error: " << IMG_GetError() << std::endl;
				}
			}
		}
		
	}
	return success;
}
开发者ID:kmokster,项目名称:lazyfoo,代码行数:74,代码来源:ColorKeyingApp.cpp


示例9: SDL_main

	int SDL_main (int argc,char* argv[]) {
#elif __APPLE__
	int SDL_main (int argc,char* argv[]) {
#else
	#ifdef main
	#undef main
	#endif
	int main(int argc,char* argv[]) {
#endif

    printf("[INFO] Entering main\n");

    uint32_t flags=SDL_INIT_VIDEO;
#ifndef WIN32
    flags|=SDL_INIT_EVENTTHREAD;
#endif
#ifdef __MACH__
	flags = SDL_INIT_EVERYTHING;
#endif
    if (SDL_Init(flags)==-1) {
        printf("SDL_Init: %s\n", SDL_GetError ());
        return -1;
    }
    screen=SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT, 32, SDL_SWSURFACE);
    if(screen == NULL) {
        printf("SDL_SetVideoMode failed!\n");
        return -2;
    }
    SDL_WM_SetCaption ("Pebble Local Simulator - 24H Style",0);
    pebbleScreen = createScreen;

    if(TTF_Init()==-1) {
        printf("TTF_Init: %s\n", TTF_GetError());
        return -3;
    }

    if (IMG_Init (IMG_INIT_PNG)==-1) {
        printf("IMG_Init: %s\n", IMG_GetError());
        return -4;
    }

    if (!loadSimulatorImages())
        return -5;
    bodyImg=getSimulatorImage(SIM_IMG_BODY);
    shadowImg=getSimulatorImage(SIM_IMG_SCREEN_SHADOW);
    vibeImg=getSimulatorImage(SIM_IMG_VIBE);
    lightImg=getSimulatorImage(SIM_IMG_BACKLIGHT);
    logFile=fopen (LOG_FILE,"a");

    if (!initRender(pebbleScreen))
        return -9;
    persistent_storage_load();
    initHardwareOutput ();
    initButtons();
    pbl_main();
    unloadSystemFonts ();
    quitRender();
    persistent_storage_free();

    if (logFile!=0)
        fclose(logFile);

    freeSimulatorImages();
    IMG_Quit ();
    TTF_Quit ();
    SDL_Quit ();
    return 0;
}
开发者ID:Shirk,项目名称:PebbleLocalSim,代码行数:68,代码来源:main.c


示例10: SDL_CreateWindow

/******************************************************************************
 * Display Initialization
******************************************************************************/
bool display::init(const math::vec2i inResolution, bool isFullScreen) {
    Uint32 windowFlags =
        SDL_WINDOW_OPENGL       |
        SDL_WINDOW_SHOWN        |
        SDL_WINDOW_INPUT_FOCUS  |
        SDL_WINDOW_MOUSE_FOCUS  |
        //SDL_WINDOW_INPUT_GRABBED|
        0;
    
    if (isFullScreen) {
        windowFlags |= SDL_WINDOW_FULLSCREEN;
    }
    
    /*
     * Create the window
     */
     pWindow = SDL_CreateWindow(
        _GAME_NAME,
        SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
        inResolution[0], inResolution[1], windowFlags
    );
    if (!pWindow) {
        std::cerr << SDL_GetError() << std::endl;
        return false;
    }
    
     /*
      * Create a renderer that will be used for the window
      */
    pRenderer = SDL_CreateRenderer(pWindow, -1, SDL_RENDERER_ACCELERATED);
    if (!pRenderer) {
        std::cerr << SDL_GetError() << std::endl;
        SDL_DestroyWindow(pWindow);
        return false;
    }
    
    /*
     * Attempt to initialize additional image format support
     */
    const int imgFlags = IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF;
    if ((IMG_Init(imgFlags)&imgFlags) != imgFlags) {
        std::cerr
            << "Warning: Unable to initialize JPG, PNG, and TIF image loaders.\n"
            << IMG_GetError()
            << std::endl;
    }
    
    /*
     * Initialize the TTF addon
     */
    if (TTF_Init() < 0) {
        std::cerr
            << "Warning: Unable to initialize the TTF add-on.\n"
            << TTF_GetError()
            << std::endl;
    }
    
    /*
     * Misc
     */
    SDL_SetRenderDrawBlendMode(pRenderer, SDL_BLENDMODE_BLEND);
    SDL_GL_SetSwapInterval(1);
    
    return true;
}
开发者ID:Night-Owl-Studios,项目名称:Giant-Slayers,代码行数:68,代码来源:display.cpp


示例11: main

int main(int argc, char **argv)
{
  // the character returned from the getopt function
  char c;

  // now loop and parse the command line options

  while( (c=getopt(argc,argv,ARGUMENTS)) !=EOF)
  {
    switch(c) // which option has been chosen
    {
      case 'h' :
        std::cout<<"TextureCompressor [filename(s)] for default DXT1 compression\n";
        std::cout<<"-e [name] to change extension from default .cmp\n";
        std::cout<<"-c [1][3][5] for DxT1 DxT3 or Dxt5 compression \n";
        std::cout<<"-v verbose \n";
        std::cout<<"it will process all files on command line\n";
        exit(EXIT_SUCCESS);

      case 'e' :
         g_ext=optarg;
      break;
      case 'v' :
        g_verbose=true;
      break;

      case '?' : // unknown option report this and exit
        // where optopt is the current option
        std::cout<<"Unknown argument "<<optopt<<std::endl;
        exit(EXIT_FAILURE);
      break;
      case 'o' :
       g_output=optarg;
      break;
      case 'c' :
        if(optarg[0]=='1')
        {
          // this is the default but set it anyway
          g_comp=DXT1;
          g_scomp=squish::kDxt1;
        }
        else if(optarg[0]=='3')
        {
          g_comp=DXT3;
          g_scomp=squish::kDxt3;
        }
        else if(optarg[0]=='5')
        {
          g_comp=DXT5;
          g_scomp=squish::kDxt5;
        }

       break;

    }

  }

  // Initialize SDL's Video subsystem
  if (SDL_Init(SDL_INIT_VIDEO) < 0 )
  {
    // Or die on error
    std::cerr<<"Problem with SDL\n";
    std::exit(EXIT_FAILURE);
  }
  // image data to load
  SDL_Surface *image;

  std::ofstream fileOut;
  fileOut.open(g_output.c_str(),std::ios::out | std::ios::binary);
  const std::string header("ngl::packtexture");
  fileOut.write(header.c_str(),header.length());
  int numFiles=0;
  // need to store this position for later so we can write out
  // the actual number of files packed.
  int numFileLocation=fileOut.tellp();
  // now write out dummy size;
  fileOut.write(reinterpret_cast<char *>(&numFiles),sizeof(int));

  for(int file=optind; file<argc; ++file)
  {
    // load current file and see if it is ok
    image=IMG_Load(argv[file]);
    if(!image)
    {
      std::cerr<<"Problem loading "<<argv[file]<<" " <<IMG_GetError()<<"\n";
      continue;
    }
    // now compress.
    createCompressedTexture(fileOut,image,argv[file]);
    // and free the image
    SDL_free(image);
    ++numFiles;
  }
  fileOut.seekp(numFileLocation,std::ios_base::beg	);
  fileOut.write(reinterpret_cast<char *>(&numFiles),sizeof(int));

  // close file
  fileOut.close();

//.........这里部分代码省略.........
开发者ID:NCCA,项目名称:TextureCompressor,代码行数:101,代码来源:main.cpp


示例12: init

  void ReinforcementPictures<T>::displayLoop()
  {
#if 0
    // initialization
    logging.info("Starting SDL init (0)..");

    SDL_Init(0);

    logging.info("Starting SDL subsystem init (events, video, audio)..");

    if(SDL_InitSubSystem(SDL_INIT_EVENTS) != 0){
      logging.error("SDL_Init(EVENTS) failed.");
      SDL_Quit();
      running = false;
      return;
    }

    if(SDL_InitSubSystem(SDL_INIT_VIDEO) != 0){
      logging.error("SDL_Init(VIDEO) failed.");
      SDL_Quit();
      running = false;
      return;
    }

    if(SDL_InitSubSystem(SDL_INIT_AUDIO) != 0){
      logging.error("SDL_Init(AUDIO) failed.");
      SDL_Quit();
      running = false;
      return;
    }

    logging.info("SDL_Init() events, video, audio successful.");
#endif
    
    // opens SDL display

    SDL_Window* window = NULL;
    
    int W = 640;
    int H = 480;

    SDL_DisplayMode mode;

    if(SDL_GetCurrentDisplayMode(0, &mode) == 0){
      W = (3*mode.w)/4;
      H = (3*mode.h)/4;
    }
    else{
      whiteice::logging.error("SDL_GetCurrentDisplayMode() failed");
      running = false;
      SDL_Quit();
      return;
    }

#if 0
    if(TTF_Init() != 0){
      char buffer[80];
      snprintf(buffer, 80, "TTF_Init failed: %s\n", TTF_GetError());
      logging.error(buffer);
      TTF_Quit();
      SDL_Quit();      
      running = false;      
      return;
    }
    else
      logging.info("Starting TTF_Init() done..");

    int flags = IMG_INIT_JPG | IMG_INIT_PNG;

    if(IMG_Init(flags) != flags){
      char buffer[80];
      snprintf(buffer, 80, "IMG_Init failed: %s\n", IMG_GetError());
      logging.error(buffer);
      IMG_Quit();
      TTF_Quit();
      SDL_Quit();
      running = false;
      return;
    }
#endif

    window = SDL_CreateWindow("Tranquility",
			      SDL_WINDOWPOS_CENTERED,
			      SDL_WINDOWPOS_CENTERED,
			      W, H,
			      SDL_WINDOW_ALWAYS_ON_TOP |
			      SDL_WINDOW_INPUT_FOCUS);

    if(window == NULL){
      whiteice::logging.error("SDL_CreateWindow() failed\n");
      running = false;
      return;
    }

    SDL_RaiseWindow(window);
    SDL_UpdateWindowSurface(window);
    SDL_RaiseWindow(window);

    // loads font
    TTF_Font* font  = NULL;
//.........这里部分代码省略.........
开发者ID:cslr,项目名称:resonanz,代码行数:101,代码来源:ReinforcementPictures.cpp


示例13: printf

bool World::InitScreen()
{
     bool run = true;
     if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
        {
            printf("Fail initialize : %s\n",SDL_GetError());
            run = false;
        }
        else
        {
            printf("Initialization Success!\n");

            if(!SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1"))
            {
                printf("Warning: VSync not enabled!\n");
                run = false;
            }

            m_window = SDL_CreateWindow(TITLE,SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,g_WINDOW_WIDTH,g_WINDOW_HEIGHT,SDL_WINDOW_SHOWN);

            if(m_window == NULL)
            {
                printf("ERROR creting Window : %s\n",SDL_GetError());
                run = false;
            }
            else
            {
                printf("Created Window .\n");

                m_render = SDL_CreateRenderer(m_window,-1,SDL_RENDERER_ACCELERATED);

                if(m_render == NULL)
                {
                    printf("Failed creating Render : %s\n",SDL_GetError());
                    run = false;
                }
                else
                {
                    printf("Creted Render.\n");
                    SDL_SetRenderDrawColor( m_render, 0xFF, 0xFF, 0xFF, 0xFF );

                    int picFlag = IMG_INIT_PNG;
                    if(!(IMG_Init(picFlag))& picFlag)
                    {
                        printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
                        run = false;
                    }
                    else
                    {
                        if(!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"))
                        {
                            printf("Warning: Scale Quality not enabled!\n");
                            run = false;
                        }
                        else
                        {
                            m_Stick1 = SDL_JoystickOpen(0);
                            if(m_Stick1 == NULL)
                            {
                                printf("Warning: 1st Joystick FAIL\n");
                            }
                            m_Stick2 = SDL_JoystickOpen(1);
                            if(m_Stick2 == NULL)
                            {
                                printf("Warning: 2nd Joystick FAIL\n");
                            }
                                if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 4, 4048 ) < 0 )
                            {
                                printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
                            }
                        }
                    }

                }
            }
        }
        m_main_music= new Sound();
        m_main_music->Init("data/music.txt");
        m_main_music->Play(true);
        SDL_JoystickEventState(SDL_ENABLE);
        return run;
}
开发者ID:nbu-gamedev,项目名称:spacewar-2014,代码行数:82,代码来源:World.cpp


示例14: SDL_GetError

/*
 * Initializes the window and set it's corresponding Surface
 */
bool        Graphics::init()
{
    bool    success;
    int     imgFlags;

    success = true;
    imgFlags = IMG_INIT_JPG | IMG_INIT_PNG;
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        success = false;
        std::cerr << "SDL could not initialize! SDL_Error: " <<  SDL_GetError() << std::endl;
    }
    else
    {
        this->_window = SDL_CreateWindow("SDL Tutorial",
                                            SDL_WINDOWPOS_UNDEFINED,
                                            SDL_WINDOWPOS_UNDEFINED,
                                            SCREEN_WIDTH,
                                            SCREEN_HEIGHT,
                                            SDL_WINDOW_SHOWN);
        if (this->_window == NULL)
        {
            success = false;
            std::cerr << "Window could not be created! SDL_Error: " << SDL_GetError() << std::endl;
        }
        else
        {
            this->_renderer = SDL_CreateRenderer(this->_window, -1, SDL_RENDERER_ACCELERATED);
            if (this->_renderer == NULL)
            {
                success = false;
                std::cerr << "Renderer could not be created! SDL Error: " << SDL_GetError() << std::endl;
            }
            else
            {
                SDL_SetRenderDrawColor(this->_renderer, 255, 0, 0, 255);
                if (!(IMG_Init(imgFlags) & imgFlags))
                {
                    std::cerr << "SDL_Image could not initialize! SDL_Image error: " << IMG_GetError() << std::endl;
                    success = false;
                }
            }
        }
    }
    return success;
}
开发者ID:oz117,项目名称:SDL_Training,代码行数:49,代码来源:Graphics.cpp


示例15: init

bool init(int screen)//0 = windowed (default), 1 = 1.5x screen, 2 = fullscreen, 3 = 1.5x fullscreen mode
{
    //Initialization flag
    bool success = true;

    //Initialize SDL
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        printf("SDL could not initialize! SDL Error: %s\n", SDL_GetError());
        success = false;
    }
    else
    {
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
        //Use OpenGL 2.1
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

        //Create window
        switch (screen) {
        case 1:
            gWindow = SDL_CreateWindow("Frictionless", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH*1.5, SCREEN_HEIGHT*1.5, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
            break;
        case 2:
            gWindow = SDL_CreateWindow("Frictionless", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN);
            break;
        case 3:
            gWindow = SDL_CreateWindow("Frictionless", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH*1.5, SCREEN_HEIGHT*1.5, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN);
            break;
        default:
            gWindow = SDL_CreateWindow("Frictionless", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
        }
        SDLNet_Init();
        if (gWindow == NULL)
        {
            printf("Window could not be created! SDL Error: %s\n", SDL_GetError());
            success = false;
        }
        else
        {
            //Create context
            gContext = SDL_GL_CreateContext(gWindow);
            if (gContext == NULL)
            {
                printf("OpenGL context could not be created! SDL Error: %s\n", SDL_GetError());
                success = false;
            }
            else
            {
                //Use Vsync
                if (SDL_GL_SetSwapInterval(0) < 0)
                {
                    printf("Warning: Unable to set VSync! SDL Error: %s\n", SDL_GetError());
                }

                //Initialize PNG loading
                int imgFlags = IMG_INIT_PNG;
                if (!(IMG_Init(imgFlags) & imgFlags))
                {
                    printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
                    success = false;
                }
                //Initialize OpenGL
                if (!initGL())
                {
                    printf("Unable to initialize OpenGL!\n");
                    success = false;
                }
            }
        }
    }

    return success;
}
开发者ID:RonWeber,项目名称:Frictionless,代码行数:75,代码来源:main.cpp


示例16: shared_object

        texture_impl::texture_impl(const string & fname, const int & format, const GLenum opengl_texture_unit, const bool compress)
            : shared_object(), name(fname), format(format), compress(compress), opengl_texture_unit(opengl_texture_unit), opengl_id(0), buffer(0)
        {
            if (!file::exists(fname))
                throw io_exception(L"Texture file %ls not found.", fname.w_string());

            SDL_Surface *surface = IMG_Load(fname.c_string());

            if (!surface)
                throw runtime_exception(L"Unable to load texture file %ls: %hs", fname.w_string(), IMG_GetError());

            buffer = new rgba_buffer(surface);

            SDL_FreeSurface(surface);
        } // texture_impl::texture_impl()
开发者ID:kulibali,项目名称:periapsis,代码行数:15,代码来源:texture.cpp


示例17: logerror

void PseuGUI::_Init(void)
{
    if(SDL_Init(SDL_INIT_VIDEO) < 0)//initialisation de la SDL
    {
       logerror("Erreur d'initialisation de la SDL : %s",SDL_GetError());
     //  return EXIT_FAILURE;
    }
	// Initialise SDL Video 
	screen =  SDL_CreateWindow("Handmade Hero",
                                          SDL_WINDOWPOS_UNDEFINED,
                                          SDL_WINDOWPOS_UNDEFINED,
                                          800,
                                          600,
                                          SDL_WINDOW_RESIZABLE);

	renderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE);
	
	
	
	/*
	/////
    // Create window and renderer.
   /// screen = SDL_CreateWindow("test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_SHOWN);

   // renderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE);
   */
    if (screen == NULL || renderer == NULL)
        {
            logerror("Impossible d'initialiser le mode écran à %d x %d: %s\n", 800, 600, SDL_GetError());
           // exit(1);
        }

	//Initialisation du chargement des images png avec la SDL 2.0 - Voir les commentaires du chapitre 9
	int imgFlags = IMG_INIT_PNG;
	if( !( IMG_Init( imgFlags ) & imgFlags ) )
	{
		logerror( "SDL_image n'a pu être initialisée! SDL_image Error: %s\n", IMG_GetError() );
		//exit(1);
	}

	// Cache le curseur de la souris 
	//SDL_ShowCursor(SDL_DISABLE);

	/* Initialise SDL_TTF */

	if (TTF_Init() < 0)
	{
		logerror("Impossible d'initialiser SDL TTF: %s\n", TTF_GetError());

	//	exit(1);
	}

	 SDL_SetRenderDrawColor( renderer, 255, 255, 255, 255 );
    

	font[0] = loadFont("./font/Kraash_Black.ttf", 48);
	font[1] = loadFont("./font/GenBasB.ttf", 24);
	font[2] = loadFont("./font/Super_Mario_Bros.ttf", 32);
	font[3] = loadFont("./font/MORPHEUS.TTF", 48);
	font[4] = loadFont("./font/MORPHEUS.TTF", 18);
	font[5] = loadFont("./font/GenBasB.TTF", 18);
	font[6] = loadFont("./font/Kraash_Black.TTF", 16);
	font[7] = loadFont("verdana.ttf", 16);
	

	//SDL_Texture *background;
	/*
    _device = createDevice(_driverType,dimension2d<u32>(_xres,_yres),_colordepth,!_windowed,_shadows,_vsync);
    if(!_device)
    {
        logerror("PseuGUI: Can't use specified video driver, trying software mode...");
        _device = createDevice(video::EDT_SOFTWARE,dimension2d<u32>(_xres,_yres),_colordepth,!_windowed,false,false);
        if(!_device)
        {
            logerror("ERROR: PseuGUI::_Init() failed, no video driver available!");
            return;
        }
        else
        {
            logerror("PseuGUI: Software mode OK!");
        }
    }
    DEBUG(logdebug("PseuGUI::Init() _device=%X",_device));
    
	
	_device->setWindowCaption(L"PseuWoW - Initializing");
    _device->setResizable(true);
	*/
    //_driver = _device->getVideoDriver();
   // _smgr = _device->getSceneManager();
   // _guienv = _device->getGUIEnvironment();
    _timer = SDL_GetTicks();
   // _screendimension = _driver->getScreenSize();

    //...

    // disable crappy irrlicht logging
 //   _device->getLogger()->setLogLevel(ELL_NONE);

    // register external loaders for not supported filetypes
//.........这里部分代码省略.........
开发者ID:supdams,项目名称:SupGame,代码行数:101,代码来源:PseuGUI.cpp


示例18: getline

//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
    lastchar = -1;
    inputdelay = -1;

    std::string typeface = "Terminus";
    std::string blending = "solid";
    std::ifstream fin;
    int faceIndex = 0;
    int fontsize = 0; //actuall size
    fin.open("data/FONTDATA");
    if (!fin.is_open()){
        fontwidth = 8;
        fontheight = 16;
        std::ofstream fout;//create data/FONDATA file
        fout.open("data/FONTDATA");
        if(fout.is_open()) {
            fout << typeface << "\n";
            fout << fontwidth << "\n";
            fout << fontheight;
            fout.close();
        }
    } else {
        getline(fin, typeface);
        fin >> fontwidth;
        fin >> fontheight;
        fin >> fontsize;
        fin >> blending;
        if ((fontwidth <= 4) || (fontheight <= 4)) {
            fontheight = 16;
            fontwidth = 8;
        }
        fin.close();
    }

    fontblending = (blending=="blended");

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;

    if(!InitSDL()) {
        DebugLog() << "Failed to initialize SDL: " << SDL_GetError() << "\n";
        return NULL;
    }

    TERMINAL_WIDTH = OPTIONS["TERMINAL_X"];
    TERMINAL_HEIGHT = OPTIONS["TERMINAL_Y"];

    if(OPTIONS["FULLSCREEN"]) {
        // Fullscreen mode overrides terminal width/height
        SDL_DisplayMode display_mode;
        SDL_GetDesktopDisplayMode(0, &display_mode);

        TERMINAL_WIDTH = display_mode.w / fontwidth;
        TERMINAL_HEIGHT = display_mode.h / fontheight;

        WindowWidth  = display_mode.w;
        WindowHeight = display_mode.h;
    } else {
        WindowWidth= OPTIONS["TERMINAL_X"];
        if (WindowWidth < FULL_SCREEN_WIDTH) WindowWidth = FULL_SCREEN_WIDTH;
        WindowWidth *= fontwidth;
        WindowHeight = OPTIONS["TERMINAL_Y"] * fontheight;
    }

    if(!WinCreate()) {
        DebugLog() << "Failed to create game window: " << SDL_GetError() << "\n";
        return NULL;
    }

    #ifdef SDLTILES
    DebugLog() << "Initializing SDL Tiles context\n";
    tilecontext = new cata_tiles(renderer);
    try {
        tilecontext->init("gfx");
        DebugLog() << "Tiles initialized successfully.\n";
    } catch(std::string err) {
        // use_tiles is the cached value of the USE_TILES option.
        // most (all?) code refers to this to see if cata_tiles should be used.
        // Setting it to false disables this from getting used.
        use_tiles = false;
    }
    #endif // SDLTILES

    #ifdef SDLTILES
    while(!strcasecmp(typeface.substr(typeface.length()-4).c_str(),".bmp") ||
          !strcasecmp(typeface.substr(typeface.length()-4).c_str(),".png")) {
        DebugLog() << "Loading bitmap font [" + typeface + "].\n" ;
        typeface = "data/font/" + typeface;
        SDL_Surface *asciiload = IMG_Load(typeface.c_str());
        if(!asciiload || asciiload->w*asciiload->h < (fontwidth * fontheight * 256)) {
            DebugLog() << "Failed to load bitmap font: " << IMG_GetError() << "\n";
            SDL_FreeSurface(asciiload);
            break;
        }
        Uint32 key = SDL_MapRGB(asciiload->format, 0xFF, 0, 0xFF);
        SDL_SetColorKey(asciiload,SDL_TRUE,key);
        SDL_Surface *ascii_surf[16];
        ascii_surf[0] = SDL_ConvertSurface(asciiload,format,0);
//.........这里部分代码省略.........
开发者ID:Tearlach,项目名称:Cataclysm-DDA,代码行数:101,代码来源:sdltiles.cpp


示例19: printf

/* Inicjacja programu wraz z ladowanie obiektow */
bool Engine::init()
{
    bool success = true;

    if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
    {
        printf( "Nie zainicjowano SDL Error %s\n", SDL_GetError() );
        success = false;
    }
    else
    {
        if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
        {
            printf( "Ostrzezenie: Liniowe filtrowanie tekstur jest wylaczone!\n " );
        }

        width = 800;
        height = 600;
        Uint32 flags = SDL_WINDOW_SHOWN;

        window = SDL_CreateWindow( "CD2", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, flags );
        if( window == NULL )
        {
            printf( "Nie utworzono okna! Error %s\n", SDL_GetError() );
            success = false;
        }
        else
        {
            int index = -1;
            Uint32 flag 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ IMG_Init函数代码示例发布时间:2022-05-30
下一篇:
C++ IMG_AddInstrumentFunction函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap