I have a UISlider giving me float values between 0 and 255 and I need to set the opacity of an Cocos2D that is in Glubyte.
How do I convert a float to GLubyte ??????
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A
GLubyteis simply defined as:So, conversion is actually no problem (have a look at this post, which offers a few possible approaches behind the “basic”
(int)(x+0.5)), except for “out-of-range” values (since an unsigned char can represent decimal between 0 and 255). In short, you should decide what to do with floating point values that cannot be represented as unsigned integers.Since you say that your slider gives you values between 0 and 255, you should have no problem, though.