当前位置: 首页>>代码示例>>C++>>正文


C++ IMG_Load_RW函数代码示例

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


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

示例1: main

int main(int argc, char * argv[])
{
	//Load the config and apply
		//Load the configs of screen
	win_w = cfg.Load(KEY_WINWIDTH);
	win_h = cfg.Load(KEY_WINHEIGHT);
		//Load the volumn and apply
	snd.ApplyCfg(BGMCN, cfg.Load(BGMCN));
	snd.ApplyCfg(SECN,  cfg.Load(SECN));
	snd.ApplyCfg(VCECN, cfg.Load(VCECN));

	//Init
	SDL_Init(SDL_INIT_EVENTS);
	win = SDL_CreateWindow("MaikazeSekai", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, win_w, win_h, SDL_WINDOW_OPENGL);
	ren = SDL_CreateRenderer(win, -1, 0);
	SDL_RenderSetLogicalSize(ren, 1280, 720);
	blk = SDL_CreateTexture(ren, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, win_w, win_h);
		//sent the renderer to Class Image as a stage and init them with the FileMgr
	img.Init(ren, &file);
	snd.Init(&file);

    
    auto *rw = SDL_RWFromFile("z:/star.png", "r");
    auto sur = IMG_Load_RW(rw, AUTOFREE);
    auto tex = SDL_CreateTextureFromSurface(ren, sur);
    SDL_FreeSurface(sur);
    SDL_Rect rt = { 0, 0, 2362, 7087 };
    SDL_RenderCopy(ren, tex, NULL, &rt);
    SDL_RenderPresent(ren);
    SDL_DestroyTexture(tex);

    auto *rw2 = SDL_RWFromFile("z:/1.png", "r");
    auto sur2 = IMG_Load_RW(rw2, AUTOFREE);
    auto tex2 = SDL_CreateTextureFromSurface(ren, sur2);
    SDL_FreeSurface(sur2);
    SDL_Rect rt2 = { 0, 0, 800, 900 };
    SDL_RenderCopy(ren, tex2, NULL, &rt2);
    SDL_RenderPresent(ren);
    //SDL_DestroyTexture(tex);
    
	
	//
	BGM("yui.wav", 1, 0);
	BG("sample.png");
	img.OnDraw();

	//Refresh the textures on renderer
	SDL_RenderPresent(ren);
    UnLoadBG();
    //SDL_DestroyTexture()
	//Logo();
	//Title();
	SDL_Quit();
	return 0;
}
开发者ID:Amarillys,项目名称:MaikazeSekai,代码行数:55,代码来源:MaikazeSekai.cpp

示例2: get_no_cache

surface get_no_cache(const std::string& key)
{
	std::string fname = path + key;
#if defined(__ANDROID__)
	if(fname[0] == '.' && fname[1] == '/') {
		fname = fname.substr(2);
	}
	SDL_RWops *rw = sys::read_sdl_rw_from_asset(module::map_file(fname).c_str());
	surface surf;
	if(rw) {
		surf = surface(IMG_Load_RW(rw,1));
	} else {
		surf = surface(IMG_Load(module::map_file(fname).c_str()));
	}
#else
	surface surf = surface(IMG_Load(module::map_file(fname).c_str()));
#endif // ANDROID
	//std::cerr << "loading image '" << fname << "'\n";
	if(surf.get() == false || surf->w == 0) {
		std::cerr << "failed to load image '" << key << "'\n";
		throw load_image_error();
	}

	//std::cerr << "IMAGE SIZE: " << (surf->w*surf->h) << "\n";
	return surf;
}
开发者ID:DDR0,项目名称:Cube_Trains,代码行数:26,代码来源:surface_cache.cpp

示例3: Drawable

