Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable alpha in ImGui::Image? #4730

Closed
l1ghtrider opened this issue Nov 17, 2021 · 7 comments
Closed

How to disable alpha in ImGui::Image? #4730

l1ghtrider opened this issue Nov 17, 2021 · 7 comments

Comments

@l1ghtrider
Copy link

Im working for a scene window using ImGui::Image to display my scene, there are translucent elements so the frame buffer shall shall contains texels with alpha factor after rendering the scene,
it seems the ImGui::Image take the alpha factor and blend to the window background (in my case, the window background is black)
is there some quick trick to render the color only?

@PathogenDavid
Copy link
Contributor

The issue template isn't there just for fun 😘

@l1ghtrider
Copy link
Author

The issue template isn't there just for fun 😘

im serious, i need this feature and seems there aren't solution on net,
it is an issue for me and if its not an "Issue" and just no such feature, apologies, i'll try otherway

@xastrix
Copy link

xastrix commented Nov 17, 2021

image transparent?

@l1ghtrider
Copy link
Author

image transparent?

yes

@ocornut
Copy link
Owner

ocornut commented Nov 17, 2021

If you cannot remove the alpha component from your texture, you would need to either disable alpha blending during the rendering of that image, or swap the shader to one which omits alpha. You can do that by registering a ImDrawList call with AddCallback() to a custom callback tailored for the rendering backend you are using (eg for an OpenGL backend your custom callback would eg disable blending, then you submit another callback after the image to reenable blending).

Variants of this question have been asked here before, and because you have ignored our guidelines and issue template I am closing this.

@l1ghtrider
Copy link
Author

If you cannot remove the alpha component from your texture, you would need to either disable alpha blending during the rendering of that image, or swap the shader to one which omits alpha. You can do that by registering a ImDrawList call with AddCallback() to a custom callback tailored for the rendering backend you are using (eg for an OpenGL backend your custom callback would eg disable blending, then you submit another callback after the image to reenable blending).

Variants of this question have been asked here before, and because you have ignored our guidelines and issue template I am closing this.

Thank you for help, this is exactly what im looking for, and sorry for ignoring the issue template , im just new to communicate on github and didn't realize that, i'll check it then.

@aboood40091
Copy link

I know this is an issue from 2 years ago, but in case someone comes through this, there is an easier solution than everything mentioned here for OpenGL, which is swizzling (GL_TEXTURE_SWIZZLE_RGBA). Simply set the alpha channel swizzle to GL_ONE. Example:

// Texture must be bound first
GLint swizzle[4] = {
    GL_RED,   // Shader Red   channel source = Texture Red
    GL_GREEN, // Shader Green channel source = Texture Green
    GL_BLUE,  // Shader Blue  channel source = Texture Blue
    GL_ONE    // Shader Alpha channel source = One
};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle);

As mentioned, this is for OpenGL, but most graphics APIs have swizzling, you just need to figure out how to do it for your API.

@ocornut ocornut changed the title How to dsiable alpha in ImGui::Image? How to disable alpha in ImGui::Image? Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants