mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 20:18:47 +02:00
ImFont::GetTextureData API allow to retrieve 8/32 bits data + lazily load defaults font
Examples: OpenGL3 and DirectX11 back to using 32-bits texture solely for ease of integration.
This commit is contained in:
@ -148,14 +148,17 @@ void InitGL()
|
||||
|
||||
void LoadFontTexture(ImFont* font)
|
||||
{
|
||||
IM_ASSERT(font && font->IsLoaded());
|
||||
unsigned char* pixels;
|
||||
int width, height;
|
||||
font->GetTextureDataAlpha8(&pixels, &width, &height);
|
||||
|
||||
GLuint tex_id;
|
||||
glGenTextures(1, &tex_id);
|
||||
glBindTexture(GL_TEXTURE_2D, tex_id);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, font->TexWidth, font->TexHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, font->TexPixels);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
font->TexID = (void *)(intptr_t)tex_id;
|
||||
}
|
||||
|
||||
@ -186,10 +189,9 @@ void InitImGui()
|
||||
io.SetClipboardTextFn = ImImpl_SetClipboardTextFn;
|
||||
io.GetClipboardTextFn = ImImpl_GetClipboardTextFn;
|
||||
|
||||
// Load font
|
||||
io.Font->LoadDefault();
|
||||
// Load font (optionally load a custom TTF font)
|
||||
//io.Font->LoadFromFileTTF("myfont.ttf", font_size_px, ImFont::GetGlyphRangesDefault());
|
||||
//io.Font->DisplayOffset.y += 0.0f;
|
||||
//io.Font->DisplayOffset.y += 1.0f;
|
||||
LoadFontTexture(io.Font);
|
||||
}
|
||||
|
||||
@ -249,11 +251,6 @@ int main(int argc, char** argv)
|
||||
show_test_window ^= ImGui::Button("Test Window");
|
||||
show_another_window ^= ImGui::Button("Another Window");
|
||||
|
||||
static ImFont* font2 = NULL;
|
||||
if (!font2) { font2 = new ImFont(); font2->LoadFromFileTTF("../../extra_fonts/ArialUni.ttf", 30.0f); LoadFontTexture(font2); }
|
||||
ImGui::Image(font2->TexID, ImVec2((float)font2->TexWidth, (float)font2->TexHeight));
|
||||
//ImGui::GetWindowDrawList()->AddText(font2, 30.0f, ImGui::GetCursorScreenPos(), 0xFFFFFFFF, "Another font");
|
||||
|
||||
// Calculate and show frame rate
|
||||
static float ms_per_frame[120] = { 0 };
|
||||
static int ms_per_frame_idx = 0;
|
||||
|
Reference in New Issue
Block a user