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

Author Topic: Problems with GLSL 4  (Read 1106 times)

0 Members and 1 Guest are viewing this topic.

Millsialix

  • Guest
Problems with GLSL 4
« on: July 19, 2019, 03:16:03 am »
Hi,
I'm not an expert in shaders, and I recently noticed that a lot of recent computers don't support glsl 3 anymore, and the gl_* variables used in the SFML tutorial are depreciated, so, as a happy new owner of one of those recent computers, I started to do a glsl 4 shader. Everything was fine, until I try to get the texture coordinates of the pixel I'm working on. Apparently we must add a vertex shader to get that, so I add it and I realize that my sprite doesn't appear anymore. Here's the code:

main.cpp
sf::Texture texture;
        texture.loadFromFile( "something.png" );
sf::Sprite sprite( texture );

sf::Shader shader;
        shader.loadFromFile( "shader.vert", "shader.frag" );
        shader.setUniform( "t", texture );

// Later
window.draw( sprite, &shader );
 

shader.vert (I got it somewhere on the internet)
#version 400

layout( location = 0 ) in vec4 vert; // Vertex we're working on
in vec2 tCoords; // Coordinates of the pixel we will work on
out vec2 coords; // Coordinates of the pixel we will work on

uniform mat4 projection; // No idea of what it is
uniform mat4 view;
uniform mat4 model;

void main(){
        coords = tCoords; // Set the coordinates of the pixel we'll working on
        gl_Position = projection*view*model*vert;
}

 

shader.frag
#version 400

uniform sampler2D t; // Texture which will be modified
in vec2 coords; // Coordinates of the pixel we're working on
out vec4 fragColor; // Final color of this pixel

void main(){
        fragColor = texture( t, coords ); // Get the color of the pixel position in the texture
}
 

So that's it, the problem is that I can't see the sprite and I don't know if the problem comes from the vertices or the color, so here is my question:
- If this is the vertices, is that because of the "uniform mat4" in the shader, and how to solve that problem?
Or:
- How can I retrieve the pixel coordinates on the texture (without gl_texCoords[0], depreciated) to play with the colors? (I want to move each color channels of an image, I don't think I can do that without a shader)

Thanks if you can helping me
« Last Edit: July 19, 2019, 03:20:51 am by Millsialix »