Vertex/Fragment Shader does not take effect

Vertex shader source code is below:

#version 330 core
layout(location = 0) in vec4 position;

void main()
{
	gl_Position = position;
};

Fragment shader source code is below:

#version 330 core
layout(location = 0) in vec4 color;

void main()
{
    color = vec4(1.0, 0.0, 0.0, 1.0);
};

vec4(1.0, 0.0, 0.0, 1.0) given by Fragment Shader indicates Red.
But glGetShaderiv did not return GL_TRUE when the shader object was either Vertex Shader or Fragment Shader.

Besides, a runtime error arouse as follow:

ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII character (0xdd)
ERROR: 0:1: '' : illegal non-ASCII
  1. Don’t post pictures of code.

  2. What is in vshader_src when you look at it in a debugger?

  3. Do you know if parseShader is working?

1 Like

Thank you for your advice.

  1. Pictures have been removed, and the words have been re-organized.

The root cause is “const char*” is used as return type for parseShader, which was also hinted by you. That would surely save nothing after exiting parseShader.

An alternate is just use std::string as return type, and futher convert it to const char*, then pass it to glShaderSource

Uh, no. It’s not the return type that matters, it’s what you’re returning. I’m going to guess that you were returning a pointer to an automatic (non-static local) variable, so its contents were undefined (and most likely overwritten) after returning. Returning a pointer to memory allocated with malloc wouldn’t have that problem.