您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ stbi_failure_reason函数代码示例

51自学网 2021-06-03 08:23:15
  C++
这篇教程C++ stbi_failure_reason函数代码示例写得很实用,希望能帮到您。

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

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

示例1: stbi_load

ImageBasedDensityProvider::ImageBasedDensityProvider(const std::string filename, const AABB model_aabb){    int desired_channel_count = 0; // keep original amount of channels    int img_x, img_y, img_z; // stbi requires pointer to int rather than to coord_t    image = stbi_load(filename.c_str(), &img_x, &img_y, &img_z, desired_channel_count);    image_size = Point3(img_x, img_y, img_z);    if (!image)    {        const char* reason = "[unknown reason]";        if (stbi_failure_reason())        {            reason = stbi_failure_reason();        }        logError("Cannot load image %s: '%s'./n", filename.c_str(), reason);        std::exit(-1);    }    { // compute aabb        Point middle = model_aabb.getMiddle();        Point model_aabb_size = model_aabb.max - model_aabb.min;        Point image_size2 = Point(image_size.x, image_size.y);        float aabb_aspect_ratio = float(model_aabb_size.X) / float(model_aabb_size.Y);        float image_aspect_ratio = float(image_size.x) / float(image_size.y);        Point aabb_size;        if (image_aspect_ratio < aabb_aspect_ratio)        {            aabb_size = image_size2 * model_aabb_size.X / image_size.x;        }        else        {            aabb_size = image_size2 * model_aabb_size.Y / image_size.y;        }        print_aabb = AABB(middle - aabb_size / 2, middle + aabb_size / 2);        assert(aabb_size.X >= model_aabb_size.X && aabb_size.Y >= model_aabb_size.Y);    }}
开发者ID:PuddingPengChen,项目名称:Magic3D,代码行数:35,


示例2: main

int main(int argc, char** argv){    if (argc < 2)    {        std::cerr << "Use " << argv[0] << " filename" << std::endl;        return 1;    }    // load image    int width, height, nc;    float* rgba = stbi_loadf(argv[1], &width, &height, &nc, 4);    if (stbi_failure_reason())    {        std::cerr << "stbi: " << stbi_failure_reason() << std::endl;        return 1;    }    // create summed area table of luminance image    summed_area_table lum_sat;    lum_sat.create_lum(rgba, width, height, 4);    // apply median cut    std::vector<sat_region> regions;    median_cut(lum_sat, 9, regions); // max 2^n cuts    // create 2d positions from regions    std::vector<float2> lights;    create_lights(regions, lights);    // draw a marker into image for each position    size_t i = 0;    for (auto l = lights.begin(); l != lights.end(); ++l)    {        std::cout << "Light " << i++ << ": (" << l->x << ", " << l->y << ")" << std::endl;        draw(rgba, width, height, *l);    }    // save image with marked samples    std::vector<unsigned char> conv;    conv.resize(width*height*4);    for (size_t i = 0; i < width * height * 4; ++i)        conv[i] = static_cast<unsigned char>(rgba[i]*255);    stbi_write_bmp("test.bmp", width, height, 4, &conv[0]);    return 0;}
开发者ID:gunsafighter,项目名称:mediancut,代码行数:48,


示例3: fp

void FileImage::load_file(){    FSFile fp(filename.c_str(), "r");    if (!fp.is_open()) {        printf("Could not open image /"%s/"/n", filename.c_str());        return;    }    int w, h, channels;    image = load_image(fp, fp.get_size(), &w, &h, &channels);    width = w;    height = h;    fp.close();    if (image == NULL) {        printf("Could not load image /"%s/": %s/n", filename.c_str(),               stbi_failure_reason());        return;    }    if (!transparent.is_enabled())        return;#ifndef CHOWDREN_FORCE_TRANSPARENT    if (channels != 1 && channels != 3)        return;#endif    set_transparent_color(transparent);}
开发者ID:mattl,项目名称:anaconda,代码行数:33,


示例4: stbi_load_from_callbacks

Stb::ImagePtr Stb::Image::loadFromStream(std::istream & s, Format fmt){	ImagePtr image = std::static_pointer_cast<Image>(std::make_shared<Image::Wrapper>());	try	{		int imageFmt = UNKNOWN;		image->m_Data = stbi_load_from_callbacks(&g_StbCB, &s, &image->m_Width, &image->m_Height, &imageFmt, fmt);		if (!image->m_Data)			throw std::runtime_error(stbi_failure_reason());		image->m_Format = static_cast<Format>(fmt == UNKNOWN ? imageFmt : fmt);		if (image->m_Format == UNKNOWN)			throw std::runtime_error("unable to determine pixel format for the image.");	}	catch (const std::exception & e)	{		if (image->m_Data)			stbi_image_free(image->m_Data);		std::clog << "Error reading image: " << e.what() << std::endl;		image->m_Data = &g_DummyData;		image->m_Width = 0;		image->m_Height = 0;		image->m_Format = UNKNOWN;	}	return image;}
开发者ID:friedcroc,项目名称:tizen_spacerace,代码行数:30,


示例5: stbi_load

bool ImageLoader::loadImageFromFile(const std::string& filename, std::vector<Uint8>& pixels, unsigned int& width, unsigned int& height){    // Clear the array (just in case)    pixels.clear();    // Load the image and get a pointer to the pixels in memory    int imgWidth, imgHeight, imgChannels;    unsigned char* ptr = stbi_load(filename.c_str(), &imgWidth, &imgHeight, &imgChannels, STBI_rgb_alpha);    if (ptr && imgWidth && imgHeight)    {        // Assign the image properties        width  = imgWidth;        height = imgHeight;        // Copy the loaded pixels to the pixel buffer        pixels.resize(width * height * 4);        memcpy(&pixels[0], ptr, pixels.size());        // Free the loaded pixels (they are now in our own pixel buffer)        stbi_image_free(ptr);        return true;    }    else    {        // Error, failed to load the image        err() << "Failed to load image /"" << filename << "/". Reason : " << stbi_failure_reason() << std::endl;        return false;    }}
开发者ID:EternalWind,项目名称:SFML,代码行数:32,


示例6: open_image_file

void Image::load(){    flags |= USED;    if (tex != 0 || image != NULL)        return;    if (flags & FILE) {        ((FileImage*)this)->load_file();        return;    }    open_image_file();    image_file.set_item(handle, AssetFile::IMAGE_DATA);    FileStream stream(image_file);    hotspot_x = stream.read_int16();    hotspot_y = stream.read_int16();    action_x = stream.read_int16();    action_y = stream.read_int16();    int size = stream.read_uint32();    int w, h, channels;    image = load_image(image_file, size, &w, &h, &channels);    width = w;    height = h;    if (image == NULL) {        std::cout << "Could not load image " << handle << std::endl;        std::cout << stbi_failure_reason() << std::endl;        return;    }}
开发者ID:devinvisible,项目名称:anaconda,代码行数:35,


示例7: defined

void Stb::Read(SoyPixelsImpl& Pixels,const ArrayBridge<char>& ArrayBuffer,TReadFunction ReadFunction){#if defined(USE_STB)	const stbi_uc* Buffer = reinterpret_cast<const stbi_uc*>( ArrayBuffer.GetArray() );	auto BufferSize = size_cast<int>( ArrayBuffer.GetDataSize() );	int Width = 0;	int Height = 0;	int Channels = 0;	int RequestedChannels = 4;	auto* DecodedPixels = stbi_load_from_memory( Buffer, BufferSize, &Width, &Height, &Channels, RequestedChannels );	if ( !DecodedPixels )	{		//	gr: as this is not thread safe, it could come out mangled :( maybe add a lock around error popping before read (maybe have to lock around the whole thing)		auto* StbError = stbi_failure_reason();		if ( !StbError )			StbError = "Unknown error";		std::stringstream Error;		Error << "Failed to read image pixels; " << StbError;				throw Soy::AssertException( Error.str() );	}		//	convert output into pixels	//	gr: have to assume size	auto Format = SoyPixelsFormat::GetFormatFromChannelCount( Channels );	SoyPixelsMeta Meta( Width, Height, Format );	SoyPixelsRemote OutputPixels( DecodedPixels, Meta.GetDataSize(), Meta );	Pixels.Copy( OutputPixels );#else	throw Soy::AssertException("No STB support, no image reading");#endif}
开发者ID:SoylentGraham,项目名称:SoyLib,代码行数:32,


示例8: stbi_load

void StbImageFactory::load(ResourceData *resource){    StbImage* stbresource = static_cast<StbImage*>(resource);    int x,y,comp;    stbi_uc* data = stbi_load(stbresource->path().toLocal8Bit().data(), &x, &y, &comp, stbresource->m_comp);    if(data != 0)    {        logInfo( "StbImage loaded " << resource->name() << " (" << x << "x" << y << ")");        stbresource->m_data = data;        stbresource->m_width = x;        stbresource->m_height = y;        // If we asked 0 components comp now contains the number of components        if(stbresource->m_comp == 0)            stbresource->m_comp = comp;        stbresource->m_state = StbImage::STATE_LOADED;        stbresource->buildTexture();    }    else    {        logWarn( "StbImage failed to load " << resource->name() << "/n" << stbi_failure_reason());    }}
开发者ID:smatcher,项目名称:S5old,代码行数:26,


示例9: load_embedded_image

static int load_embedded_image(lua_State *L) {    am_check_nargs(L, 1);    const char *filename = luaL_checkstring(L, 1);    am_embedded_file_record *rec = am_get_embedded_file(filename);    if (rec == NULL) {        return luaL_error(L, "embedded file not found: %s", filename);    }    int width, height;    int components = 4;    stbi_set_flip_vertically_on_load(1);    stbi_uc *img_data =        stbi_load_from_memory((stbi_uc const *)rec->data, rec->len, &width, &height, &components, 4);    if (img_data == NULL) {        return luaL_error(L, "error loading image %s: %s", filename, stbi_failure_reason());    }    am_image_buffer *img = am_new_userdata(L, am_image_buffer);    img->width = width;    img->height = height;    img->format = AM_PIXEL_FORMAT_RGBA8;    int sz = width * height * pixel_format_size(img->format);    am_buffer *imgbuf = am_new_userdata(L, am_buffer);    imgbuf->size = sz;    imgbuf->data = img_data;    img->buffer = imgbuf;    img->buffer_ref = img->ref(L, -1);    lua_pop(L, 1); // pop imgbuf    return 1;}
开发者ID:AntonioModer,项目名称:amulet,代码行数:28,


示例10: load_image

static int load_image(lua_State *L) {    am_check_nargs(L, 1);    char *errmsg;    int len;    const char *filename = luaL_checkstring(L, 1);    void *data = am_read_resource(filename, &len, &errmsg);    if (data == NULL) {        lua_pushstring(L, errmsg);        free(errmsg);        return lua_error(L);    }    int width, height;    int components = 4;    stbi_set_flip_vertically_on_load(1);    stbi_uc *img_data =        stbi_load_from_memory((stbi_uc const *)data, len, &width, &height, &components, 4);    free(data);    if (img_data == NULL) {        return luaL_error(L, "error loading image %s: %s", filename, stbi_failure_reason());    }    am_image_buffer *img = am_new_userdata(L, am_image_buffer);    img->width = width;    img->height = height;    img->format = AM_PIXEL_FORMAT_RGBA8;    int sz = width * height * pixel_format_size(img->format);    am_buffer *imgbuf = am_new_userdata(L, am_buffer);    imgbuf->size = sz;    imgbuf->data = img_data;    img->buffer = imgbuf;    img->buffer_ref = img->ref(L, -1);    lua_pop(L, 1); // pop imgbuf    return 1;}
开发者ID:AntonioModer,项目名称:amulet,代码行数:33,


示例11: stbi_load_from_memory

void cImage::LoadFromPack( cPack * Pack, const std::string& FilePackPath ) {	if ( NULL != Pack && Pack->IsOpen() && -1 != Pack->Exists( FilePackPath ) ) {		SafeDataPointer PData;		Pack->ExtractFileToMemory( FilePackPath, PData );		int w, h, c;		Uint8 * data = stbi_load_from_memory( PData.Data, PData.DataSize, &w, &h, &c, mChannels );		if ( NULL != data ) {			mPixels		= data;			mWidth		= (eeUint)w;			mHeight		= (eeUint)h;			if ( STBI_default == mChannels )				mChannels	= (eeUint)c;			mSize	= mWidth * mHeight * mChannels;			mLoadedFromStbi = true;		} else {			eePRINTL( "Failed to load image %s. Reason: %s", stbi_failure_reason(), FilePackPath.c_str() );		}	} else {		eePRINTL( "Failed to load image %s from pack.", FilePackPath.c_str() );	}}
开发者ID:dogtwelve,项目名称:eepp,代码行数:27,


示例12: load_image

Image load_image(const std::string& filename, Image::Format format){    int32_t width, height;    auto data = stbi_load(filename.c_str(), &width, &height, nullptr, format);    if (!data)        std::cerr << stbi_failure_reason() << std::endl;    return Image(width, height, format, data);}
开发者ID:djrollins,项目名称:LearnOpenGL,代码行数:8,


示例13: stbi_convert_iphone_png_to_rgb

	bool Image::LoadFile( uint8_t * data, int32_t size )	{		this->bpp = 4;		stbi_convert_iphone_png_to_rgb(1);		this->pixels = stbi_load_from_memory(data, (int)size, (int*)&this->width, (int*)&this->height, (int*)&this->original_bpp, this->bpp);		if ( this->pixels == NULL )		{			std::cout << "elix::Image:" << stbi_failure_reason() << std::endl;			this->length = 0;			return false;		}		if ( this->bpp != 4 )		{			std::cout << "this->bpp:" << this->bpp << "-" << stbi_failure_reason() << std::endl;		}		this->length = this->width * this->height * this->bpp;		return true;	}
开发者ID:lukesalisbury,项目名称:luxengine,代码行数:18,


示例14: loadTexture

Texture2D loadTexture(u8 *image_data, u64 image_size, RenderContext *render_context, RenderContext::Format format, int force_components) {	int tex_w, tex_h, tex_comps;	stbi_set_flip_vertically_on_load(true);	u8 *tex_data = (u8 *)stbi_loadf_from_memory((stbi_uc *)image_data, image_size, &tex_w, &tex_h, &tex_comps, force_components);	const char *fail_reason = stbi_failure_reason();	Texture2D result  = render_context->createTexture2D(tex_data, (u32)tex_w,  (u32)tex_h, format);	stbi_image_free(tex_data);	return result;	}
开发者ID:napoleon89,项目名称:Pawprint,代码行数:9,


示例15: stbi_failure_reason

std::string StbContext::GetError(){	//	gr: as this is not thread safe, it could come out mangled :( maybe add a lock around error popping before read (maybe have to lock around the whole thing)	auto* StbError = stbi_failure_reason();	if ( !StbError )		return "Unknown error";	return StbError;}
开发者ID:SoylentGraham,项目名称:SoyLib,代码行数:9,


示例16: stbi_load

Bitmap Bitmap::bitmapFromFile(std::string filePath) {    int width, height, channels;    unsigned char* pixels = stbi_load(filePath.c_str(), &width, &height, &channels, 0);    if(!pixels) throw std::runtime_error(stbi_failure_reason());    Bitmap bmp(width, height, (Format)channels, pixels);    stbi_image_free(pixels);    return bmp;}
开发者ID:Ubuska,项目名称:WarpEngine,代码行数:9,


示例17: memStream

    //---------------------------------------------------------------------    Codec::DecodeResult STBIImageCodec::decode(DataStreamPtr& input) const    {        // Buffer stream into memory (TODO: override IO functions instead?)        MemoryDataStream memStream(input, true);        int width, height, components;        stbi_uc* pixelData = stbi_load_from_memory(memStream.getPtr(),                static_cast<int>(memStream.size()), &width, &height, &components, 0);        if (!pixelData)        {            OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,                 "Error decoding image: " + String(stbi_failure_reason()),                "STBIImageCodec::decode");        }        SharedPtr<ImageData> imgData(OGRE_NEW ImageData());        MemoryDataStreamPtr output;        imgData->depth = 1; // only 2D formats handled by this codec        imgData->width = width;        imgData->height = height;        imgData->num_mipmaps = 0; // no mipmaps in non-DDS         imgData->flags = 0;        switch( components )        {            case 1:                imgData->format = PF_BYTE_L;                break;            case 2:                imgData->format = PF_BYTE_LA;                break;            case 3:                imgData->format = PF_BYTE_RGB;                break;            case 4:                imgData->format = PF_BYTE_RGBA;                break;            default:                stbi_image_free(pixelData);                OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,                            "Unknown or unsupported image format",                            "STBIImageCodec::decode");                break;        }                size_t dstPitch = imgData->width * PixelUtil::getNumElemBytes(imgData->format);        imgData->size = dstPitch * imgData->height;        output.bind(OGRE_NEW MemoryDataStream(pixelData, imgData->size, true));                DecodeResult ret;        ret.first = output;        ret.second = imgData;        return ret;    }
开发者ID:OGRECave,项目名称:ogre,代码行数:57,


示例18: TextureLoader_stbi

TextureResourceData* TextureLoader_stbi(ResourceDataSource &dataSource, Allocator &alloc, bool forceRGBA){    stbi_io_callbacks callbacks;    callbacks.read = read;    callbacks.skip = skip;    callbacks.eof = eof;    int x, y, bpp;    auto pixels = stbi_load_from_callbacks(&callbacks, &dataSource, &x, &y, &bpp, forceRGBA ? 4 : 0);    if (!pixels)    {#ifdef STB_DO_ERROR_PRINT        DFLOG_WARN(stbi_failure_reason());#endif        return nullptr;    }    auto fmt = PixelFormat::INVALID;    if (bpp == STBI_rgb)    {        fmt = PixelFormat::RGB;    }    else if (bpp == STBI_rgb_alpha)    {        fmt = PixelFormat::RGBA;    }    else    {        DFLOG_WARN("Parsed image with an invalid bpp");        stbi_image_free(pixels);        return nullptr;    }    if (forceRGBA)        fmt = PixelFormat::RGBA;    auto resource = MAKE_NEW(alloc, TextureResourceData);    resource->format = fmt;    resource->mipLevels.resize(1);    resource->mipLevels[0].width = x;    resource->mipLevels[0].height = y;    int compCount = forceRGBA ? 4 : bpp;    resource->mipLevels[0].pixels.resize(compCount * x * y);    memcpy(resource->mipLevels[0].pixels.data(), pixels, compCount * x * y);    stbi_image_free(pixels);    return resource;}
开发者ID:flaming0,项目名称:libdf3d,代码行数:53,


示例19: stbi_load

bool Texture::load(std::string filename){	int width, height, channels;	unsigned char* ptr = stbi_load(filename.c_str(), &width, &height, &channels, STBI_rgb_alpha);	bool result = false;	if (ptr && width && height) result = load(ptr, width, height);	else printLog("Failed to load image /"%s/". Reason : %s/n", filename.c_str(), stbi_failure_reason());	stbi_image_free(ptr);	return result;}
开发者ID:budsan,项目名称:guyframework,代码行数:12,


示例20: mPixels

cImage::cImage( std::string Path, const eeUint& forceChannels ) :	mPixels(NULL),	mWidth(0),	mHeight(0),	mChannels(forceChannels),	mSize(0),	mAvoidFree(false),	mLoadedFromStbi(false){	int w, h, c;	cPack * tPack = NULL;	Uint8 * data = stbi_load( Path.c_str(), &w, &h, &c, mChannels );	if ( NULL == data ) {		data = stbi_load( ( Sys::GetProcessPath() + Path ).c_str(), &w, &h, &c, mChannels );	}	if ( NULL != data ) {		mPixels		= data;		mWidth		= (eeUint)w;		mHeight		= (eeUint)h;		if ( STBI_default == mChannels )			mChannels	= (eeUint)c;		mSize	= mWidth * mHeight * mChannels;		mLoadedFromStbi = true;	} else if ( cPackManager::instance()->FallbackToPacks() && NULL != ( tPack = cPackManager::instance()->Exists( Path ) ) ) {		LoadFromPack( tPack, Path );	} else {		std::string reason = ".";		if ( NULL != stbi_failure_reason() ) {			reason = ", reason: " + std::string( stbi_failure_reason() );		}		eePRINTL( "Failed to load image %s. Reason: %s", Path.c_str(), reason.c_str() );	}}
开发者ID:dogtwelve,项目名称:eepp,代码行数:40,


示例21: stbi_load_from_memory

bool Texture::load(const void* memFile, std::size_t size){	int width, height, channels;	const unsigned char* buffer = static_cast<const unsigned char*>(memFile);	unsigned char* ptr = stbi_load_from_memory(buffer, static_cast<int>(size), &width, &height, &channels, STBI_rgb_alpha);	bool result = false;	if (ptr && width && height) result = load(ptr, width, height);	else printLog("Failed to load image from memory. Reason : %s/n", stbi_failure_reason());	stbi_image_free(ptr);	return result;}
开发者ID:budsan,项目名称:guyframework,代码行数:13,


示例22: fseek

static unsigned char *read_zip_file(FILE *file, int offset, int *sizep){	int sig, method, csize, usize;	int namelength, extralength;	char *cdata, *udata;	fseek(file, offset, 0);	sig = getlong(file);	if (sig != ZIP_LOCAL_FILE_SIG) {		warn("zip: wrong signature for local file");		return NULL;	}	(void) getshort(file); /* version */	(void) getshort(file); /* general */	method = getshort(file);	(void) getshort(file); /* file time */	(void) getshort(file); /* file date */	(void) getlong(file); /* crc-32 */	csize = getlong(file); /* csize */	usize = getlong(file); /* usize */	namelength = getshort(file);	extralength = getshort(file);	fseek(file, namelength + extralength, 1);	if (method == 0 && csize == usize) {		cdata = malloc(csize);		fread(cdata, 1, csize, file);		*sizep = csize;		return (unsigned char*) cdata;	}	if (method == 8) {		cdata = malloc(csize);		fread(cdata, 1, csize, file);		udata = malloc(usize);		usize = stbi_zlib_decode_noheader_buffer(udata, usize, cdata, csize);		free(cdata);		if (usize < 0) {			warn("zip: %s", stbi_failure_reason());			return NULL;		}		*sizep = usize;		return (unsigned char*) udata;	}	warn("zip: unknown compression method");	return NULL;}
开发者ID:ccxvii,项目名称:mio,代码行数:51,


示例23: stbi_load

bool Texture::load(const std::string &path, GLenum min_filter, GLenum mag_filter, GLenum wrap_s, GLenum wrap_t) {    int width, height, perPixComp;    const char *image_path = path.c_str();    unsigned char* image = stbi_load(image_path, &width, &height, &perPixComp, 3);    if (!image) {        std::cout << "ERROR::TEXTURE::LOADING_FAILED/n" << stbi_failure_reason() << std::endl;        return false;    } else {        load(image, width, height, min_filter, mag_filter, wrap_s, wrap_t);        stbi_image_free(image);    }    return true;}
开发者ID:valche5,项目名称:ValEngine,代码行数:14,


示例24: printf

    int Render::loadTexture(string texture_file, string texture_name)    {        //std::string path(GLSL_SOURCE_DIR);        //path += "../../../sprites/boid.png";        //path += "../../../sprites/enjalot.jpg";        printf("LOAD TEXTURE!!!!!!!!!!!!!!/n");        //printf("path: %s/n", path.c_str());        //Load an image with stb_image        int w,h,channels;        int force_channels = 0;        unsigned char *im = stbi_load( texture_file.c_str(), &w, &h, &channels, force_channels );        printf("after load w: %d h: %d channels: %d/n", w, h, channels);        printf("im looking for the image at %s/n", texture_file.c_str());        if (im == NULL)        {            printf("fail!: %s/n", stbi_failure_reason());            printf("WTF/n");        }        //load as gl texture        glGenTextures(1, &gl_textures[texture_name]);        glBindTexture(GL_TEXTURE_2D, gl_textures[texture_name]);        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);                //better way to do this?        if(channels == 3)        {            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0,                     GL_RGB, GL_UNSIGNED_BYTE, &im[0]);        }        else if (channels == 4)        {             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0,                  GL_RGBA, GL_UNSIGNED_BYTE, &im[0]);        }        glBindTexture(GL_TEXTURE_2D,0);        free(im);        return 0; //success    }
开发者ID:JorgeFRod,项目名称:EnjaParticles,代码行数:48,


示例25: load_image

  Image load_image( const char* filename )  {    i32 width;    i32 height;    i32 format;    // Using NULL because stbi_load takes an integer and nullptr    // has type nullptr_t.    u8* pixels = stbi_load( filename, &width, &height, &format, 0 );    defer( stbi_image_free( pixels ) );    if ( !pixels )      throw std::runtime_error( stbi_failure_reason() );    return load_image( width, height, (ImageFormat)format, pixels );  }
开发者ID:for-all-mankind,项目名称:game-engine,代码行数:16,


示例26: stbi_set_flip_vertically_on_load

    TexturePtr Texture::load(const char* path)    {        int width;        int height;        int comp;        stbi_set_flip_vertically_on_load(1); // we need to flip the y axis due to OpenGL        unsigned char* data = stbi_load(path, &width, &height, &comp, STBI_rgb_alpha);        if (data == nullptr)        {            std::cout << "Texture::load error: there was a problem loading the texture " << path << std::endl;            std::cout << "STBI: " << stbi_failure_reason() << std::endl;            return nullptr;        }        return TexturePtr(new Texture(data, width, height, comp, path));    }
开发者ID:redxdev,项目名称:Wake,代码行数:16,


示例27: stbi_set_flip_vertically_on_load

kit::Texture::Ptr kit::Texture::create2DFromFile(std::string filename, kit::Texture::InternalFormat format, kit::Texture::EdgeSamplingMode edgemode, kit::Texture::FilteringMode minfilter, kit::Texture::FilteringMode magfilter){  std::cout << "Loading texture from file " << filename.c_str() << std::endl;  kit::Texture::Ptr returner = std::make_shared<kit::Texture>(Texture2D);  returner->m_internalFormat    = format;  // Try to load data from file  unsigned char* bufferdata;  int x, y, n;  stbi_set_flip_vertically_on_load(1);  bufferdata = stbi_load(filename.c_str(), &x, &y, &n, 4);  if (bufferdata == nullptr)  {    KIT_ERR(stbi_failure_reason());    x = 1;    y = 1;    n = 4;    bufferdata = new unsigned char[4];    bufferdata[0] = 255;    bufferdata[1] = 0;    bufferdata[2] = 0;    bufferdata[3] = 255;  }  // Set resolution  returner->m_resolution        = glm::uvec3(x, y, 0);  // Specify storage and upload data to GPU  KIT_GL(glTextureStorage2D(returner->m_glHandle, returner->calculateMipLevels(), returner->m_internalFormat, returner->m_resolution.x, returner->m_resolution.y));  KIT_GL(glTextureSubImage2D(returner->m_glHandle, 0, 0, 0, x, y, GL_RGBA, GL_UNSIGNED_BYTE, bufferdata));  // Free loaded data  stbi_image_free(bufferdata);  // Set parameters  returner->setEdgeSamplingMode(edgemode);  returner->setMinFilteringMode(minfilter);  returner->setMagFilteringMode(magfilter);  returner->setAnisotropicLevel(8.0f);  // Generate mipmap  returner->generateMipmap();  return returner;}
开发者ID:bryongloden,项目名称:kit,代码行数:47,


示例28: stbi_load_from_memory

bool ImageLoader::loadImageFromMemory(const void* data, std::size_t dataSize, std::vector<Uint8>& pixels, Vector2u& size){    // Check input parameters    if (data && dataSize)    {        // Clear the array (just in case)        pixels.clear();        // Load the image and get a pointer to the pixels in memory        int width = 0;        int height = 0;        int channels = 0;        const unsigned char* buffer = static_cast<const unsigned char*>(data);        unsigned char* ptr = stbi_load_from_memory(buffer, static_cast<int>(dataSize), &width, &height, &channels, STBI_rgb_alpha);        if (ptr)        {            // Assign the image properties            size.x = width;            size.y = height;            if (width && height)            {                // Copy the loaded pixels to the pixel buffer                pixels.resize(width * height * 4);                memcpy(&pixels[0], ptr, pixels.size());            }            // Free the loaded pixels (they are now in our own pixel buffer)            stbi_image_free(ptr);            return true;        }        else        {            // Error, failed to load the image            err() << "Failed to load image from memory. Reason: " << stbi_failure_reason() << std::endl;            return false;        }    }    else    {        err() << "Failed to load image from memory, no data provided" << std::endl;        return false;    }}
开发者ID:42bottles,项目名称:SFML,代码行数:47,



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


C++ stbi_image_free函数代码示例
C++ status_set_viewdata函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。