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

C++ SDL_RWFromFile函数代码示例

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

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



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

示例1: snprintf

SDL_Surface *GetCIcon(FrameBuf *screen, short cicn_id)
{
	char file[256];
	DataDir data_dir;
	SDL_Surface *cicn;
	SDL_RWops *cicn_src;
	Uint8 *pixels, *mask;
	Uint16 w, h;
	
	/* Open the cicn sprite file.. */
	snprintf(file, sizeof(file), "Images/Maelstrom_Icon#%hd.cicn", cicn_id);
	if ( (cicn_src=SDL_RWFromFile(data_dir.FullPath(file), "r")) == NULL ) {
		error("GetCIcon(%hd): Can't open CICN %s: ",
					cicn_id, data_dir.FullPath(file));
		return(NULL);
	}

	w = SDL_ReadBE16(cicn_src);
	h = SDL_ReadBE16(cicn_src);
        pixels = new Uint8[w*h];
        if ( SDL_RWread(cicn_src, pixels, 1, w*h) != (w*h) ) {
		error("GetCIcon(%hd): Corrupt CICN!\n", cicn_id);
		delete[] pixels;
		SDL_RWclose(cicn_src);
		return(NULL);
	}
        mask = new Uint8[(w/8)*h];
        if ( SDL_RWread(cicn_src, mask, 1, (w/8)*h) != ((w/8)*h) ) {
		error("GetCIcon(%hd): Corrupt CICN!\n", cicn_id);
		delete[] pixels;
		delete[] mask;
		SDL_RWclose(cicn_src);
		return(NULL);
	}
	SDL_RWclose(cicn_src);

	cicn = screen->LoadImage(w, h, pixels, mask);
	delete[] pixels;
	delete[] mask;
	if ( cicn == NULL ) {
		error("GetCIcon(%hd): Couldn't convert CICN!\n", cicn_id);
	}
	return(cicn);
}
开发者ID:MaddTheSane,项目名称:maelstrom,代码行数:44,代码来源:load.cpp


示例2: load_SRAM

/* Given a file_path and buffer, attempts to load save data into the buffer
 * up to the suppled size in bytes. Returns the size of the file if successful, 
 * returns 0 if unsuccessful. Buffer should at least be of length size*/
unsigned long load_SRAM(const char *file_path, unsigned char *data, unsigned long size) {
    
    log_message(LOG_INFO, "Attempting to load SRAM for file: %s\n",file_path);
    
    SDL_RWops *rw = SDL_RWFromFile(file_path, "rb");
    
    if (rw == NULL) {
        log_message(LOG_ERROR, 
            "Error opening file %s: %s\n", file_path, SDL_GetError());       
        return 0;
    }

    Sint64 res_size = SDL_RWsize(rw);
    if (res_size > size) {
        log_message(LOG_ERROR,
            "Error opening file %s: File is too large to be SRAM snapshot\n",
            file_path);
        return 0;
    }

    if (res_size == 0) {
        log_message(LOG_WARN, "File %s has a size of 0 bytes\n", file_path);
        return 0;
    }

    Sint64 nb_read_total = 0, nb_read = 1;
    unsigned char* buf = data;
    while (nb_read_total < res_size && nb_read != 0) {
            nb_read = SDL_RWread(rw, buf, 1, (res_size - nb_read_total));
            nb_read_total += nb_read;
            buf += nb_read;
    }

        SDL_RWclose(rw);
        if (nb_read_total != res_size) {
                log_message(LOG_ERROR, 
                    "Bytes expected (%lu) is not equal to bytes read (%lu)\n",
                    res_size, nb_read_total);
                free(data);
                return 0;
        }
    
    return res_size;
}
开发者ID:RossMeikleham,项目名称:PlutoBoy,代码行数:47,代码来源:files.c


示例3: SDL_RWFromFile

