OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::IMTexture Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/ImGuiWrapper.hpp>

Static Public Member Functions

static bool load_from_svg_file (const std::string &filename, unsigned width, unsigned height, ImTextureID &texture_id)

Detailed Description

Member Function Documentation

◆ load_from_svg_file()

bool Slic3r::GUI::IMTexture::load_from_svg_file ( const std::string & filename,
unsigned width,
unsigned height,
ImTextureID & texture_id )
static
3656{
3657 NSVGimage* image = nsvgParseFromFile(filename.c_str(), "px", 96.0f);
3658 if (image == nullptr) {
3659 return false;
3660 }
3661
3662 float scale = (float)width / std::max(image->width, image->height);
3663
3664 int n_pixels = width * height;
3665
3666 if (n_pixels <= 0) {
3667 nsvgDelete(image);
3668 return false;
3669 }
3670
3671 NSVGrasterizer* rast = nsvgCreateRasterizer();
3672 if (rast == nullptr) {
3673 nsvgDelete(image);
3674 return false;
3675 }
3676 std::vector<unsigned char> data(n_pixels * 4, 0);
3677 nsvgRasterize(rast, image, 0, 0, scale, data.data(), width, height, width * 4);
3678
3679 bool compress = false;
3680 GLint last_texture;
3681 unsigned m_image_texture{ 0 };
3682 unsigned char* pixels = (unsigned char*)(&data[0]);
3683
3685 glsafe(::glGenTextures(1, &m_image_texture));
3686 glsafe(::glBindTexture(GL_TEXTURE_2D, m_image_texture));
3690 glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
3691
3692 // Store our identifier
3693 texture_id = (ImTextureID)(intptr_t)m_image_texture;
3694
3695 // Restore state
3696 glsafe(::glBindTexture(GL_TEXTURE_2D, last_texture));
3697
3698 nsvgDeleteRasterizer(rast);
3699 nsvgDelete(image);
3700
3701 return true;
3702}
#define glsafe(cmd)
Definition OpenGLUtils.hpp:25
int scale(const int val)
Definition WipeTowerDialog.cpp:58
#define GL_TEXTURE_MIN_FILTER
Definition gl.h:1828
#define glPixelStorei
Definition gl.h:4451
#define GL_LINEAR
Definition gl.h:930
#define glTexParameteri
Definition gl.h:4911
int GLint
Definition gl.h:2062
#define glGetIntegerv
Definition gl.h:3873
#define glTexImage2D
Definition gl.h:4895
#define GL_UNSIGNED_BYTE
Definition gl.h:1937
#define glGenTextures
Definition gl.h:3787
#define glBindTexture
Definition gl.h:3299
#define GL_RGBA
Definition gl.h:1493
#define GL_TEXTURE_MAG_FILTER
Definition gl.h:1822
#define GL_TEXTURE_2D
Definition gl.h:1739
#define GL_TEXTURE_BINDING_2D
Definition gl.h:1749
#define GL_UNPACK_ROW_LENGTH
Definition gl.h:1931
coord_t width(const BoundingBox &box)
Definition Arrange.cpp:1184
coord_t height(const BoundingBox &box)
Definition Arrange.cpp:1185
NSVGimage_ptr nsvgParseFromFile(const std::string &filename, const char *units, float dpi)
Definition NSVGUtils.cpp:106

References GL_LINEAR, GL_RGBA, GL_TEXTURE_2D, GL_TEXTURE_BINDING_2D, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER, GL_UNPACK_ROW_LENGTH, GL_UNSIGNED_BYTE, glBindTexture, glGenTextures, glGetIntegerv, glPixelStorei, glsafe, glTexImage2D, glTexParameteri, Slic3r::nsvgParseFromFile(), and scale().

Referenced by Slic3r::GUI::GLGizmosManager::init_icon_textures(), Slic3r::GUI::IMSlider::init_texture(), and Slic3r::GUI::menu_item_with_icon().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: