Rendering am image #561

Closed
opened 2016-03-22 17:22:06 +00:00 by v71 · 16 comments
v71 commented 2016-03-22 17:22:06 +00:00 (Migrated from github.com)

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

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
ocornut commented 2016-03-22 17:30:21 +00:00 (Migrated from github.com)

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.

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.
v71 commented 2016-03-22 17:50:27 +00:00 (Migrated from github.com)

Basically i am doing this, assuming my texture is correctly loaded ,and canvas size correctly computed

    ImGui::Image( &(GLuint)mytexture.Id,canvas_size );

is that sufficent ? or do i need to use another setupping function ?

Basically i am doing this, assuming my texture is correctly loaded ,and canvas size correctly computed ``` ImGui::Image( &(GLuint)mytexture.Id,canvas_size ); ``` is that sufficent ? or do i need to use another setupping function ?
ocornut commented 2016-03-22 17:52:49 +00:00 (Migrated from github.com)

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.Id to (void*)(GLuint)mytexture.id, that is assuming your rendering does that same as above.

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.Id` to `(void*)(GLuint)mytexture.id`, that is assuming your rendering does that same as above.
v71 commented 2016-03-22 18:15:56 +00:00 (Migrated from github.com)

This code alone doesn't mean anything without the corresponding code in the renderer.

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.

> This code alone doesn't mean anything without the corresponding code in the renderer. 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.
ocornut commented 2016-03-22 18:27:06 +00:00 (Migrated from github.com)

You haven't answered

  • what is the type of your variable
  • what is your rendering code doing
  • have you tried (void*)myid (no address taking with &!)
You haven't answered - what is the type of your variable - what is your rendering code doing - have you tried `(void*)myid` (no address taking with &!)
v71 commented 2016-03-22 18:35:50 +00:00 (Migrated from github.com)

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

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
ocornut commented 2016-03-22 18:40:56 +00:00 (Migrated from github.com)

You haven't answered

  • what is the type of your mytexture.Id variable, I have no idea of the storage type nor what it does/means to your engine.
  • what is your rendering code doing.

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.

You haven't answered - what is the type of your mytexture.Id variable, I have no idea of the storage type nor what it does/means to your engine. - what is your rendering code doing. 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.
v71 commented 2016-03-22 18:45:22 +00:00 (Migrated from github.com)

What do you mean for type ?? its an unsigned int used to store texture id
here is how i generate texture id

        glGenTextures(1, &Id);
        glBindTexture(GL_TEXTURE_2D, Id);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);

        glBindTexture(GL_TEXTURE_2D, 0);

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

What do you mean for type ?? its an unsigned int used to store texture id here is how i generate texture id ``` glGenTextures(1, &Id); glBindTexture(GL_TEXTURE_2D, Id); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); glBindTexture(GL_TEXTURE_2D, 0); ``` 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
ocornut commented 2016-03-22 18:49:46 +00:00 (Migrated from github.com)

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.

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.
v71 commented 2016-03-22 20:01:59 +00:00 (Migrated from github.com)

Ok i can understand

Ok i can understand
ocornut commented 2016-03-22 20:19:17 +00:00 (Migrated from github.com)

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@367c53967f

metrics_triangle

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. https://github.com/ocornut/imgui/commit/367c53967f859bc0473ab76a3e156f3532b9300f ![metrics_triangle](https://cloud.githubusercontent.com/assets/8225057/13966584/758028fa-f073-11e5-8d4f-a4874568c7f6.png)
v71 commented 2016-03-22 20:47:35 +00:00 (Migrated from github.com)

OK, will try when i'll be back home

OK, will try when i'll be back home
v71 commented 2016-03-22 22:27:17 +00:00 (Migrated from github.com)

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

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
ocornut commented 2016-03-22 22:42:56 +00:00 (Migrated from github.com)

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).

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).
v71 commented 2016-03-22 23:30:20 +00:00 (Migrated from github.com)

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

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
ocornut commented 2016-03-23 09:29:38 +00:00 (Migrated from github.com)

I am pretty sure it would work with other texture formats as well, as long as your texture data/upload format are matching.

I am pretty sure it would work with other texture formats as well, as long as your texture data/upload format are matching.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#561
No description provided.