void SdlAudio::BGM_Play(std::string const& file, int volume, int /* pitch */, int fadein) {
	std::string const path = FileFinder::FindMusic(file);
	if (path.empty()) {
		Output::Debug("Music not found: %s", file.c_str());
		return;
	}

	SDL_RWops *rw = SDL_RWFromFile(path.c_str(), "rb");
#if SDL_MIXER_MAJOR_VERSION>1
	bgm.reset(Mix_LoadMUS_RW(rw, 1), &Mix_FreeMusic);
#else
	bgm.reset(Mix_LoadMUS_RW(rw), &Mix_FreeMusic);
#endif
	if (!bgm) {
		Output::Warning("Couldn't load %s BGM.\n%s\n", file.c_str(), Mix_GetError());
		return;
	}
#if SDL_MAJOR_VERSION>1
	// SDL2_mixer produces noise when playing wav.
	// Workaround: Use Mix_LoadWAV
	// https://bugzilla.libsdl.org/show_bug.cgi?id=2094
	if (bgs_playing) {
		BGS_Stop();
	}
	if (Mix_GetMusicType(bgm.get()) == MUS_WAV) {
		BGM_Stop();
		BGS_Play(file, volume, 0, fadein);
		return;
	}
#endif

	BGM_Volume(volume);
	if (!me_stopped_bgm &&
#ifdef _WIN32
	    (Mix_GetMusicType(bgm.get()) == MUS_MID && WindowsUtils::GetWindowsVersion() >= 6
	     ? Mix_PlayMusic(bgm.get(), -1) : Mix_FadeInMusic(bgm.get(), -1, fadein))
#else
	     Mix_FadeInMusic(bgm.get(), -1, fadein)
#endif
	     == -1) {
		Output::Warning("Couldn't play %s BGM.\n%s\n", file.c_str(), Mix_GetError());
		return;
	}
}
开发者ID:glynnc,项目名称:Player,代码行数:44,代码来源:sdl_audio.cpp


示例4: SDL_RWFromFile

    void Map::loadFromFile(const std::string filename){
        this->map = new Tmx::Map();
        this->map->ParseFile(filename);

        if(map->HasError() == true) { throw map->GetErrorText(); }
        if(this->renderer == nullptr) { throw new ExNoRenderer(); }
        
        // Load image files
        const std::vector<Tmx::Tileset*>& tileSets = map->GetTilesets();
        for(int i = 0; i < tileSets.size(); ++i) {
            const Tmx::Tileset * tileSet = tileSets[i];
            const Tmx::Image * image = tileSet->GetImage();
            const std::string source = image->GetSource();
            SDL_RWops * rwop = SDL_RWFromFile(source.c_str(),"r");
            SDL_Surface * surf = IMG_LoadPNG_RW(rwop);
            SDL_Texture * tex = SDL_CreateTextureFromSurface(this->renderer, surf);
            this->images.push_back(tex);
        }
    }
开发者ID:agharbin,项目名称:tiler,代码行数:19,代码来源:tiler.cpp


示例5: init_gaia

int init_gaia(void)
{
  struct SDL_Surface *Z;
  struct SDL_RWops *F;
  Sint32 w;
  int i, x=0;

  
  if( (F = SDL_RWFromFile("data/hblk01.dat","r")) == NULL)
    abend(0);

  for(i=0; i < 256*6; i++) {
    w = SDL_ReadLE32(F);
    w = (w < 6144)? 0: (w - 6144) / 320;
    subtile_table[i] = w;
    x = (w > x)? w : x;
  }
  printf("Gaia tile module:\n  +  %d unique subtiles.\n", x);
  x++;
  
  if(!(Z = CreateZSurface(get_pal("data/hpal01.dat"), 32,16*x)) )
    SDL_RWclose(F), abend(0);

  load_subtiles(F, Z->pixels, x);
  if(1) subtiles = Z;
  else {
    if( (subtiles = SDL_CreateRGBSurface(SDL_HWSURFACE,
					 32,16*x,32,
					 RR,GG,BB,AA)) )
      SDL_BlitSurface(Z, NULL, subtiles, NULL);
    SDL_FreeSurface(Z);
  }

  SDL_RWclose(F);

  lua_pushnumber(L, SCALE); lua_setfield(L, LUA_GLOBALSINDEX, "scale");
  lua_register(L, "s2m", s2m);
  lua_register(L, "m2s", m2s);

  REG_CLASS(L, map);

  return subtiles != NULL;
}
开发者ID:ashur-xx,项目名称:FreeSynd,代码行数:43,代码来源:gaia.c


示例6: SDL_RWFromFile

