diff --git a/examples/allegro5_example/imgui_impl_a5.cpp b/examples/allegro5_example/imgui_impl_a5.cpp index ecbf26290..0b1b8ed2e 100644 --- a/examples/allegro5_example/imgui_impl_a5.cpp +++ b/examples/allegro5_example/imgui_impl_a5.cpp @@ -88,9 +88,8 @@ void ImGui_ImplA5_RenderDrawLists(ImDrawData* draw_data) bool Imgui_ImplA5_CreateDeviceObjects() { + // Build texture atlas ImGuiIO &io = ImGui::GetIO(); - - // Build texture unsigned char *pixels; int width, height; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); @@ -125,10 +124,6 @@ bool Imgui_ImplA5_CreateDeviceObjects() io.Fonts->TexID = (void*)cloned_img; g_Texture = cloned_img; - // Cleanup (don't clear the input data if you want to append new fonts later) - io.Fonts->ClearInputData(); - io.Fonts->ClearTexData(); - // Create an invisible mouse cursor // Because al_hide_mouse_cursor() seems to mess up with the actual inputs.. ALLEGRO_BITMAP* mouse_cursor = al_create_bitmap(8,8); diff --git a/examples/directx11_example/imgui_impl_dx11.cpp b/examples/directx11_example/imgui_impl_dx11.cpp index 001e912b3..44be6e0fd 100644 --- a/examples/directx11_example/imgui_impl_dx11.cpp +++ b/examples/directx11_example/imgui_impl_dx11.cpp @@ -224,14 +224,13 @@ IMGUI_API LRESULT ImGui_ImplDX11_WndProcHandler(HWND, UINT msg, WPARAM wParam, L static void ImGui_ImplDX11_CreateFontsTexture() { + // Build texture atlas ImGuiIO& io = ImGui::GetIO(); - - // Build unsigned char* pixels; int width, height; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); - // Create DX11 texture + // Upload texture to graphics system { D3D11_TEXTURE2D_DESC texDesc; ZeroMemory(&texDesc, sizeof(texDesc)); @@ -280,10 +279,6 @@ static void ImGui_ImplDX11_CreateFontsTexture() samplerDesc.MaxLOD = 0.f; g_pd3dDevice->CreateSamplerState(&samplerDesc, &g_pFontSampler); } - - // Cleanup (don't clear the input data if you want to append new fonts later) - io.Fonts->ClearInputData(); - io.Fonts->ClearTexData(); } bool ImGui_ImplDX11_CreateDeviceObjects() diff --git a/examples/directx9_example/imgui_impl_dx9.cpp b/examples/directx9_example/imgui_impl_dx9.cpp index db31bd5d6..907a8941c 100644 --- a/examples/directx9_example/imgui_impl_dx9.cpp +++ b/examples/directx9_example/imgui_impl_dx9.cpp @@ -230,14 +230,13 @@ void ImGui_ImplDX9_Shutdown() static bool ImGui_ImplDX9_CreateFontsTexture() { + // Build texture atlas ImGuiIO& io = ImGui::GetIO(); - - // Build unsigned char* pixels; int width, height, bytes_per_pixel; io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height, &bytes_per_pixel); - // Create DX9 texture + // Upload texture to graphics system g_FontTexture = NULL; if (D3DXCreateTexture(g_pd3dDevice, width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8, D3DPOOL_DEFAULT, &g_FontTexture) < 0) return false; @@ -251,9 +250,6 @@ static bool ImGui_ImplDX9_CreateFontsTexture() // Store our identifier io.Fonts->TexID = (void *)g_FontTexture; - // Cleanup (don't clear the input data if you want to append new fonts later) - io.Fonts->ClearInputData(); - io.Fonts->ClearTexData(); return true; } diff --git a/examples/ios_example/imguiex/imgui_impl_ios.mm b/examples/ios_example/imguiex/imgui_impl_ios.mm index a8f6f6418..2b8c3531f 100644 --- a/examples/ios_example/imguiex/imgui_impl_ios.mm +++ b/examples/ios_example/imguiex/imgui_impl_ios.mm @@ -692,12 +692,15 @@ static void ImGui_ImplIOS_RenderDrawLists (ImDrawData *draw_data) void ImGui_ImplIOS_CreateFontsTexture() { + // Build texture atlas ImGuiIO& io = ImGui::GetIO(); - unsigned char* pixels; int width, height; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits for OpenGL3 demo because it is more likely to be compatible with user's existing shader. + // Upload texture to graphics system + GLint last_texture; + glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); glGenTextures(1, &g_FontTexture); glBindTexture(GL_TEXTURE_2D, g_FontTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -706,10 +709,9 @@ void ImGui_ImplIOS_CreateFontsTexture() // Store our identifier io.Fonts->TexID = (void *)(intptr_t)g_FontTexture; - - // Cleanup (don't clear the input data if you want to append new fonts later) - io.Fonts->ClearInputData(); - io.Fonts->ClearTexData(); + + // Restore state + glBindTexture(GL_TEXTURE_2D, last_texture); } bool ImGui_ImplIOS_CreateDeviceObjects() @@ -767,7 +769,6 @@ bool ImGui_ImplIOS_CreateDeviceObjects() } #endif - glAttachShader(g_ShaderHandle, g_VertHandle); glAttachShader(g_ShaderHandle, g_FragHandle); glLinkProgram(g_ShaderHandle); diff --git a/examples/marmalade_example/imgui_impl_marmalade.cpp b/examples/marmalade_example/imgui_impl_marmalade.cpp index 9f1c9a494..a9f9bf2e1 100644 --- a/examples/marmalade_example/imgui_impl_marmalade.cpp +++ b/examples/marmalade_example/imgui_impl_marmalade.cpp @@ -167,14 +167,13 @@ int32 ImGui_Marmalade_CharCallback(void* SystemData, void* userData) bool ImGui_Marmalade_CreateDeviceObjects() { - ImGuiIO& io = ImGui::GetIO(); - // Build texture atlas + ImGuiIO& io = ImGui::GetIO(); unsigned char* pixels; int width, height; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); - // Create texture + // Upload texture to graphics system g_FontTexture = new CIwTexture(); g_FontTexture->SetModifiable(true); CIwImage& image = g_FontTexture->GetImage(); @@ -187,13 +186,9 @@ bool ImGui_Marmalade_CreateDeviceObjects() g_FontTexture->SetFiltering(false); g_FontTexture->Upload(); - // Store the pointer + // Store our identifier io.Fonts->TexID = (void *)g_FontTexture; - // Cleanup (don't clear the input data if you want to append new fonts later) - io.Fonts->ClearInputData(); - io.Fonts->ClearTexData(); - return true; } diff --git a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp index 8195acf3b..3b3d1b43c 100644 --- a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp +++ b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp @@ -161,16 +161,17 @@ void ImGui_ImplGlfwGL3_CharCallback(GLFWwindow*, unsigned int c) io.AddInputCharacter((unsigned short)c); } -void ImGui_ImplGlfwGL3_CreateFontsTexture() +bool ImGui_ImplGlfwGL3_CreateFontsTexture() { - ImGuiIO& io = ImGui::GetIO(); - // Build texture atlas + ImGuiIO& io = ImGui::GetIO(); unsigned char* pixels; int width, height; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits for OpenGL3 demo because it is more likely to be compatible with user's existing shader. - // Create OpenGL texture + // Upload texture to graphics system + GLint last_texture; + glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); glGenTextures(1, &g_FontTexture); glBindTexture(GL_TEXTURE_2D, g_FontTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -180,9 +181,10 @@ void ImGui_ImplGlfwGL3_CreateFontsTexture() // Store our identifier io.Fonts->TexID = (void *)(intptr_t)g_FontTexture; - // Cleanup (don't clear the input data if you want to append new fonts later) - io.Fonts->ClearInputData(); - io.Fonts->ClearTexData(); + // Restore state + glBindTexture(GL_TEXTURE_2D, last_texture); + + return true; } bool ImGui_ImplGlfwGL3_CreateDeviceObjects() diff --git a/examples/opengl_example/imgui_impl_glfw.cpp b/examples/opengl_example/imgui_impl_glfw.cpp index 0cda99af4..ab37c2f1f 100644 --- a/examples/opengl_example/imgui_impl_glfw.cpp +++ b/examples/opengl_example/imgui_impl_glfw.cpp @@ -145,14 +145,13 @@ void ImGui_ImplGlfw_CharCallback(GLFWwindow*, unsigned int c) bool ImGui_ImplGlfw_CreateDeviceObjects() { - ImGuiIO& io = ImGui::GetIO(); - // Build texture atlas + ImGuiIO& io = ImGui::GetIO(); unsigned char* pixels; int width, height; io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height); - // Create OpenGL texture + // Upload texture to graphics system GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); glGenTextures(1, &g_FontTexture); @@ -164,9 +163,7 @@ bool ImGui_ImplGlfw_CreateDeviceObjects() // Store our identifier io.Fonts->TexID = (void *)(intptr_t)g_FontTexture; - // Cleanup (don't clear the input data if you want to append new fonts later) - io.Fonts->ClearInputData(); - io.Fonts->ClearTexData(); + // Restore state glBindTexture(GL_TEXTURE_2D, last_texture); return true; diff --git a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp index 90d151884..fcef265e3 100644 --- a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp +++ b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp @@ -166,14 +166,15 @@ bool ImGui_ImplSdlGL3_ProcessEvent(SDL_Event* event) void ImGui_ImplSdlGL3_CreateFontsTexture() { - ImGuiIO& io = ImGui::GetIO(); - // Build texture atlas + ImGuiIO& io = ImGui::GetIO(); unsigned char* pixels; int width, height; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bits for OpenGL3 demo because it is more likely to be compatible with user's existing shader. - // Create OpenGL texture + // Upload texture to graphics system + GLint last_texture; + glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); glGenTextures(1, &g_FontTexture); glBindTexture(GL_TEXTURE_2D, g_FontTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -183,9 +184,8 @@ void ImGui_ImplSdlGL3_CreateFontsTexture() // Store our identifier io.Fonts->TexID = (void *)(intptr_t)g_FontTexture; - // Cleanup (don't clear the input data if you want to append new fonts later) - io.Fonts->ClearInputData(); - io.Fonts->ClearTexData(); + // Restore state + glBindTexture(GL_TEXTURE_2D, last_texture); } bool ImGui_ImplSdlGL3_CreateDeviceObjects() diff --git a/examples/sdl_opengl_example/imgui_impl_sdl.cpp b/examples/sdl_opengl_example/imgui_impl_sdl.cpp index 140eaa505..f3125aae5 100644 --- a/examples/sdl_opengl_example/imgui_impl_sdl.cpp +++ b/examples/sdl_opengl_example/imgui_impl_sdl.cpp @@ -146,14 +146,15 @@ bool ImGui_ImplSdl_ProcessEvent(SDL_Event* event) bool ImGui_ImplSdl_CreateDeviceObjects() { + // Build texture atlas ImGuiIO& io = ImGui::GetIO(); - - // Build texture unsigned char* pixels; int width, height; io.Fonts->GetTexDataAsAlpha8(&pixels, &width, &height); - // Create texture + // Upload texture to graphics system + GLint last_texture; + glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); glGenTextures(1, &g_FontTexture); glBindTexture(GL_TEXTURE_2D, g_FontTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -163,9 +164,8 @@ bool ImGui_ImplSdl_CreateDeviceObjects() // Store our identifier io.Fonts->TexID = (void *)(intptr_t)g_FontTexture; - // Cleanup (don't clear the input data if you want to append new fonts later) - io.Fonts->ClearInputData(); - io.Fonts->ClearTexData(); + // Restore state + glBindTexture(GL_TEXTURE_2D, last_texture); return true; }