/**
* @brief Needs Debug 
* @param file_name name of the image file to load, relative to the base directory specified
* @param base_directory the base directory to use
*/
Surface::Surface(const std::string& file_name, ImageDirectory base_directory): Drawable(), internal_surface_created(true)
{
	std::string prefix = "";
	bool language_specific = false;
	
	if(base_directory == DIR_SPRITES)
	{
		prefix = "sprites/";
	}
	
	std::string prefixed_file_name = prefix + file_name;
	std::cout << prefixed_file_name << std::endl;
	size_t size;
	char* buffer;
	FileTools::data_file_open_buffer(prefixed_file_name, &buffer, &size);
	SDL_RWops* rw = SDL_RWFromMem(buffer, int(size));
	if(rw == NULL)
		std::cout << "rw didn't load\n";
	this->internal_surface = IMG_Load_RW(rw, 0);
	if(!internal_surface)
	{
		printf( "IMG_Load: %s\n", IMG_GetError());
		return;
	}
	FileTools::data_file_close_buffer(buffer);
	SDL_RWclose(rw);

	//Debug assertion
	
}
开发者ID:woodenToaster,项目名称:kirpsquest,代码行数:35,代码来源:Surface.cpp

示例4: SDL_RWFromFile

Image::Image(const char *filename) {
	SDL_RWops *image = SDL_RWFromFile(filename, "rb");
	m_surface = IMG_Load_RW(image, 1);
	
	if(!m_surface) {
		fprintf(stderr, "Failed to load image \"%s\": %s\n", filename, IMG_GetError());
		exit(EXIT_FAILURE);
	}
	
	m_width = m_surface->w;
	m_height = m_surface->h;
	
	m_texture = SDL_CreateTextureFromSurface(Window::main->renderer(), m_surface);
	if(!m_texture) {
		fprintf(stderr, "Failed to create texture from image: %s", SDL_GetError());
		exit(EXIT_FAILURE);
	}
	
	m_clipRect.x = 0;
	m_clipRect.y = 0;
	m_clipRect.w = m_width;
	m_clipRect.h = m_height;
	
	m_posRect.x = 0;
	m_posRect.y = 0;
	m_posRect.w = m_width;
	m_posRect.h = m_height;
}
开发者ID:Janacek,项目名称:Hoelia,代码行数:28,代码来源:image.cpp

示例5: SDL_RWFromMem

gcn::Image* InfraellyImageLoader::load(unsigned char *buffer, long bufferLength, bool convertToDisplayFormat){
    //make rWop out of character buffer
    SDL_RWops *source_Rwop = SDL_RWFromMem(buffer, bufferLength);

    //load the rWop into a SDL Surface
    SDL_Surface *loadedSurface = IMG_Load_RW(source_Rwop, 1);

    if (loadedSurface == NULL)
    {
        throw GCN_EXCEPTION( std::string("Unable to load image file: ") );
    }

    SDL_Surface *surface = convertToStandardFormat(loadedSurface);
    SDL_FreeSurface(loadedSurface);

    if (surface == NULL)
    {
        throw GCN_EXCEPTION( std::string("Not enough memory to load: ") );
    }

    gcn::Image *image = new gcn::SDLImage(surface, true);

    if (convertToDisplayFormat)
    {
        image->convertToDisplayFormat();
    }

    return image;
}
开发者ID:Infraelly,项目名称:old-infraelly-engine,代码行数:29,代码来源:InfraellyImageLoader.cpp

示例6: gSetError

gSurface *gLoadImage(const char *name)
{
   gSurface    *ret;
   SDL_RWops   *ops;

   if(!PHYSFS_exists(name))
   {
      gSetError("gLoadImage was unable to load the image %s", name);
      return NULL;
   }

   ops = PHYSFSRWOPS_openRead(name);
   if(!ops)
   {
      gSetError("gLoadImage was unable to load the image %s: failed _openRead", name);
      return NULL;
   }

   if(!(ret = IMG_Load_RW(ops, true)))
   {
      gSetError("gLoadImage was unable to load the image %s: %s", name, SDL_GetError());
      return NULL;
   }

   return ret;
}
开发者ID:gitustc,项目名称:d2imdev,代码行数:26,代码来源:gmainframe.c

