Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


sbar

Member Since 14 Oct 2012
Offline Last Active Oct 23 2012 03:38 PM

Topics I've Started

[GLSL] Draw a textured (RGBA) polygon with opacity

14 October 2012 - 01:07 PM

Hello. I'm new to GLSL and have another one nooby question: how to draw a textured polygon with opacity, that changes from C/C++ application?

I'm using OpenGL 1.4 and GLSL 1.2 via ARB-extensions. Tried to set opacity using uniform variable to vertex shader and assign it to varying variable to use it in fragment shader—surly I see gradient-like opacity (that I don't want), 'cause of varying variable.

Vertex shader looks like:
uniform float opacity;
varying float vopacity;

void main() {
    vopacity = opacity;
    gl_Position = gl_Vertex;
    gl_TexCoord[0] = gl_MultiTexCoord0;
}

and fragment one like:
uniform sampler2D tex;
varying float vopacity;

void main() {
	vec4 color = texture2D(tex, gl_TexCoord[0].st);
	if (color.a > 0.01)
		color.a = vopacity;
		//color.a = 0.4; // that works as I want, but it's not a variable
	gl_FragColor = color;
}

Googled this pretty simple problem all the day without success. I'd be glad if someone point me to the right way.
Thank you!

P.S. to admin/moderator: if I chose the wrong forum section—please move it to "For beginners".

PARTNERS