Patreon Logo Support us on Patreon to keep GamingOnLinux alive. This ensures all of our main content remains free for everyone. Just good, fresh content! Alternatively, you can donate through PayPal Logo PayPal. You can also buy games using our partner links for GOG and Humble Store.
Title: (noob) OpenGL Fragment Coordinates
StackMasher 12 Jan 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:
External Media: You need to be logged in to view this.

What am I doing wrong? (opengl 4.5 core btw if you didn't notice)
tuubi 12 Jan 2017
User Avatar
I know absolutely nothing about GLSL, but should the alpha component really be 0.0? Doesn't that just make it transparent?
StackMasher 12 Jan 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 12 Jan 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 12 Jan 2017
User Avatar
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](http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-10-transparency/) I got agrees.
StackMasher 12 Jan 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 12 Jan 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:
External Media: You need to be logged in to view this.

(screen tearing lol)
Thanks everyone
Smilex 24 Jan 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 Logo Patreon. Plain Donations: PayPal Logo 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