示例7: SetWindowIcon

void SetWindowIcon(photon_window &window, const std::string &filename){
    if(PHYSFS_exists(filename.c_str())){
        auto fp = PHYSFS_openRead(filename.c_str());
        intmax_t length = PHYSFS_fileLength(fp);
        if(length > 0){
            uint8_t *buffer = new uint8_t[length];

            PHYSFS_read(fp, buffer, 1, length);

            PHYSFS_close(fp);

            SDL_RWops *rw = SDL_RWFromMem(buffer, length);
            SDL_Surface *icon = IMG_Load_RW(rw, 1);

            if(icon == nullptr){
                PrintToLog("ERROR: icon loading failed! %s", IMG_GetError());
            }

            SDL_SetWindowIcon(window.window_SDL, icon);

            SDL_FreeSurface(icon);
            delete[] buffer;
        }else{
            PrintToLog("ERROR: Unable to open image file \"%s\"!");
        }
    }else{
        PrintToLog("ERROR: Image file \"%s\" does not exist!", filename.c_str());
    }
}
开发者ID:chipgw,项目名称:photon-legacy,代码行数:29,代码来源:window_managment.cpp

示例8: read_indexed_wad_from_file

SDL_Surface *WadImageCache::image_from_desc(WadImageDescriptor& desc)
{
	SDL_Surface *surface = NULL;
	OpenedFile wad_file;
	if (open_wad_file_for_reading(desc.file, wad_file))
	{
		struct wad_header header;
		if (read_wad_header(wad_file, &header))
		{
			struct wad_data *wad;
			wad = read_indexed_wad_from_file(wad_file, &header, desc.index, true);
			if (wad)
			{
				void *data;
				size_t length;
				data = extract_type_from_wad(wad, desc.tag, &length);
				if (data && length)
				{
					SDL_RWops *rwops = SDL_RWFromConstMem(data, length);
#ifdef HAVE_SDL_IMAGE
					surface = IMG_Load_RW(rwops, 1);
#else
					surface = SDL_LoadBMP_RW(rwops, 1);
#endif
				}
				free_wad(wad);
			}
		}
		close_wad_file(wad_file);
	}
	clear_game_error();
	return surface;
}
开发者ID:blezek,项目名称:marathon-ios,代码行数:33,代码来源:WadImageCache.cpp

示例9: img_read

int img_read(char *filein) {

	SDL_PixelFormat *fmt;   // we need that to determine which BPP
	SDL_RWops *rw;

	if (g_statics.debug) {
		printf("Reading from %s\n", filein);
		fflush(stdout);
	}

	if (!strcmp(filein, "-")) { // stdin as input. Shouldn't work but we try anyways
		rw = SDL_RWFromFP(stdin, 0);
	} else { // a regular file name
		rw = SDL_RWFromFile(filein, "rb");
	}

	g_statics.image_in = IMG_Load_RW(rw, 0);
	if (g_statics.image_in == NULL) {
		fprintf(stderr, "ERROR: %s\n", SDL_GetError());
		SDL_FreeRW(rw);
		return(-1);
	}

	// check if image is in 8bpp format
	fmt = g_statics.image_in->format;
	if (fmt->BitsPerPixel != 8) {
		fprintf(stderr, "ERROR: the image file is not in 8 bpp. Please convert it.\n");
		SDL_FreeSurface(g_statics.image_in);
		SDL_FreeRW(rw);
		return(-1);
	}

	if (g_statics.image_in->w != 192 || g_statics.image_in->h != 192) {
		fprintf(stderr, "ERROR: The image file is not 192x192 pixels. Please modify it.\n");
		SDL_FreeSurface(g_statics.image_in);
		SDL_FreeRW(rw);
		return(-1);
	}

	if (g_statics.debug > 1) {
		printf("The image file uses %d colours\n", fmt->palette->ncolors);
		fflush(stdout);
	}

	if ((g_variables.image_out = SDL_CreateRGBSurfaceFrom(g_statics.image_in->pixels, g_statics.image_in->w, g_statics.image_in->h, g_statics.image_in->pitch, g_statics.image_in->format->BitsPerPixel, 0, 0, 0, 0)) == NULL) {
		fprintf(stderr, "ERROR: %s", SDL_GetError());
		return(-1);
	}

	// need to convert the image using proper values for format, since there is a strong likelyhood to have more colours in the palette than for image_in.
	// algo: create proper palette, retrieve number of colours
	//       update image_in->format->palette with new info
	//       launch SDL_ConvertSurface

	g_variables.image_out = SDL_ConvertSurface(g_variables.image_out, g_statics.image_in->format, SDL_SWSURFACE);

	// a bit of clean up
	SDL_FreeRW(rw);
	return(0);
}
开发者ID:exult,项目名称:exult,代码行数:60,代码来源:image.c

