Glsl shader not showing any errors, but neither any output

When I use this shader, I see no errors, but neither any color is drawn.

vert:

#version 330 core
layout (location = 0) in vec3 aPos;
  
out vec4 vertexColor;

void main()
{
    gl_Position = vec4(aPos, 1.0);
    vertexColor = vec4(0.5, 0.0, 0.0, 1.0);
}

frag:

#version 330 core
out vec4 FragColor;
  
in vec4 vertexColor;

void main()
{
    FragColor = vertexColor;
} 
PShader s_msdf; 

void settings() {
  size(600, 600, P2D);
}

void setup() {
  s_msdf = loadShader("msdf.frag", "msdf.vert");
}

void draw() {
  shader(s_msdf);
  fill(0);
  rect(0, 0, 500, 500);
  resetShader();
}

How can this be fixed? Normally I write my shaders more in the ‘old’ style. But it’s so outdated.

1 Like

Try this instead:

PShader s_msdf; 

void settings() {
  size(600, 600, P2D);
}

void setup() {
  s_msdf = new PShader( g.parent, vertSrc, fragSrc );
}

void draw() {
  shader(s_msdf);
  fill(0);
  rect(0, 0, 500, 500);
  resetShader();
}


String[] vertSrc = {"""
#version 330 core
uniform mat4 transformMatrix;
layout (location = 0) in vec4 position;
  
out vec4 vertexColor;

void main()
{
    gl_Position = transformMatrix * position;
    vertexColor = vec4(0.5, 0.0, 0.0, 1.0);
}
"""};


String[] fragSrc = {"""
#version 330 core
out vec4 FragColor;
  
in vec4 vertexColor;

void main()
{
    FragColor = vertexColor;
}
"""};
1 Like

Thank you, that works.

1 Like