gpt4 book ai didi

c++ - Opengl glubyte 数组到整数值

转载 作者:行者123 更新时间:2023-11-28 03:42:37 27 4
gpt4 key购买 nike

我将 RGB 值存储在大小为 3 的 GLubyte 数组中,想知道如何将 RGB 颜色值表示为单个整数,所以我想要的是组合所有 3 个值来创建颜色的整数表示, 谁能解释一下如何做到这一点?

最佳答案

您可以使用移位来生成整数:

GLuint get_number(GLubyte const* ptr) {
// magic numbers for shift sizes are safe because GL types have fixed sizes
// (8 for GLubyte and 32 for GLuint)
return ptr[0] << 16 + ptr[1] << 8 + ptr[2];
}

要填充数组,您可以使用位掩码:

void get_bytes(GLuint number, GLubyte* out) {
out[0] = (number & 0xFF0000) >> 16;
out[1] = (number & 0x00FF00) >> 8;
out[2] = number & 0x0000FF;
}

关于c++ - Opengl glubyte 数组到整数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8645139/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com