示例10: SDL_RWFromMem

//
// TextureResourceLoader::VLoadResource				- Chapter 14, page 492
//
bool TextureResourceLoader::VLoadResource( char *rawBuffer, unsigned int rawSize, shared_ptr<ResHandle> handle )
   {
 	Renderer renderer = EngineApp::GetRendererImpl();
	if ( renderer == Renderer::Renderer_OpenGL )
	   {
		
      SDL_RWops* p_RWops = SDL_RWFromMem( rawBuffer, rawSize );
      if( !p_RWops )
         {
         ENG_ERROR( SDL_GetError() );
         return false;
         }
      SDL_Surface* p_Surface = IMG_Load_RW( p_RWops, 0 );
      if( SDL_RWclose( p_RWops ) )
         {
         ENG_WARNING( SDL_GetError() );
         }
      if( !p_Surface )
         {
         ENG_ERROR( SDL_GetError() );
         return false;
         }
      shared_ptr<SDLTextureResourceExtraData> extra = shared_ptr<SDLTextureResourceExtraData>( ENG_NEW SDLTextureResourceExtraData() );
      extra->m_pSurface = p_Surface;
      handle->SetExtraData( extra );
      handle->SetSize( extra->m_pSurface->w * extra->m_pSurface->h * extra->m_pSurface->format->BytesPerPixel );
	   }

	return true;
   }
开发者ID:scw000000,项目名称:Engine,代码行数:33,代码来源:TextureResource.cpp

示例11: IMG_Load_RW

gcn::Image* InfraellyImageLoader::load(SDL_RWops *source_Rwop, bool freeRWOP, bool convertToDisplayFormat){
    //load the rWop into a SDL Surface
    SDL_Surface *loadedSurface = IMG_Load_RW(source_Rwop, freeRWOP);

    if (loadedSurface == NULL)
    {
        throw GCN_EXCEPTION( std::string("Unable to load image file: ") );
    }

    SDL_Surface *surface = convertToStandardFormat(loadedSurface);
    SDL_FreeSurface(loadedSurface);

    if (surface == NULL)
    {
        throw GCN_EXCEPTION( std::string("Not enough memory to load: ") );
    }

    gcn::Image *image = new gcn::SDLImage(surface, true);

    if (convertToDisplayFormat)
    {
        image->convertToDisplayFormat();
    }

    return image;
}
开发者ID:Infraelly,项目名称:old-infraelly-engine,代码行数:26,代码来源:InfraellyImageLoader.cpp

示例12: LoadTextureFromFile

