MCPcopy Create free account
hub / github.com/XorTroll/uLaunch / SaveAsImage

Method SaveAsImage

projects/uDesigner/source/main.cpp:722–741  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

720 }
721
722 inline bool SaveAsImage(zip_t *theme_zip) {
723 if(!this->ImageIsBuiltin() && (this->el_img.width > 0)) {
724 GLuint fb;
725 glGenFramebuffers(1, &fb);
726 glBindFramebuffer(GL_FRAMEBUFFER, fb);
727 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this->el_img.gl_tex, 0);
728
729 auto pixels = reinterpret_cast<u8*>(malloc(this->el_img.width * this->el_img.height * 4));
730 glReadBuffer(GL_COLOR_ATTACHMENT0);
731 glReadPixels(0, 0, this->el_img.width, this->el_img.height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
732
733 glDeleteFramebuffers(1, &fb);
734
735 int png_ptr_size;
736 auto png_ptr = stbi_write_png_to_mem(pixels, this->el_img.width * 4, this->el_img.width, this->el_img.height, 4, &png_ptr_size);
737 return SaveThemeAsset(theme_zip, this->load_ctx.img_path + ".png", png_ptr, png_ptr_size);
738 }
739
740 return true;
741 }
742
743 inline nlohmann::json &GetSettingsReference() {
744 return g_UiSettings[ul::design::MenuSettingsNames[static_cast<u32>(this->menu)]][this->ui_name];

Callers 1

SaveMethod · 0.95

Calls 2

ImageIsBuiltinMethod · 0.95
SaveThemeAssetFunction · 0.85

Tested by

no test coverage detected