Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: GLSL 430 gl_TexCoord  (Read 6836 times)

0 Members and 1 Guest are viewing this topic.

l00k

  • Newbie
  • *
  • Posts: 9
    • View Profile
GLSL 430 gl_TexCoord
« 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?

« Last Edit: April 19, 2016, 11:12:10 pm by l00k »

SpeCter

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: GLSL 430 gl_TexCoord
« Reply #1 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.

l00k

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: GLSL 430 gl_TexCoord
« Reply #2 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?

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?

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: GLSL 430 gl_TexCoord
« Reply #3 on: April 20, 2016, 05:26:13 pm »
SFML uses the fixed pipeline, so there's no shaders.

l00k

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: GLSL 430 gl_TexCoord
« Reply #4 on: April 20, 2016, 05:51:12 pm »
Ok is see. Thanks a lot.
I will implement VS to pass texture coords.

SpeCter

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: GLSL 430 gl_TexCoord
« Reply #5 on: April 20, 2016, 05:57:50 pm »
SFML uses the fixed pipeline, so there's no shaders.
WHAT?! ::)

l00k

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: GLSL 430 gl_TexCoord
« Reply #6 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.
« Last Edit: April 20, 2016, 06:34:09 pm by l00k »

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: GLSL 430 gl_TexCoord
« Reply #7 on: April 20, 2016, 10:30:11 pm »
I should have said : "They are no default shaders".  ;)