Jump to content

  • Log In with Google      Sign In   
  • Create Account

GLSL initialize uniform variable with default value


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 ShotoReaper   Members   -  Reputation: 149

Like
0Likes
Like

Posted 05 February 2013 - 12:50 PM

Hi! I want to initialize my uniform variable in GLSL with a default value, but the program give me an error when I run it:

Fragment code GLSL

uniform vec3 Color = vec3(1.0,0.0,0.0);
out vec3 out_Color;
void main(void){
out_Color = Color;
}

If I the variable "Color" isn´t a uniform variable, the program works. I need that Color is uniform to change his value from a class.

When I load the material I call this method:

 

 

void Color_mat::Load(void)
 { 
shader = getParent()->getEngine()->content.Load("Shaders/ColorShader.glsl");
 Material::Load(); 
ColorUniformLocation = glGetUniformLocation(shader->ID, "Color");
 ExitOnGLError("ERROR: Could not get the Color uniform location");
} 
 

 

 

And When I draw, i call this method to start drawing the objects:

 

void Color_mat::Prepare3dDraw(glm::mat4 ModelMatrix)
{
    Material::Prepare3dDraw(ModelMatrix);
    glUniform3f(ColorUniformLocation, color.x, color.y, color.z);
    ExitOnGLError("ERROR: Could not set the color");
}

 

 


Edited by ShotoReaper, 05 February 2013 - 01:11 PM.


Sponsor:

#2 Arkhyl   Members   -  Reputation: 577

Like
0Likes
Like

Posted 06 February 2013 - 02:05 AM

As said in OpenGL wiki, it is possible to initialize uniform variables as you do, but it might not be correctly implemented in some drivers : http://www.opengl.org/wiki/Uniform_(GLSL)#GLSL_definition_and_behavior.



#3 ShotoReaper   Members   -  Reputation: 149

Like
0Likes
Like

Posted 06 February 2013 - 02:32 PM

If I not initialize the color variable in GLSL but I give a value through "glUniform3f(ColorUniformLocation, color.x, color.y, color.z);" in the code, it does´n work. 

Am I doing something wrong?






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS