Search code examples
goopenglfragment-shaderopengl-3imgui

How does texture display to color not grey scale in OpenGL3?


I am developing a GUI Program using Golang.

And I am using imgui-go framework for my GUI.

Now, I encountered color texture display issue.

I have loaded a image from file and I made image as a texture and then attached on GUI.

Image is definitely colored but It's displaying greyscale on gui.

Is there best solution for this issue?

Thank you.

OpenGL fragment shader:

uniform int ImageType;
uniform sampler2D Texture;
uniform sampler2D Palette;
in vec2 Frag_UV;
in vec4 Frag_Color;
out vec4 Out_Color;
void main()
{
     
    Out_Color = vec4(Frag_Color.rgb, Frag_Color.a * texture( Texture, Frag_UV.st).r); 
}

Image Texture:

gl.BindTexture(gl.TEXTURE_2D, texture)

width := int32(bm.W)
height := int32(bm.H) 
dataPtr := gl.Ptr(bm.Data)

gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
gl.PixelStorei(gl.UNPACK_ROW_LENGTH, 0)
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(width), int32(height),
    0, gl.RGBA, gl.UNSIGNED_BYTE, dataPtr)

enter image description here


Solution

  • I don't know what is Frag_Color but you are putting it in output color as Frag_Color.rgb which makes texture's color dependent on its value. You put Texture only in alpha value which is transparency/visibility. Try this code, it should work: Out_Color = texture(Texture, Frag_UV.st); If that code won't work you can try also this: Out_Color = Frag_Color * texture(Texture, Frag_UV.st);

    I'm sorry for formatting, it doesn't work well when I'm writing on phone