Exemplo n.º 1
0
    bool Texture::loadTexture(const Platform::FileData* file){

        const ImageUtils::RawImageData raw_image_data = ImageUtils::get_raw_image_data_from_png(file->data, static_cast<unsigned int>(file->data_length));
        
        GLuint texture_object_id;
        glGenTextures(1, &texture_object_id);
        assert(texture_object_id != 0);

        glBindTexture(GL_TEXTURE_2D, texture_object_id);

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexImage2D(GL_TEXTURE_2D, 0, raw_image_data.gl_color_format, raw_image_data.width, raw_image_data.height, 0, raw_image_data.gl_color_format, GL_UNSIGNED_BYTE, raw_image_data.data);
        glGenerateMipmap(GL_TEXTURE_2D);

        glBindTexture(GL_TEXTURE_2D, 0);
        
        this->texture = texture_object_id;

        release_raw_image_data(&raw_image_data);

        return true;
    }
Exemplo n.º 2
0
GLuint load_png_asset_into_texture(const char* relative_path)
{
	assert(relative_path != NULL);

	const FileData png_file = get_asset_data(relative_path);
	const RawImageData raw_image_data = get_raw_image_data_from_png(png_file.data, (int)png_file.data_length);
	const GLuint texture_object_id = load_texture(raw_image_data.width, raw_image_data.height, raw_image_data.gl_color_format, raw_image_data.data);

	release_raw_image_data(&raw_image_data);
	release_asset_data(&png_file);

	return texture_object_id;
}