Jump to content
  • Advertisement
Sign in to follow this  
Jossos

Pass in 0-255 color values instead of 0.0-1.0

This topic is 1104 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 am trying to pass in values between 0-256 into a opengl shader, but anything 1 and above just gives a solid color. How do I make this work, or do I have to divide by 255 every time?

 

glubyte r, g, b;

 

glUniform3f(colorLoc, r, g, g);

 

Help is appreciated

Share this post


Link to post
Share on other sites
Advertisement

Divide by 255.

 

You could potentially create a macro or your own function which does this for you, e.g.

void my_glUniform3byte(int colorLoc glubyte r, glubyte g, glubyte b)
{
    glUniform3f(colorLoc, r / 255.0f, g / 255.0f, b / 255.0f);
}

Share this post


Link to post
Share on other sites

 

Divide by 255.

 

You could potentially create a macro or your own function which does this for you, e.g.

void my_glUniform3byte(int colorLoc glubyte r, glubyte g, glubyte b)
{
    glUniform3f(colorLoc, r / 255.0f, g / 255.0f, b / 255.0f);
}

Thanks for your answer. I swear I was able to previously pass in ints and get what I needed, but if this is the best option I'll do it.

 

I am using this for reading id's from the backbuffer. will that still be ok? I won't get any inacuracy when using glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE will i?

Share this post


Link to post
Share on other sites
glUniform3f sets three float values. Your bytes will be cast to floatx and then passed to the shader as uniform variables. No clamping/clipping will occur for values larger than 1.0f.

What does your shader code look like that consumes this uniform value?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!