SDL_Texture* LoadTextureFromFile(const String &file, SDL_Renderer *renderer)
{
	SDL_Texture *texture = nullptr;
	SDL_Surface *loadedImage = nullptr;

	//android
	#if defined(__ANDROID__)
		SDL_RWops *f = SDL_RWFromFile(file.c_str(), "rb");
		loadedImage = IMG_Load_RW(f , 1);

		if(f > 0)
			__android_log_write(ANDROID_LOG_INFO, "Chain Drop", "File Loaded");
	#elif defined(_WIN32)
		loadedImage = IMG_Load(file.c_str());
	#endif

	//If the loading went ok, convert to texture and return the texture
	if (loadedImage != nullptr)
	{
		texture = SDL_CreateTextureFromSurface(renderer, loadedImage);
		SDL_FreeSurface(loadedImage);
		//Make sure converting went ok too
		if (texture == nullptr)
			logSDLError(std::cout, "LoadTextureFromFile");
	}
	else
		logSDLError(std::cout, "LoadTextureFromFile");

	return texture;
}
开发者ID:ghronkrepps,项目名称:textures,代码行数:30,代码来源:SDLUtil.cpp

示例13: is

void ResourceFile::load(std::string source)
{
	std::ifstream is(source.c_str(), std::ifstream::binary);
	ResourceMarker marker = ResourceMarker();

	while(!is.eof())
	{
		is.read( (char*) &marker, sizeof(ResourceMarker) );
		int rlength = marker.length;
		std::string rname = marker.name;

		char * buffer = new char[rlength];

		is.read(buffer, rlength);

		SDL_RWops *rw = SDL_RWFromMem(buffer, rlength);

		SDL_Surface *sdlSurface = IMG_Load_RW(rw, 1);

		Surface *surface = new Surface(sdlSurface);
		surface->setReleaseSurface(true);
		std::cout << IMG_GetError() << std::endl;

		//some error handling to do here

		delete buffer;

		resources.insert(std::make_pair(rname, surface));
	}

	is.close();
}
开发者ID:jordsti,项目名称:stigame,代码行数:32,代码来源:ResourceFile.cpp

示例14: SDL_RWFromMem

/**\brief Load image from buffer
 */
bool Image::Load( char *buf, int bufSize ) {
	SDL_RWops *rw;
	SDL_Surface *s = NULL;

	rw = SDL_RWFromMem( buf, bufSize );
	if( !rw ) {
		LogMsg(WARN, "Image loading failed. Could not create RWops" );
		return( false );
	}

	s = IMG_Load_RW( rw, 0 );
	SDL_FreeRW(rw);

	if( !s ) {
		LogMsg(WARN, "Image loading failed. Could not load image from RWops" );
		return( false );
	}

	w = s->w;
	h = s->h;

	if( ConvertToTexture( s ) == false ) {
		LogMsg(WARN, "Failed to load image from buffer" );
		SDL_FreeSurface( s );
		return( false );
	}


	return( true );
}
开发者ID:DuMuT6p,项目名称:Epiar,代码行数:32,代码来源:image.cpp

示例15: memcpy

GLuint Graphic::LoadTexture( const char* src, GLfloat *texcoord, Uint32* width, Uint32* height) {
    static std::pair<GLuint, TexCoordArray> dat;
    tex_iter iter = texMap.find(src);
    GLuint texture;
    if (iter != texMap.end()) {
        texture = iter->second.first;
        memcpy(texcoord, iter->second.second.data, 4 * sizeof(GLfloat));
        *width = iter->second.second.w;
        *height = iter->second.second.h;
    } else {
        SDL_Surface *surface = IMG_Load_RW(Storage::GetInstance()->OpenIFile(src), 1);
        if (!surface) {
            char buf[256];
            snprintf(buf, sizeof(buf), "Load file failed: %s", src);
            throw Exception(buf);
        }
        texture = SDL_GL_LoadTexture(surface, texcoord);
        if (texture == 0) {
            throw Exception("failed create texture.");
        }
        dat.first = texture;
        memcpy(dat.second.data, texcoord, 4*sizeof(GLfloat));
        dat.second.w = *width = surface->w;
        dat.second.h = *height = surface->h;
        texMap[src] = dat;
        SDL_FreeSurface(surface);

    }
    return texture;
}
开发者ID:resty-daze,项目名称:game-make,代码行数:30,代码来源:Graphic.cpp


注:本文中的IMG_Load_RW函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。