Jump to content
  • Advertisement
Sign in to follow this  
Hector San Roman Lanza

GLSL initialize uniform variable with default value

This topic is 2021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!