gl_Vertex and gl_Position not accessable?

I’m reading the OpenGL Shading Language, and it had an example of how to transform temperature into color.
I’ve made my own version, but when I start my program I get the follow errors out the info log functions:

Fragment info

(0) : error C5052: gl_Vertex is not accessable in this profile
(0) : error C5052: gl_Position is not accessable in this profile

Here are my shaders:

uniform float MaxTemp;
uniform float MixPercentageColor;
attribute float Incoming_Temperature;
varying vec3 InOut_Color;

void main()
	float InOut_Temperature = (Incoming_Temperature - 273.0) / (MaxTemp - 273.0);
	// Handle the r component
	if(InOut_Temperature <= 0.5)
		InOut_Color.r = 0.0;
		InOut_Color.r = (InOut_Temperature-0.5)*2.0;
	// Deal with the g component
	if(InOut_Temperature <= 0.25)
		InOut_Color.g = 0.0;
	else if(InOut_Temperature <= 0.5)
		InOut_Color.g = (InOut_Temperature-0.25)*4.0;
		InOut_Color.g = 1.0 - (4.0 * InOut_Temperature);
	// And lastly, set the b component
	InOut_Color.b = 1.0 - 5.0 * InOut_Temperature;
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;


uniform float MaxTemp;
uniform float MixPercentageColor;
varying vec3 InOut_Color;

void main()
	gl_FragColor = mix(vec4(InOut_Color, 1.0), gl_Color, MixPercentageColor);

I use the following code to activate the two shaders:

	VShader = glCreateShader(GL_VERTEX_SHADER);
	FShader = glCreateShader(GL_FRAGMENT_SHADER);
	const GLchar *DataF = ReadFile("fragment.shad").c_str();
	const GLchar *DataV = ReadFile("vertex.shad").c_str();
	glShaderSource(VShader, 1, &DataV, NULL);
	glShaderSource(FShader, 1, &DataF, NULL);
	ShaderProgram = glCreateProgram();
	glAttachShader(ShaderProgram, VShader);
	glAttachShader(ShaderProgram, FShader);
	Uni_MaxTemp = glGetUniformLocation(ShaderProgram, "MaxTemp");
	Uni_MixPercentageColor = glGetUniformLocation(ShaderProgram, "MixPercentageColor");
	Attr_Incoming_Temperature = glGetAttribLocation(ShaderProgram, "Incoming_Temperature");
	glUniform1f(Uni_MaxTemp, 500.0);
	glUniform1f(Uni_MixPercentageColor, 0.0);

Any idea what could be wrong with my shaders? Because to me, the shaders look alright.
thanks in advance,

That error message looks wrong:

“Fragment info” ??!!

It seems you are probably loading your vertex shader into a fragment shader.

I see your problem, it is a C++ code problem with these lines:

const GLchar *DataF = ReadFile(“fragment.shad”).c_str();
const GLchar *DataV = ReadFile(“vertex.shad”).c_str();

They should read:

string DataF = ReadFile(“fragment.shad”);
string DataV = ReadFile(“vertex.shad”);

Then when passing to OpenGL do:
DataF.c_str() and

The reason being is that the previous code was taking a internal pointer to a temporary return string object that went out of scope and was deleted. Therefore, you got access to random memory. (eg. the other string data)

Because I can’t directly do &DataF.c_str() to the function(it complains about non-lvalue in unary `&’).
I’ve changed it into this:

	std::string DataFStr = ReadFile("fragment.shad");
	std::string DataVStr = ReadFile("vertex.shad");
	const GLchar *DataF = DataFStr.c_str();
	const GLchar *DataV = DataVStr.c_str();
	glShaderSource(VShader, 1, &DataV, NULL);
	glShaderSource(FShader, 1, &DataF, NULL);

And it seems to be working.
Thank you for pointing out the problem.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.