Check out our Monthly Survey Page to see what our users are running.
(noob) OpenGL Fragment Coordinates
StackMasher Jan 12, 2017
I've written a shader that looks like this:
#version 450 core

out vec4 color;
void main()
{
color = vec4(abs(gl_FragCoord.x), abs(gl_FragCoord.y), abs(gl_FragCoord.z), 0.0);
}

I'm expecting every pixel drawn to be a different color but instead I'm getting a solid yellow color like so:

What am I doing wrong? (opengl 4.5 core btw if you didn't notice)
tuubi Jan 12, 2017
I know absolutely nothing about GLSL, but should the alpha component really be 0.0? Doesn't that just make it transparent?
StackMasher Jan 12, 2017
Quoting: tuubiI know absolutely nothing about GLSL, but should the alpha component really be 0.0? Doesn't that just make it transparent?
I think it's the other way round and it makes it completely opaque
Guppy Jan 12, 2017
Unless you told the shader linker to use 'color' I'm fairly sure it expects it to be 'diffuseColor', if you didn't then it won't see any out put and it will choose a colour at "random".


Disclaimer: It's been long a while since I've tampered with shaders, so I could be entirely wrong ;)
tuubi Jan 12, 2017
Quoting: StackMasher
Quoting: tuubiI know absolutely nothing about GLSL, but should the alpha component really be 0.0? Doesn't that just make it transparent?
I think it's the other way round and it makes it completely opaque
I still kinda remember reading that in OpenGL 1.0 is actually fully opaque. And the first google result I got agrees.
StackMasher Jan 12, 2017
Quoting: GuppyUnless you told the shader linker to use 'color' I'm fairly sure it expects it to be 'diffuseColor', if you didn't then it won't see any out put and it will choose a colour at "random".


Disclaimer: It's been long a while since I've tampered with shaders, so I could be entirely wrong ;)
It says that diffuseColor is undefined. Also, it isn't really random since the square is at z=0, and red and green makes yellow (I think) so it makes sense but what I don't get is why it's a solid yellow color. For example, on the bottom side, it should be getting greener towards the middle since X is getting smaller
StackMasher Jan 12, 2017
Quoting: GuestI think that gl_FragCoord is not a floating point number between 0 and 1, but an integer corresponding to the pixel coordinates on the screen.

Edit: it’s actually floating point, but still, not between 0 and 1.
woah nice that was the problem. Now it looks like this:

(screen tearing lol)
Thanks everyone
Smilex Jan 24, 2017
Have you defined "color" to be your output?

glBindFragDataLocation(shaderProgram, 0, "color");

Also you want your alpha to be at full value, so 1.0, not 0.0. And your colors will be solid, because gl_FragCoord values are way above 1.0, and 1.0 is full value. You can try dividing them by your screen size.
While you're here, please consider supporting GamingOnLinux on:

Reward Tiers: Patreon. Plain Donations: PayPal.

This ensures all of our main content remains totally free for everyone! Patreon supporters can also remove all adverts and sponsors! Supporting us helps bring good, fresh content. Without your continued support, we simply could not continue!

You can find even more ways to support us on this dedicated page any time. If you already are, thank you!
Login / Register


Or login with...
Sign in with Steam Sign in with Google
Social logins require cookies to stay logged in.