/*static*/ bool	tqt::is_tqt_file(const char* filename)
// Return true if the given file looks like a .tqt file of our
// appropriate version.  Do this by attempting to read the header.
{
	SDL_RWops*	in = SDL_RWFromFile(filename, "rb");
	if (in == NULL) {
		return false;
	}

	// Read header.
	tqt_header_info	info = read_tqt_header_info(in);
	SDL_RWclose(in);

	if (info.m_version != TQT_VERSION) {
		return false;
	}
	
	return true;
}
开发者ID:moltenguy1,项目名称:deusexmachina,代码行数:19,代码来源:tqt.cpp


示例7: BAIL_IF_MACRO

Sound_Sample *Sound_NewSampleFromFile(const char *filename,
                                      Sound_AudioInfo *desired,
                                      Uint32 bufferSize)
{
    const char *ext;
    SDL_RWops *rw;

    BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
    BAIL_IF_MACRO(filename == NULL, ERR_INVALID_ARGUMENT, NULL);

    ext = strrchr(filename, '.');
    rw = SDL_RWFromFile(filename, "rb");
    BAIL_IF_MACRO(rw == NULL, SDL_GetError(), NULL);

    if (ext != NULL)
        ext++;

    return(Sound_NewSample(rw, ext, desired, bufferSize));
} /* Sound_NewSampleFromFile */
开发者ID:ptitSeb,项目名称:SDL_sound,代码行数:19,代码来源:SDL_sound.c


示例8: open_font

static int open_font(lua_State * L) {
	const char * filename;
	lua_Integer fontsize;
	TTF_Font * font;
	TTF_Font ** ud;
	char adjusted_filename[MAX_ADJUSTED_FILENAME_LEN];
	SDL_RWops * file;
	
	filename = luaL_checkstring(L, 1);
	prepend_data_path(adjusted_filename, filename, MAX_ADJUSTED_FILENAME_LEN);
	file = SDL_RWFromFile(adjusted_filename, "rt");
	fontsize = luaL_checkinteger(L, 2);
	font = TTF_OpenFontRW(file, 1, fontsize);
	if (!font) fatal(TTF_GetError());
	ud = (TTF_Font **) lua_newuserdata(L, sizeof(TTF_Font *));
	if (ud == NULL) fatal("ud NULL in open_font");
	*ud = font;
	return 1;
}
开发者ID:cbhuber,项目名称:Games,代码行数:19,代码来源:font.c


示例9: SDL_RWFromFile

BaseD::Profile::Profile(const char* spc_filename)
{
  is_profiling = true;
  old_gain_db = BaseD::player->gain_db;
  BaseD::player->pause(1, true, false);
  BaseD::reload();
  BaseD::player->pause(0, false, false);
  BaseD::player->pause(1, false, false);
  //BaseD::player->restart_track();
  // Set Volume to 0
  player->set_gain_db(Music_Player::min_gain_db, true);
  // get pointer to spc_file_t
  // open the SPC File
  //DEBUGLOG("spc file path = %s\n", BaseD::g_cfg.playlist[BaseD::g_cur_entry]);
  //const char *spc_filename = BaseD::g_cfg.playlist[BaseD::g_cur_entry];
  // need to open a file
  SDL_RWops *orig_spc_file = SDL_RWFromFile(spc_filename, "rb");
  if (orig_spc_file == NULL)
  {
    sprintf(BaseD::tmpbuf, "Warning: Unable to open file %s!\n %s", spc_filename, SDL_GetError() );
    SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
                   "Could not open FILE!",
                   BaseD::tmpbuf,
                   NULL);
    //return -1;
    is_profiling=false;
    delete this;
  }

  if (SDL_RWread(orig_spc_file, orig_spc_state, Snes_Spc::spc_file_size, 1) == 0)
  {
    sprintf(BaseD::tmpbuf, "Warning: Unable to read file %s!\n %s", spc_filename, SDL_GetError() );
    SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
                   "Could not read file!",
                   BaseD::tmpbuf,
                   NULL);
    SDL_RWclose(orig_spc_file);
    //return -1;
    is_profiling=false;
    delete this;
  }
  else SDL_RWclose(orig_spc_file);
}
开发者ID:MisterZeus,项目名称:SNES-Tracker,代码行数:43,代码来源:BaseD.cpp


示例10: sizeof

