Browse Source

Examples: Not clearing input data/tex data in atlas (will be required for dynamic atlas anyway). Effectively fix resizing in DX examples.

+ Standardized comments.
ocornut 9 years ago
parent
commit
6cee2fca94

+ 1 - 6
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);

+ 2 - 7
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()

+ 2 - 6
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;
 }
 

+ 7 - 6
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);

+ 3 - 8
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;
 }
 

+ 9 - 7
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()

+ 3 - 6
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;

+ 6 - 6
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()

+ 6 - 6
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;
 }