int loadDemoData(struct NVGcontext* vg, struct DemoData* data) { int i; if (vg == NULL) return -1; for (i = 0; i < 12; i++) { char file[128]; snprintf(file, 128, "../example/images/image%d.jpg", i+1); data->images[i] = nvgCreateImage(vg, file); if (data->images[i] == 0) { printf("Could not load %s.\n", file); return -1; } } data->fontIcons = nvgCreateFont(vg, "icons", "../example/entypo.ttf"); if (data->fontIcons == -1) { printf("Could not add font icons.\n"); return -1; } data->fontNormal = nvgCreateFont(vg, "sans", "../example/Roboto-Regular.ttf"); if (data->fontNormal == -1) { printf("Could not add font italic.\n"); return -1; } data->fontBold = nvgCreateFont(vg, "sans-bold", "../example/Roboto-Bold.ttf"); if (data->fontBold == -1) { printf("Could not add font bold.\n"); return -1; } return 0; }
static struct icon ICON(NVGcontext *vg, const char *path) { struct icon i; i.image = nvgCreateImage(vg, path, 0); i.img = zr_image_id(i.image); return i; }
ImageGlyph::ImageGlyph(const std::string& file, AlloyContext* context, bool mipmap) : Glyph(GetFileNameWithoutExtension(file), GlyphType::Image, 0, 0), file( file) { handle = nvgCreateImage(context->nvgContext, file.c_str(), (mipmap) ? NVG_IMAGE_GENERATE_MIPMAPS : 0); int w, h; nvgImageSize(context->nvgContext, handle, &w, &h); width = (pixel) w; height = (pixel) h; }
JNIEXPORT int JNICALL Java_firststep_internal_NVG_createImage (JNIEnv *e, jclass c, jlong ctx, jstring fname, jint flags) { int r; const char *filename = (*e)->GetStringUTFChars(e, fname, 0); r = nvgCreateImage((NVGcontext*)ctx, filename, flags); (*e)->ReleaseStringUTFChars(e, fname, filename); return r; }
void setup() { size(640, 320); glfwSetKeyCallback(window, keyevent); glfwSetCharCallback(window, charevent); uictx = uiCreateContext(); uiMakeCurrent(uictx); bndSetFont(nvgCreateFont(vg, "system", "../3rdparty/blendish/DejaVuSans.ttf")); bndSetIconImage(nvgCreateImage(vg, "../3rdparty/blendish/blender_icons16.png", NVG_IMAGE_GENERATE_MIPMAPS)); }
Image& NanoInk::fetchImage(Image& image, bool tile) { if(image.d_index == 0) { image.d_index = nvgCreateImage(mCtx, (mLayer.target().window().resourcePath() + "interface/uisprites/" + image.d_name + ".png").c_str(), tile ? (NVG_IMAGE_REPEATX | NVG_IMAGE_REPEATY) : 0); nvgImageSize(mCtx, image.d_index, &image.d_width, &image.d_height); #ifdef NANO_ATLAS ImageRect& rect = mLayer.target().window().atlas().findSpriteRect(image.d_name + ".png"); image.d_left = rect.x; image.d_top = rect.y; #endif } return image; }
void other_begin(BATB& batb) { auto* nvg = batb.gl.nvg_context; //glClearColor( 0, 0, 0.3, 0 ); auto image_path = file::static_data( "batb/openforest-512x256.png" ); image = nvgCreateImage( nvg, image_path.c_str(), 0 ); int w, h; nvgImageSize( nvg, image, &w, &h ); image_wth = w; image_hth = h; }
bool t2Image::loadImage(string path) { img = nvgCreateImage(t2GetContext(), path.c_str(), 0); if(!img) { bLoaded = false; t2PrintError("图片读取失败,可能是路径有误"); return false; } else { bLoaded = true; nvgImageSize(t2GetContext(), img, &width, &height); return true; } }
int loadDemoData(struct NVGcontext* vg, struct DemoData* data) { for (uint32_t ii = 0; ii < 12; ++ii) { char file[128]; bx::snprintf(file, 128, "images/image%d.jpg", ii+1); data->images[ii] = nvgCreateImage(vg, file, 0); if (data->images[ii] == 0) { printf("Could not load %s.\n", file); return -1; } } data->fontIcons = nvgCreateFont(vg, "icons", "font/entypo.ttf"); if (data->fontIcons == -1) { printf("Could not add font icons.\n"); return -1; } data->fontNormal = nvgCreateFont(vg, "sans", "font/roboto-regular.ttf"); if (data->fontNormal == -1) { printf("Could not add font italic.\n"); return -1; } data->fontBold = nvgCreateFont(vg, "sans-bold", "font/roboto-bold.ttf"); if (data->fontBold == -1) { printf("Could not add font bold.\n"); return -1; } return 0; }
std::vector<std::pair<int, std::string>> loadImageDirectory(NVGcontext *ctx, const std::string &path) { std::vector<std::pair<int, std::string> > result; #if !defined(_WIN32) DIR *dp = opendir(path.c_str()); if (!dp) throw std::runtime_error("Could not open image directory!"); struct dirent *ep; while ((ep = readdir(dp))) { const char *fname = ep->d_name; #else WIN32_FIND_DATA ffd; std::string searchPath = path + "/*.*"; HANDLE handle = FindFirstFileA(searchPath.c_str(), &ffd); if (handle == INVALID_HANDLE_VALUE) throw std::runtime_error("Could not open image directory!"); do { const char *fname = ffd.cFileName; #endif if (strstr(fname, "png") == nullptr) continue; std::string fullName = path + "/" + std::string(fname); int img = nvgCreateImage(ctx, fullName.c_str(), 0); if (img == 0) throw std::runtime_error("Could not open image data!"); result.push_back( std::make_pair(img, fullName.substr(0, fullName.length() - 4))); #if !defined(_WIN32) } closedir(dp); #else } while (FindNextFileA(handle, &ffd) != 0); FindClose(handle); #endif return result; }
void init(NVGcontext *vg) { bndSetFont(nvgCreateFont(vg, "system", "DejaVuSans.ttf")); bndSetIconImage(nvgCreateImage(vg, "blender_icons16.png", 0)); }
int _main_(int _argc, char** _argv) { Args args(_argc, _argv); uint32_t width = 1280; uint32_t height = 720; uint32_t debug = BGFX_DEBUG_TEXT; uint32_t reset = BGFX_RESET_VSYNC; bgfx::init(args.m_type, args.m_pciId); bgfx::reset(width, height, reset); // Enable debug text. bgfx::setDebug(debug); // Set view 0 clear state. bgfx::setViewClear(0 , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH , 0x303030ff , 1.0f , 0 ); imguiCreate(); NVGcontext* nvg = nvgCreate(1, 0); bgfx::setViewSeq(0, true); DemoData data; loadDemoData(nvg, &data); bndSetFont(nvgCreateFont(nvg, "droidsans", "font/droidsans.ttf") ); bndSetIconImage(nvgCreateImage(nvg, "images/blender_icons16.png", 0) ); int64_t timeOffset = bx::getHPCounter(); entry::MouseState mouseState; while (!entry::processEvents(width, height, debug, reset, &mouseState) ) { int64_t now = bx::getHPCounter(); const double freq = double(bx::getHPFrequency() ); float time = (float)( (now-timeOffset)/freq); // Set view 0 default viewport. bgfx::setViewRect(0, 0, 0, width, height); // This dummy draw call is here to make sure that view 0 is cleared // if no other draw calls are submitted to view 0. bgfx::touch(0); // Use debug font to print information about this example. bgfx::dbgTextClear(); bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/20-nanovg"); bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: NanoVG is small antialiased vector graphics rendering library."); nvgBeginFrame(nvg, width, height, 1.0f); renderDemo(nvg, float(mouseState.m_mx), float(mouseState.m_my), float(width), float(height), time, 0, &data); nvgEndFrame(nvg); // Advance to next frame. Rendering thread will be kicked to // process submitted rendering primitives. bgfx::frame(); } freeDemoData(nvg, &data); nvgDelete(nvg); imguiDestroy(); // Shutdown bgfx. bgfx::shutdown(); return 0; }
uint32 loadImage(const std::string& filename) { if (!m_inited) return 0; return nvgCreateImage(m_vg, filename.c_str(), 0); }
virtual void initializeGL( osg::State* state ) { std::string file = osgDB::findDataFile( "Images/osg256.png" ); int img = nvgCreateImage( _vg, file.c_str(), 0 ); if ( img!=0 ) _loadedImages.push_back( img ); }