mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-14 19:04:44 +00:00
Rendering am image #561
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#561
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?
Hello basically this is not an issue , but a noob question, so please don't blame on me.
I am trying to use the Image function, i pass my texture id as parameter, but i get the font atlas rendered instead.
Sorry if i posted in the wrong place
Your TextureId is basically passed unmodified to your rendering function at the end of the pipe. So that rendering function (which is your code, or any function copied from the imgui_impl_xxx files) must select the texture there.
For example, the OpenGL example stores a GL texture identifier in ImTextureId and calls glBindTexture() before the draw call. The DirectX9 examples stores a LPDIRECT3DTEXTURE9 here, etc.
You can pass a pointer or whatever makes sense in your engine to "identify" a unique texture, as long as both the caller and the rendering function agrees.
Basically i am doing this, assuming my texture is correctly loaded ,and canvas size correctly computed
is that sufficent ? or do i need to use another setupping function ?
This code alone doesn't mean anything without the corresponding code in the renderer.
Also we don't know the type of
mytexture.id.The renderer in imgui_impl_glfw for example are doing:
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);So assume a GLuint stored in the TextureId field.
Here you are storing a pointer to GLuint instead. So maybe just remove the & operator to pass the GLuint, change
&(GLuint)mytexture.Idto(void*)(GLuint)mytexture.id, that is assuming your rendering does that same as above.If i remove the '&' i get an error, the functions expects a void pointer so i casted to GLuint, i noticed that if i pass a null value i get always the font atlas rendered.
You haven't answered
(void*)myid(no address taking with &!)yes
ImGui::Image( (void*)mytexture.Id,canvas_size );
but i get nothing rendered , i have taken a look at the glfw3 rendered and i see that the last texture id is saved and restored after the main drawing fuction has been called, so i think the problem is that the texture id is not passed and doesn't get stored , correct me if i am wrong.
I have taken a look at main.cpp in the glf3 example and i copied, the problem is with the Image function.
I don't know if i have to open another issue but i get these
1>e:\project39\project0\imgui\imgui.cpp(6101): warning C4723: potential divide by 0
1>e:\project39\project0\imgui\imgui.cpp(6144): warning C4723: potential divide by 0
You haven't answered
Will look into the warnings, I think they are false positive, please post the lines themselves seeing you aren't working with the latest master.
EDIT Please put more effort into reporting information, looking into values and stepping with a debugger, etc. I can't be possibly debugging everyone's code.
What do you mean for type ?? its an unsigned int used to store texture id
here is how i generate texture id
image has been loaded with stb image loader and its a png
my rendering code is drawing a wire frame, i have setup everything to minimize interferences
do i need to enable texture drawing ? according to me not or i wouldn't see rendered font as well
I had no idea that your program was running OpenGL or that you were storing gl identifier, hence asking for clarification.
Call ShowMetricsWindow() to inspect the values passed to draw calls, and compare them to your values. All the code is at your disposal in imgui_impl_glfw* you can also step and look at that.
Please put more effort into reporting information, looking into values and stepping with a debugger, etc. I can't be possibly debugging everyone's code.
The code in imgui.cpp/imgui_draw.cpp definitively works seeing it only copy your value around and does nothing else with it. As long as the value fits in a
void*you should be set.It it not impossible that ImDrawList may have bugs if you are doing some manual / funky use of the draw list, but just calling ImGui::Image() shouldn't.
Ok i can understand
A bit overkill-inception but: I have updated the Metrics window to display wireframe of each triangle in a draw-call. So you can browse individual draw-calls and visualize the triangles involved, and you can see the texture identifier used for said draw call.
ocornut/imgui@367c53967fOK, will try when i'll be back home
Using showmetrics, i get the triangles making up the texture, and it solved the problem, the
texture format is it meant to be rgba.
Thanks for the help
Good to know for next time someone ask that.
That has to do with the renderer code not imgui. I don't know what OpenGL does if you glBind a non-RGBA texture and use the default shader (aka no shader program). It would be good to clarify what OpenGL does. Which renderer were you using?
What was the format of your texture and how was the texture created? Was your texture even loaded correctly? (In which case it isn't a renderer problem but a loading problem). You posted glTexImage2D() code above using GL_RGBA and now you are saying that your texture wasn't RGBA.
Typically a high-level engine would pass "material" data which would carry one or more texture(s) along with render state information (such as shader, blend state).
Ok, you are right , i was uploading an image with stb image loader and it defaults to rgb , thus i created an rgba texture in opengl, this somehow messed up with the uploading of the texture itself, so i was sure that the texture was correctly loaded and i thought the problem was passing the correct texture id.
The correct steps are
1 ) make sure you load an rgba texture ( if its not rgba , convert it by expanding up to the alpah bit and set it to 255 )
2) upload in opengl
3) obtain the id
4) pass the id as (GLuint*)texture_id to the ImGui::Image(.....
I am using visual studio 2013 , opengl 3.3+ and glfw as context handler
To debug i programmatically created a checkered board texture in rgba format
I am pretty sure it would work with other texture formats as well, as long as your texture data/upload format are matching.