void *inhale_file(const char *name, Uint32 blk, Uint32 off)
{
  struct SDL_RWops *F = NULL;
  Uint32 x, *n;
  void *p;

  if(!(F = SDL_RWFromFile(name,"r"))) abend(0);

  /* determine size */
  x = SDL_RWseek(F, 0, SEEK_END), SDL_RWseek(F, 0, SEEK_SET);
  off += sizeof(Uint32);

  if((n = p = malloc(off+x)) == NULL) abend(0);

  *n = SDL_RWread(F, p+off, blk, x/blk);
  SDL_RWclose(F);

  return p;
}
开发者ID:ashur-xx,项目名称:FreeSynd,代码行数:19,代码来源:munin.c


示例11: raw_save_file

void raw_save_file(terrain* t, char* filename) {
  
  SDL_RWops* file = SDL_RWFromFile(filename, "wb");
  
  if (!file) {
    error("Could not load file %s\n", filename);
  }
  
  uint16_t* pixels = malloc(sizeof(uint16_t) * t->width * t->height);
  
  for(int i = 0; i < t->width * t->height; i++) {
    pixels[i] = t->heightmap[i] * (65536.0 / MAX_HEIGHT);
  }
  
  SDL_RWwrite(file, pixels, sizeof(uint16_t) * t->width * t->height, 1);
  
  SDL_RWclose(file);
  
}
开发者ID:ghosthamlet,项目名称:Corange,代码行数:19,代码来源:terrain.c


示例12: close

void close()
{
	//Open data for writing
	SDL_RWops* file = SDL_RWFromFile( "33_file_reading_and_writing/nums.bin", "w+b" );
	if( file != NULL )
	{
		//Save data
		for( int i = 0; i < TOTAL_DATA; ++i )
		{
			SDL_RWwrite( file, &gData[ i ], sizeof(Sint32), 1 );
		}

		//Close file handler
		SDL_RWclose( file );
	}
	else
	{
		printf( "Error: Unable to save file! %s\n", SDL_GetError() );
	}

	//Free loaded images
	gPromptTextTexture.free();
	for( int i = 0; i < TOTAL_DATA; ++i )
	{
		gDataTextures[ i ].free();
	}

	//Free global font
	TTF_CloseFont( gFont );
	gFont = NULL;

	//Destroy window	
	SDL_DestroyRenderer( gRenderer );
	SDL_DestroyWindow( gWindow );
	gWindow = NULL;
	gRenderer = NULL;

	//Quit SDL subsystems
	TTF_Quit();
	IMG_Quit();
	SDL_Quit();
}
开发者ID:aatwo,项目名称:TestProjects,代码行数:42,代码来源:33_file_reading_and_writing.cpp


示例13: DISKAUD_OpenDevice

static int
DISKAUD_OpenDevice(_THIS, const char *devname, int iscapture)
{
    const char *envr = SDL_getenv(DISKENVR_WRITEDELAY);
    const char *fname = DISKAUD_GetOutputFilename(devname);

    this->hidden = (struct SDL_PrivateAudioData *)
        SDL_malloc(sizeof(*this->hidden));
    if (this->hidden == NULL) {
        SDL_OutOfMemory();
        return 0;
    }
    SDL_memset(this->hidden, 0, sizeof(*this->hidden));

    /* Open the audio device */
    this->hidden->output = SDL_RWFromFile(fname, "wb");
    if (this->hidden->output == NULL) {
        DISKAUD_CloseDevice(this);
        return 0;
    }

    /* Allocate mixing buffer */
    this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
    if (this->hidden->mixbuf == NULL) {
        DISKAUD_CloseDevice(this);
        return 0;
    }
    SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);

    this->hidden->mixlen = this->spec.size;
    this->hidden->write_delay =
        (envr) ? SDL_atoi(envr) : DISKDEFAULT_WRITEDELAY;

#if HAVE_STDIO_H
    fprintf(stderr,
            "WARNING: You are using the SDL disk writer audio driver!\n"
            " Writing to file [%s].\n", fname);
#endif

    /* We're ready to rock and roll. :-) */
    return 1;
}
开发者ID:0xD34D,项目名称:supermariowar-android,代码行数:42,代码来源:SDL_diskaudio.c


示例14: get_standard_rwop

static SDL_RWops* get_standard_rwop(PyObject* obj)
{
	if(PyString_Check(obj) || PyUnicode_Check(obj))
	{
		int result;
		char* name;
		PyObject* tuple = PyTuple_New(1);
		PyTuple_SET_ITEM(tuple, 0, obj);
		Py_INCREF(obj);
		if(!tuple) return NULL;
		result = PyArg_ParseTuple(tuple, "s", &name);
		Py_DECREF(tuple);
		if(!result)
			return NULL;
		return SDL_RWFromFile(name, "rb");
	}
	// else if(PyFile_Check(obj))
        //     return SDL_RWFromFP(PyFile_AsFile(obj), 0);
        return NULL;
}
开发者ID:FractalBobz,项目名称:renpy,代码行数:20,代码来源:rwobject.c


