code:
-----code.h--------------------
unsigned char* pixels;
int width ;
int height, bytes_per_pixels;
-----code.cpp----------------------------
ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontFromFileTTF("C:\Windows\Fonts\simhei.ttf", 13.0f, NULL,io.Fonts->GetGlyphRangesChinese());
Is that anything wrong?
I don't think so, assuming that font file exists.
What is your problem?
The problem is all the letters become a black square:(
Have you uploaded the texture into video memory with whatever backend/engine you are using?
Which renderer are you using? The rendering code needs to bind a texture.
Read about ImTextureId and the different examples.
I had this happen too when you use a font with many glyphs like chinese and with too large of a font scale. Seems like the generated font texture got too big for the GPU to handle
Same here, had 4 ttf files, goal was to cover all of the language in one texture. It kept crashing on smaller GPUs, ocornut did a change later on ( https://github.com/ocornut/imgui/commit/65a525550ecf48e14f20681b081b1d9c8c136563 ) which solved it for me.
This is what I am doing right now, maybe it helps you:

I don't think that (path+"\\...").c_str() will work. Unless I'm mistaken the temporary (can) gets cleaned up before the function is called.
Instead do something like:
std::string filename = path+"\\...";
io.Font->AddFontFromFileTTF(filename.c_str(), ...);
@ocornut My backend/engine is openFrameworks(opengl).How to upload and bind the texture? I know about opengl little.I just use it as gui for c++:( :::::
@ratchetfreak you are wrong, because its const its life time is extended.
@alanyangbo Closing this now, hope it is ok.