Hylke Donker
06-24-2006, 05:01 AM
Hello,
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:
vertex.shad
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;
else
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;
else
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;
}fragment.shad
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);
glCompileShader(VShader);
OutputShaderLog(VShader);
glCompileShader(FShader);
OutputShaderLog(FShader);
ShaderProgram = glCreateProgram();
glAttachShader(ShaderProgram, VShader);
glAttachShader(ShaderProgram, FShader);
glLinkProgram(ShaderProgram);
OutputProgramLog(ShaderProgram);
glUseProgram(ShaderProgram);
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,
Hylke
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:
vertex.shad
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;
else
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;
else
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;
}fragment.shad
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);
glCompileShader(VShader);
OutputShaderLog(VShader);
glCompileShader(FShader);
OutputShaderLog(FShader);
ShaderProgram = glCreateProgram();
glAttachShader(ShaderProgram, VShader);
glAttachShader(ShaderProgram, FShader);
glLinkProgram(ShaderProgram);
OutputProgramLog(ShaderProgram);
glUseProgram(ShaderProgram);
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,
Hylke