示例15: extract_fork

static void extract_fork(SDL_RWops *fin, int req_id, const char *file_name, const char *fork_name)
{
	long id, fork_start, fork_size;
	int num_entries, fork_found;
	SDL_RWops *fout;

	// Look for fork in source file
	SDL_RWseek(fin, 0x18, SEEK_SET);
	num_entries = SDL_ReadBE16(fin);
	while (num_entries--) {
		Uint32 id = SDL_ReadBE32(fin);
		Sint32 ofs = SDL_ReadBE32(fin);
		Sint32 len = SDL_ReadBE32(fin);
		if (id == req_id) {
			fork_found = 1;
			fork_start = ofs;
			fork_size = len;
		}
	}
	if (!fork_found) {
		fprintf(stderr, "Warning: source file doesn't contain a %s fork.\n", fork_name);
		return;
	}

	// Found, open destination file
	fout = SDL_RWFromFile(file_name, "wb");
	if (fout == NULL) {
		perror("Can't open destination file");
		exit(1);
	}

	// Copy fork
	SDL_RWseek(fin, fork_start, SEEK_SET);
	while (fork_size) {
		long length = fork_size > BUFFER_SIZE ? BUFFER_SIZE : fork_size;
		SDL_RWread(fin, buffer, 1, length);
		SDL_RWwrite(fout, buffer, 1, length);
		fork_size -= length;
	}
	SDL_FreeRW(fout);
}
开发者ID:0x7F800000,项目名称:Aleph-NONE,代码行数:41,代码来源:single2forks.c


示例16: lut_load_file

texture* lut_load_file( char* filename ) {
  
  SDL_RWops* file = SDL_RWFromFile(filename, "r");
  if(file == NULL) {
    error("Cannot load file %s", filename);
  }
  
  long size = SDL_RWseek(file,0,SEEK_END);
  unsigned char* contents = malloc(size+1);
  contents[size] = '\0';
  SDL_RWseek(file, 0, SEEK_SET);
  SDL_RWread(file, contents, size, 1);
  
  SDL_RWclose(file);
  
  int head = sizeof("CORANGE-LUT")-1;
  int lut_size = (unsigned char)contents[head] | (unsigned char)contents[head + 1];
  
  int offset = head + 3;
  
  texture* t = malloc(sizeof(texture));
  
  texture tex_id;
  glEnable(GL_TEXTURE_3D);
  glGenTextures(1, &tex_id);
  glBindTexture(GL_TEXTURE_3D, tex_id);
  glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, lut_size, lut_size, lut_size, 0, GL_RGB, GL_UNSIGNED_BYTE, contents + offset);
  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_MIRRORED_REPEAT);
  glDisable(GL_TEXTURE_3D);
  
  *t = tex_id;
  
  free(contents);
  
  return t;
  
}
开发者ID:Bevilacqua,项目名称:Corange,代码行数:41,代码来源:texture.c


示例17: load_rom_from_file

/*  Given a file_path and buffer to store file data in, attempts to
 *  read the file into the buffer. Returns the size of the file if successful,
 *  returns 0 if unsuccessful. Buffer should be at minimum of size "MAX_FILE_SIZE"*/
unsigned long load_rom_from_file(const char* filename, unsigned char *data) {
        SDL_RWops *rw = SDL_RWFromFile(filename, "rb");
        
        if (rw == NULL) {
            log_message(LOG_ERROR, 
                "Error opening file %s: %s\n", filename, SDL_GetError());       
            return 0;
        }

        Sint64 res_size = SDL_RWsize(rw);
        if (res_size > MAX_FILE_SIZE) {
            log_message(LOG_ERROR,
                "Error opening file %s: File is too large to be a Gameboy ROM\n",
                filename);
            return 0;
        }

        if (res_size == 0) {
            log_message(LOG_WARN, "File %s has a size of 0 bytes\n", filename);
            return 0;
        }

        Sint64 nb_read_total = 0, nb_read = 1;
        unsigned char* buf = data;
        while (nb_read_total < res_size && nb_read != 0) {
                nb_read = SDL_RWread(rw, buf, 1, (res_size - nb_read_total));
                nb_read_total += nb_read;
                buf += nb_read;
        }

        SDL_RWclose(rw);
        if (nb_read_total != res_size) {
                log_message(LOG_ERROR, 
                    "Bytes expected (%lu) is not equal to bytes read (%lu)\n",
                    res_size, nb_read_total);
                free(data);
                return 0;
        }

        return res_size;
}
开发者ID:RossMeikleham,项目名称:PlutoBoy,代码行数:44,代码来源:files.c


