Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 sbar   Members   -  Reputation: 113

Like
0Likes
Like

Posted 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".

Edited by sbar, 14 October 2012 - 01:14 PM.


Sponsor:

#2 sbar   Members   -  Reputation: 113

Like
2Likes
Like

Posted 14 October 2012 - 01:22 PM

The issue is resolved by declaring a uniform variable in fragment shader. By some reason I thought that it's impossible to use uniform variables inside a fragment shader.

#3 beans222   Members   -  Reputation: 870

Like
1Likes
Like

Posted 14 October 2012 - 01:24 PM

You could also use the keyword 'flat' before 'varying' to turn off interpolation for that variable.

#4 apatriarca   Crossbones+   -  Reputation: 1476

Like
0Likes
Like

Posted 14 October 2012 - 03:00 PM

Why are you using an ancient OpenGL version like 1.4 with the GLSL version introduced in OpenGL 2.1? If you need features introduced in GLSL 1.2, you are probably targeting GPUs which also support the OpenGL 2.1 version (and maybe also OpenGL 3.0).

#5 Geometrian   Crossbones+   -  Reputation: 1312

Like
0Likes
Like

Posted 15 October 2012 - 12:29 AM

Also, I'm confused. (Global) uniforms act per-primitive. How did you manage different values of a per-triangle attribute for each vertex?
And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.

#6 Murdocki   Members   -  Reputation: 274

Like
0Likes
Like

Posted 15 October 2012 - 01:36 AM

I am wondering about this as well. If you are just passing through the uniform how can it even be interpolating. The same value for every vertex in a triangle should effectively disable interpolation right?

#7 sbar   Members   -  Reputation: 113

Like
0Likes
Like

Posted 15 October 2012 - 10:41 AM

You could also use the keyword 'flat' before 'varying' to turn off interpolation for that variable.

Thanks

Why are you using an ancient OpenGL version like 1.4 with the GLSL version introduced in OpenGL 2.1? If you need features introduced in GLSL 1.2, you are probably targeting GPUs which also support the OpenGL 2.1 version (and maybe also OpenGL 3.0).

I've got only old hardware right now (one of intel gma videocards), that supports only Open GL <=1.4, but GLSL 1.2 is also supported via ARB-extensions (not the way OpenGL >=2.0 works with).

Also, I'm confused. (Global) uniforms act per-primitive. How did you manage different values of a per-triangle attribute for each vertex?

If I understand right---that caused by assigning uniform to varying variable and only then using it (varying var) in fragment shader.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS