# set model to transparent where texture is transparent

I finally got around to applying textures to my game, and I noticed that the areas that are transparent on the .png of the texture are not transparent on the actual model.It is illustrated in the image below.

I want the areas of the model that are supposed to be transparent to be transparent. The white areas are the areas that should be transparent. the white areas are transparent on the actual .png. Is there any way to do this using glfw? Is there some sort of transparency function GLFW has? I thought changing RGB to RGBA on the texture generator would fix it but it did not. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); The data for the actual model is below (its formatted in json but still shows the vertices). The first 3 entries on each row are the coordinates, then 3 entries for the color, then the texture mapping.

{"vertices":[
0.00,0.00,0.0,0.0,0.0,0.0,0.0,0.0,
500.00,0.00,0.0,0.0,0.0,0.0,1.0,0.0,
500.00,500.00,0.0,0.0,0.0,0.0,1.0,1.0,
0.00,500.00,0.0,0.0,0.0,0.0,0.0,1.0

],
"indices":[
0,1,2,
0,3,2
],

"texturePath": "textures/planet1.png"}


Do I have to map the coordinates of the texture to a circular object rather than a square one like it is formatted now. I am hoping I don't, because that would make my life so much simpler.

• For starters, you're using GL_RGB as the internal format; as I recall, you need to change that to GL_RGBA. There's multiple things that effect the end result of transparency in OpenGL though such as enabling blend & setting a blend function, so that one correction might not be enough. If you fix the internal format & it still doesn't work, edit your post to include an MCVE so we can see the rest of the code. – Pikalek Jan 23 at 5:25

I figured it out using this lovely tutorial.

I changed my fragment shader from this:

out vec4 FragColor;

in vec3 ourColor;
in vec2 TexCoord;

uniform sampler2D ourTexture;

void main()
{
FragColor = texture(ourTexture, TexCoord);
}


to this:

out vec4 FragColor;

in vec3 ourColor;
in vec2 TexCoord;

uniform sampler2D ourTexture;

void main()
{
vec4 texColor = texture(ourTexture, TexCoord);
if(texColor.a < 0.1)