示例18: savePNG

int savePNG(const std::string &filename,
			const unsigned char * data,int w,int h,_XColorMode color,
			int compression)
{
	if(data == NULL) return XFalse;
	SDL_RWops *fp;
	int ret;

	if((fp = SDL_RWFromFile(filename.c_str(),"wb")) == NULL) return -1;
	SDL_Surface * picArm = NULL;
	switch(color)
	{
	case COLOR_RGB:
	case COLOR_BGR:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
		picArm = SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,24,0xff000000, 0x00ff0000, 0x0000ff00, 0x00000000);
#else
		picArm = SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,24,0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000);
#endif
		break;
	case COLOR_RGBA:
	case COLOR_BGRA:
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
		picArm = SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,32,0xff000000, 0x00ff0000, 0x0000ff00, 0x00000000);
#else
		picArm = SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,32,0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000);
#endif
		break;
	default:	//其他格式不支持
		return -1;
		break;
	}
	//这里可以考虑保存成24位色提升效率
	memcpy(picArm->pixels,data,w * h * picArm->format->BytesPerPixel);

	ret = IMG_SavePNG_RW(fp,picArm,compression);
	SDL_FreeSurface(picArm);
	picArm = NULL;
	SDL_RWclose(fp);
	return ret;
}
开发者ID:QiangJi,项目名称:XEffect2D,代码行数:41,代码来源:XSavePNG.cpp


示例19: main

int main(int argc, char *argv[])
{
    if (argc != 2) {
        fprintf(stderr, "usage: %s <filename>\n", argv[0]);
        return 1;
    }

    if (SDL_Init(SDL_INIT_AUDIO) != 0) {
        fprintf(stderr, "Error: %s\n", SDL_GetError());
        return 1;
    }

    if (Sound_Init() == 0) {
        fprintf(stderr, "Error: %s\n", Sound_GetError());
        return 1;
    }

    SDL_RWops* rw = SDL_RWFromFile(argv[1], "r");
    if (rw == NULL) {
        fprintf(stderr, "Error: %s\n", SDL_GetError());
        return 1;
    }

    Sound_AudioInfo wantedFormat;
    wantedFormat.channels = 2;
    wantedFormat.rate = 44100;
    wantedFormat.format = AUDIO_S16LSB;

    Sound_Sample* sample = Sound_NewSample(rw, 0, &wantedFormat, 8192);
    if (sample == 0) {
        fprintf(stderr, "Error: %s\n", Sound_GetError());
        return 1;
    }

    Sound_DecodeAll(sample);
    printf("Format: %s\n", sample->decoder->description);
    printf("Decoded %d bytes of data.\n", sample->buffer_size);
    Sound_FreeSample(sample);

    return 0;
}
开发者ID:3togo,项目名称:mxe,代码行数:41,代码来源:sdl_sound-test.c


示例20: Unload

bool Sample::Load(const char* filename)
{
	Unload();
	SDL_RWops* rw = SDL_RWFromFile(filename, "rb");
	if (!rw) {
		SDL_RWclose(rw);
		return false;
	}
	SDL_AudioSpec audiospec;
	memset(&audiospec, 0, sizeof(audiospec));
	SDL_AudioSpec* spec = SDL_LoadWAV_RW(rw, false, &audiospec, &data, (Uint32*)&length);
	if (spec != NULL) {
		format.freq = spec->freq;
		format.format = spec->format;
		format.channels = spec->channels;
		issdlwav = true;
	} else {
		return false;
	}
	return true;
}
开发者ID:Achilleshiel,项目名称:OpenRCT2,代码行数:21,代码来源:mixer.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ SDL_RWread函数代码示例发布时间:2022-05-30
下一篇:
C++ SDL_Init函数代码示例发布时间: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