mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-14 19:04:44 +00:00
ImageButton - white empty rectangle - why ? #521
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#521
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Sorry for opening another issue with the same problem, but I cannot make it work and I would appreciate it if someone could tell me why.
...
static LPDIRECT3DTEXTURE9 pTexture = NULL;
if ( D3DXCreateTextureFromFile( g_pd3dDevice, "Z:\alog\minion.jpg" , &pTexture ) != D3D_OK ){
printf("poop\n");
}
...
ImGui::ImageButton((void*)pTexture , ImVec2(236, 325), ImVec2(0,0),ImVec2(100,100),2);
...
All it draws is this, a white empty rectangle:
http://pasteboard.co/1kDzuLNa.png
I tripple checked the pTexture, it is a valid texture and also gets selected correctly (the same pointer) in the render funciton with:
g_pd3dDevice->SetTexture( 0,( LPDIRECT3DTEXTURE9)pcmd->TextureId );
I am honestly lost and need some help, what am I doing wrong ? what am I missing ?
Looking at the code in the header file
It looks like the UV range is
[(0,0) - (1,1)]but you send in quite large values for the last UV coords. What happens if you only set the size for the button and leave the rest of the values as default?It could be because SetTexture is expecting a texture pointer and not an
id. The ID could be used as a lookup in a map or similar structure.
I am not familiar enough with using D3D or textures in imgui to be 100%.
I tried it with the default UV values, same result, and also (without any idea what else I could do anymore) with the image size itself, like in the few lines of code I wrote above. Same white rectangle. :(
I changed to 3 different jpg, bmp, png, I tried Imgui:Image, Imgui:Imagebutton, with all kinds of different arguments I could think of. Always resulting in the white rectangle.
I can make the rectangle BLACK when I set the last arg, the "tin_col" to ImVec4(0,0,0,255)....not that it helps me in anyway, but maybe someone has an idea.
The pTexture, which I pass as (void*) to the ImageButton function is correct afaik, it uses the pointer as "ID".
If anyone has a running working texture loaded, maybe he could post a code snippet, so I know what i have to do in order to get this to work ?
If I use the already existing
ImTextureID tex_id = ImGui::GetIO().Fonts->TexID;
ImGui::ImageButton((void*)tex_id, ImVec2(50, 50), ImVec2(1,1),ImVec2(0,0),2);
it shows this texture.... but not the one(s) loaded from a file ...am I missing any steps in loading a texture from a file or why is it so much not showing anything -.- ?
Show us your code!
imgui.cpp:
And the function where I call imgui:Image for drawing the image:
This is what gets drawn, I can color the "own texture" boxes to whatever color I want by changin the tin_col argument in the ImageButton() function.
http://pasteboard.co/1lyUKj2g.png
it is like the alpha is not working and it always draws the color ontop...or maybe it is normal that the color is drawn first and the texture later ontop ? sadly I have no idea how this "usually" works.
Try opening the metrics window and confirm the texture id in the different draw calls.
This is while hovering with the mouse over the topmost white rectangle:
http://pasteboard.co/1lCsfijb.png
This is while hovering over the first "Draw 42 ..." line:
http://pasteboard.co/1lCvAl0d.png
"HoverID" and "tex" number differ..... I assume they would have to be the same pointer/ID ?
Well you can see the draw calls with 6 vtx here.
Hard to tell I don't know what you file is, I don't know what D3DXCreateTextureFromFile() does and how it may setup the alpha channel or how DX behave if the texture has 3 channels and we're using blending. Try disabling blending
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, false );. Try creating a texture the same way the font texture is created and work out the difference from there. Maybe some other code not shown here is destroying your texture. ImGui is very likely not culprit here, all it does is passing your pointer down the chain.HoveredId is the id of widget when they interact, it has nothnig to do with texture id.
Please preferably upload pictures to github and not pasteboard where they'll disappear eventually which makes the post not as useful for people reading in a few years (also they aren't viewable in e-mail).
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, false );
-> with this, the normal imgui font texture then also shows up as white rectangle...
So your idea that the texture itself needs to be loaded (or stored?) differently may be a good point to start.
My texture is a static pointer, which gets created on startup of the program and never gets touched by any other code but when the program exits. So this one should be fine.
What I'm basically asking is, if anyone else from the community uses DirectX and has a working texture code which he could share, so I get pointed with my nose what I'm missing or what special things have to be done in order to make imgui show the texture.
If I remove the line :
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE );
I get this :

If I leave it on, it just draws the alhpa channel if I see that correctly:

Someone with DX experience would probably instantly know what to do .... I assume my image needs to be in a special format / layers / ARGB something ?
I got it working now, so in case someone else gets the same issue, I had to do this in order to make it work:
Thanks for the help :))
@MINIONBOTS
Hmm, could you please post the whole sequence of g_pd3dDevice->SetRenderState(...) and g_pd3dDevice->SetTextureStageState(...) please ?
I ask because my best solution so far is to leave all the g_pd3dDevice->SetRenderState(...) as they are and replace ALL the g_pd3dDevice->SetTextureStageState(...) with:
This gives me this result:

However in openGL I got the correct blending that is slightly different:

(Tested both under Wine on Linux, so they should be correct).
P.S. on a closer look I have an additional problem: my texture colour channels are swapped!
But the alpha blending issue still remains (see the ImGui window).
So there is a problem with the _dx9 sample, it was using an Alpha only texture for the font and the renderer assumed that, hence the:
It works for the font texture but would ignore color in other textures=.
The DX9 default is:
I've changed it to that and changed the font texture to get RGBA instead of Alpha only, which is a waste of resource unfortunately.
In a real world scenario, you'd expect
So it is a legit problem you pointed here. On one hand I think those _impl files are merely examples of how to integrate ImGui within our own engine and the user is expected to plug their own system. On another hand realistically lots of people use low-level format provided by DX/OpenGL and it is nice if those renderer can be copied and pasted without any modifications (as suggested). So right now I'll adopt the more standard color format for the font texture and assume that people who adapt the renderer to their engine may want to use a Alpha-only texture for the font to save memory.
Thanks again :) glad it works now
@ocornut
It works perfectly for me too. Thanks :)