Sign in to follow this  
Hector San Roman Lanza

GLSL initialize uniform variable with default value

Recommended Posts

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this