Examples: Cast to ImTextureID instead of void* when assigning to TexId. Applied to all examples. (#2015)
diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp
index d93f02e..d0734ef 100644
--- a/examples/imgui_impl_dx10.cpp
+++ b/examples/imgui_impl_dx10.cpp
@@ -213,7 +213,8 @@
ctx->RSSetScissorRects(1, &r);
// Bind texture, Draw
- ctx->PSSetShaderResources(0, 1, (ID3D10ShaderResourceView**)&pcmd->TextureId);
+ ID3D10ShaderResourceView* texture_srv = (ID3D10ShaderResourceView*)pcmd->TextureId;
+ ctx->PSSetShaderResources(0, 1, &texture_srv);
ctx->DrawIndexed(pcmd->ElemCount, idx_offset, vtx_offset);
}
idx_offset += pcmd->ElemCount;
@@ -279,7 +280,7 @@
}
// Store our identifier
- io.Fonts->TexID = (void *)g_pFontTextureView;
+ io.Fonts->TexID = (ImTextureID)g_pFontTextureView;
// Create texture sampler
{
diff --git a/examples/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp
index eda8ce4..2f6f5a7 100644
--- a/examples/imgui_impl_dx11.cpp
+++ b/examples/imgui_impl_dx11.cpp
@@ -218,7 +218,8 @@
ctx->RSSetScissorRects(1, &r);
// Bind texture, Draw
- ctx->PSSetShaderResources(0, 1, (ID3D11ShaderResourceView**)&pcmd->TextureId);
+ ID3D11ShaderResourceView* texture_srv = (ID3D11ShaderResourceView*)pcmd->TextureId;
+ ctx->PSSetShaderResources(0, 1, &texture_srv);
ctx->DrawIndexed(pcmd->ElemCount, idx_offset, vtx_offset);
}
idx_offset += pcmd->ElemCount;
@@ -286,7 +287,7 @@
}
// Store our identifier
- io.Fonts->TexID = (void *)g_pFontTextureView;
+ io.Fonts->TexID = (ImTextureID)g_pFontTextureView;
// Create texture sampler
{
diff --git a/examples/imgui_impl_dx9.cpp b/examples/imgui_impl_dx9.cpp
index 9ee56db..d5bbc28 100644
--- a/examples/imgui_impl_dx9.cpp
+++ b/examples/imgui_impl_dx9.cpp
@@ -177,7 +177,8 @@
else
{
const RECT r = { (LONG)(pcmd->ClipRect.x - pos.x), (LONG)(pcmd->ClipRect.y - pos.y), (LONG)(pcmd->ClipRect.z - pos.x), (LONG)(pcmd->ClipRect.w - pos.y) };
- g_pd3dDevice->SetTexture(0, (LPDIRECT3DTEXTURE9)pcmd->TextureId);
+ const LPDIRECT3DTEXTURE9 texture = (LPDIRECT3DTEXTURE9)pcmd->TextureId;
+ g_pd3dDevice->SetTexture(0, texture);
g_pd3dDevice->SetScissorRect(&r);
g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, vtx_offset, 0, (UINT)cmd_list->VtxBuffer.Size, idx_offset, pcmd->ElemCount/3);
}
@@ -228,7 +229,7 @@
g_FontTexture->UnlockRect(0);
// Store our identifier
- io.Fonts->TexID = (void *)g_FontTexture;
+ io.Fonts->TexID = (ImTextureID)g_FontTexture;
return true;
}
diff --git a/examples/imgui_impl_marmalade.cpp b/examples/imgui_impl_marmalade.cpp
index 6d78a1a..23ced8f 100644
--- a/examples/imgui_impl_marmalade.cpp
+++ b/examples/imgui_impl_marmalade.cpp
@@ -190,7 +190,7 @@
g_FontTexture->Upload();
// Store our identifier
- io.Fonts->TexID = (void *)g_FontTexture;
+ io.Fonts->TexID = (ImTextureID)g_FontTexture;
return true;
}
diff --git a/examples/imgui_impl_metal.mm b/examples/imgui_impl_metal.mm
index a4d235c..678cd26 100644
--- a/examples/imgui_impl_metal.mm
+++ b/examples/imgui_impl_metal.mm
@@ -98,7 +98,7 @@
[g_sharedMetalContext makeFontTextureWithDevice:device];
ImGuiIO& io = ImGui::GetIO();
- io.Fonts->TexID = (__bridge void *)g_sharedMetalContext.fontTexture;
+ io.Fonts->TexID = (__bridge void *)g_sharedMetalContext.fontTexture; // ImTextureID == void*
return (g_sharedMetalContext.fontTexture != nil);
}
diff --git a/examples/imgui_impl_opengl2.cpp b/examples/imgui_impl_opengl2.cpp
index c70d9fe..3ff1cf7 100644
--- a/examples/imgui_impl_opengl2.cpp
+++ b/examples/imgui_impl_opengl2.cpp
@@ -182,7 +182,7 @@
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
// Store our identifier
- io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
+ io.Fonts->TexID = (ImTextureID)(intptr_t)g_FontTexture;
// Restore state
glBindTexture(GL_TEXTURE_2D, last_texture);
diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp
index c00f3c7..5f7095c 100644
--- a/examples/imgui_impl_opengl3.cpp
+++ b/examples/imgui_impl_opengl3.cpp
@@ -279,7 +279,7 @@
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
// Store our identifier
- io.Fonts->TexID = (void *)(intptr_t)g_FontTexture;
+ io.Fonts->TexID = (ImTextureID)(intptr_t)g_FontTexture;
// Restore state
glBindTexture(GL_TEXTURE_2D, last_texture);
diff --git a/examples/imgui_impl_vulkan.cpp b/examples/imgui_impl_vulkan.cpp
index 7d6f749..9ec0a12 100644
--- a/examples/imgui_impl_vulkan.cpp
+++ b/examples/imgui_impl_vulkan.cpp
@@ -461,7 +461,7 @@
}
// Store our identifier
- io.Fonts->TexID = (void *)(intptr_t)g_FontImage;
+ io.Fonts->TexID = (ImTextureID)(intptr_t)g_FontImage;
return true;
}
diff --git a/imgui.cpp b/imgui.cpp
index a8b4dca..1f29a71 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -1671,7 +1671,7 @@
return NULL;
}
if (padding_bytes > 0)
- memset((void *)(((char*)file_data) + file_size), 0, (size_t)padding_bytes);
+ memset((void*)(((char*)file_data) + file_size), 0, (size_t)padding_bytes);
fclose(f);
if (out_file_size)
@@ -8476,7 +8476,7 @@
// Default to using texture ID as ID. User can still push string/integer prefixes.
// We could hash the size/uv to create a unique ID but that would prevent the user from animating UV.
- PushID((void *)user_texture_id);
+ PushID((void*)user_texture_id);
const ImGuiID id = window->GetID("#image");
PopID();
diff --git a/misc/fonts/binary_to_compressed_c.cpp b/misc/fonts/binary_to_compressed_c.cpp
index e373e69..08b102d 100644
--- a/misc/fonts/binary_to_compressed_c.cpp
+++ b/misc/fonts/binary_to_compressed_c.cpp
@@ -71,7 +71,7 @@
if (fseek(f, 0, SEEK_END) || (data_sz = (int)ftell(f)) == -1 || fseek(f, 0, SEEK_SET)) { fclose(f); return false; }
char* data = new char[data_sz+4];
if (fread(data, 1, data_sz, f) != (size_t)data_sz) { fclose(f); delete[] data; return false; }
- memset((void *)(((char*)data) + data_sz), 0, 4);
+ memset((void*)(((char*)data) + data_sz), 0, 4);
fclose(f);
// Compress