Richard
Richard

Reputation: 287

Translucent sprite in opengl es 2.0 using shader

I'm trying to create an shader that does the same thing as glcolor4f and then the alpha part of it. In opengl es 1.1 if you set the alpha to say 0.5 the sprite would be half translucent.

Now i can't seem to get the effect using an shader, this is how my shader looks like now:

gl_FragColor = texture2d(texture, coord) * blend;

And using this blend mode:

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

But that doesn't work, it does change the color of an sprite but not the translucency. What am i missing?

Thanks for your time, Richard.

Upvotes: 0

Views: 761

Answers (1)

vmpstr
vmpstr

Reputation: 5211

It seems that you are scaling the color you get from the texture by the blend factor, which is not how alpha is performed (this would just make it darker).

I believe you need something along the lines of the following

gl_FragColor = vec4(texture2d(texture, coord).rgb, blend);

See if that works

Upvotes: 1

Related Questions