SFML community forums

Help => Graphics => Topic started by: l00k on April 19, 2016, 04:59:25 pm

Title: GLSL 430 gl_TexCoord
Post by: l00k on April 19, 2016, 04:59:25 pm
It's not strictly SFML problem but maybe someone could help me.
How can I access texture coordinates in fragment shader (version 430)?
gl_TexCoord is depracted since 120.

gl_FragCoord gives info about pixel coordinates in render target metrics. I want coordinates in rendered square metrics (0-1, 0-1).

Does I need to provide my own vertex shader to pass texture coordinate? Is there any easy way to perform it with standard SFML sprite?

I have read about gl_SamplePosition, but it doesn't work - it is always set to (0.5, 0.5).
Probably multisample rasterization is disabled - can I enable it for sfml renderTexture?

Title: Re: GLSL 430 gl_TexCoord
Post by: SpeCter on April 20, 2016, 11:40:43 am
They are deprecated because in modern OpenGL(Core Profile) they don't exist if you don't send them in.
You have to provide the texture coordinates yourself if you need them in your fragment shader.
Title: Re: GLSL 430 gl_TexCoord
Post by: l00k on April 20, 2016, 04:11:08 pm
Ok so I need to send texcoords to fragment, from vertex shader. Its required to know them in vertex.
Does each vertex of SFML sprite mesh has assigned texcoords?
(http://www.c-jump.com/bcc/common/Talk3/OpenGL/Wk07_texture/const_images/tex_mapping.png)
Something like that.

Btw. If I dont assign my own shader what is going on with gpu flow? Does SFML sets its own shaders? If true then those shaders also should provide texture coordinates to properly map texture on the triangles. Right?
Title: Re: GLSL 430 gl_TexCoord
Post by: victorlevasseur on April 20, 2016, 05:26:13 pm
SFML uses the fixed pipeline, so there's no shaders.
Title: Re: GLSL 430 gl_TexCoord
Post by: l00k on April 20, 2016, 05:51:12 pm
Ok is see. Thanks a lot.
I will implement VS to pass texture coords.
Title: Re: GLSL 430 gl_TexCoord
Post by: SpeCter on April 20, 2016, 05:57:50 pm
SFML uses the fixed pipeline, so there's no shaders.
WHAT?! ::)
Title: Re: GLSL 430 gl_TexCoord
Post by: l00k on April 20, 2016, 06:17:19 pm
It's not true?
Then where are defined default shaders?

EDIT:
src\SFML\Graphics\Shader.cpp, line 857, function Shader::bind()

if (shader && shader->m_shaderProgram)
{
    (...)
}
else
{
    // Bind no shader
    glCheck(GLEXT_glUseProgramObject(0));
}

If you don't bind your custom shader SFML sets fixed pipeline rendering.
Title: Re: GLSL 430 gl_TexCoord
Post by: victorlevasseur on April 20, 2016, 10:30:11 pm
I should have said : "They are no default shaders".  ;)