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

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

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

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

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

示例1: load_image_stb

image load_image_stb(char *filename, int channels){    int w, h, c;    unsigned char *data = stbi_load(filename, &w, &h, &c, channels);    if (!data) {        fprintf(stderr, "Cannot load file image %s/nSTB Reason: %s/n", filename, stbi_failure_reason());        exit(0);    }    if(channels) c = channels;    int i,j,k;    image im = make_image(w, h, c);    for(k = 0; k < c; ++k){        for(j = 0; j < h; ++j){            for(i = 0; i < w; ++i){                int dst_index = i + w*j + w*h*k;                int src_index = k + c*i + c*w*j;                im.data[dst_index] = (float)data[src_index]/255.;            }        }    }    free(data);    return im;}
开发者ID:Nerei,项目名称:darknet,代码行数:23,


示例2: stbi_load

bool Texture::loadFromFile(const std::string &filename) {	int width;	int height;	int comp;	stbi_uc *pixels = stbi_load(filename.c_str(), &width, &height, &comp, 4);	if (pixels == NULL) {		// TODO: Log this..		return false;	}	glBindTexture(GL_TEXTURE_2D, mName);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);	stbi_image_free(pixels);	mWidth = width;	mHeight = height;	return true;}
开发者ID:lostlevels,项目名称:wild-dust,代码行数:23,


示例3: atoi

int scene::loadMap(string mapid){	int id = atoi(mapid.c_str());	if(id!=maps.size()){		cout << "ERROR: MATERIAL ID does not match expected number of materials" << endl;		return -1;	}else{		cout << "Loading Map " << id << "..." << endl;		Map newMap;			//load static properties				string line;			getline(fp_in,line);			vector<string> tokens = utilityCore::tokenizeString(line);			if(strcmp(tokens[0].c_str(), "FILE")==0){				newMap.mapptr = stbi_load(tokens[1].c_str(),&newMap.width, &newMap.height,&newMap.depth,0);			}					  					maps.push_back(newMap);		return 1;	}}
开发者ID:YuanhuiChen,项目名称:Project1-Raytracer,代码行数:23,


示例4: glGenTextures

TextureMap::TextureMap(const GLchar* path){	glGenTextures(1, &textureID);	int width, height,bpp;	//unsigned char* image = SOIL_load_image(path, &width, &height, 0, SOIL_LOAD_RGB);	unsigned char* image = stbi_load(path, &width, &height, &bpp, 3);	mWidth = width;	mHeight = height;	glBindTexture(GL_TEXTURE_2D, textureID);	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);	glGenerateMipmap(GL_TEXTURE_2D);	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_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	float aniso = 0.0f;	glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &aniso);	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso);	glBindTexture(GL_TEXTURE_2D, 0);	stbi_image_free(image);}
开发者ID:Megavoxel01,项目名称:LOGL,代码行数:23,


示例5: stbi_load

bool NormalMap::load(float scale){    int actual_components = 0;    int requested_components = 1;    components = requested_components;    image = stbi_load(filename, &width, &height, &actual_components, requested_components);    if (image) {        assert(width > 0);        assert(height > 0);        assert(actual_components > 0);        if (actual_components != requested_components) {            if (verbose) {                printf("warning: %d component normal map treated as gray scale height map/n",                    actual_components);            }        }        normal_image = new GLubyte[width*height*3];        assert(normal_image);        GLubyte* p = normal_image;        for (int y=0; y<height; y++) {            for (int x=0; x<width; x++) {                float3 normal = computeNormal(x,y, scale);                PackedNormal packed_normal(normal);                p[0] = packed_normal.n[0];                p[1] = packed_normal.n[1];                p[2] = packed_normal.n[2];                p += 3;            }        }        assert(p == normal_image+(width*height*3));        // success        return true;    } else {        printf("%s: failed to load image %s/n", program_name, filename);        return false;    }}
开发者ID:ckiwun,项目名称:Computer-Graphics,代码行数:37,


示例6: glGenTextures

Enco3D::Rendering::TextureCubeMap::TextureCubeMap(const std::string *filenames, unsigned int filter, unsigned int wrap){	glGenTextures(1, &m_id);	glBindTexture(GL_TEXTURE_CUBE_MAP, m_id);	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, filter);	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, filter);	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, wrap);	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, wrap);	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, wrap);	for (unsigned int i = 0; i < 6; i++)	{		int w, h, bytesPerPixel;		unsigned char *data = stbi_load(filenames[i].c_str(), &w, &h, &bytesPerPixel, 4);		glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);		if (data == nullptr)		{			Core::DebugLogger::log("[ERROR] Unable to load texture: " + filenames[i]);			return;		}		else			Core::DebugLogger::log("Successfully loaded texture " + filenames[i]);		m_width = (unsigned int)w;		m_height = (unsigned int)h;		stbi_image_free(data);	}	glBindTexture(GL_TEXTURE_CUBE_MAP, 0);	Core::DebugLogger::log("[OPEN_GL] Created texture cube map with id " + std::to_string(m_id));}
开发者ID:Naronco,项目名称:Enco3D,代码行数:37,


示例7: stbi_load

void DialogControlsModels::createTextureBuffer(std::string imageFile, GLuint* vboBuffer, int* width, int* height) {    if (!boost::filesystem::exists(imageFile))        imageFile = Settings::Instance()->currentFolder + "/" + imageFile;    int tChannels;    unsigned char* tPixels = stbi_load(imageFile.c_str(), width, height, &tChannels, 0);    if (!tPixels)        Settings::Instance()->funcDoLog("Can't load texture image - " + imageFile + " with error - " + std::string(stbi_failure_reason()));    else {        glGenTextures(1, vboBuffer);        glBindTexture(GL_TEXTURE_2D, *vboBuffer);        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);        GLenum textureFormat = 0;        switch (tChannels) {            case 1:                textureFormat = GL_LUMINANCE;                break;            case 2:                textureFormat = GL_LUMINANCE_ALPHA;                break;            case 3:                textureFormat = GL_RGB;                break;            case 4:                textureFormat = GL_RGBA;                break;            default:                textureFormat = GL_RGB;                break;        }        glTexImage2D(GL_TEXTURE_2D, 0, static_cast<GLint>(textureFormat), *width, *height, 0, textureFormat, GL_UNSIGNED_BYTE, (GLvoid*)tPixels);        glGenerateMipmap(GL_TEXTURE_2D);        stbi_image_free(tPixels);    }}
开发者ID:supudo,项目名称:Kuplung,代码行数:37,


示例8: Component

Texture::Texture(const char* filename, std::initializer_list<float> texcoords) :    	Component(EComponentType::TEXTURE),		uv(texcoords) {		// Load pixeldata, width, height, and components from file	unsigned char* pixels = stbi_load(filename, &width, &height, &components, 0);	// Allocate a new texture in OpenGL	glGenTextures(1, &GLtex);	glActiveTexture(GL_TEXTURE0);		// Set active texture id	glBindTexture(GL_TEXTURE_2D, GLtex);	if (components == 4 ) {		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);	} else {		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);	}	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);	// cleanup	stbi_image_free(pixels);	// unbind texture for cleanliness	glBindTexture(GL_TEXTURE_2D, 0);	for (int i = 0; i < uv.size(); i++) {		uv[i] = uv[i] / width;		uv[i+1] = uv[i+1] / height;		i++;	}}
开发者ID:grouse,项目名称:jengine,代码行数:37,


示例9: stbi_load

bool ImageLoader::loadImageFromFile(const std::string& filename, std::vector<Uint8>& pixels, Vector2u& size){    // 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;    unsigned char* ptr = stbi_load(filename.c_str(), &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 /"" << filename << "/". Reason: " << stbi_failure_reason() << std::endl;        return false;    }}
开发者ID:42bottles,项目名称:SFML,代码行数:37,


示例10: stbi_load

Texture::Texture( const char *filename, bool png ){	int h, w, comp;	uchar *img = stbi_load( filename, &w, &h, &comp, 4 );	if ( img == NULL )	{		printf( "%sが
C++ stbi_load_from_memory函数代码示例
C++ stbi_image_free函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。