创建纹理的棋盘图像

发布于 2024-12-18 14:59:40 字数 583 浏览 0 评论 0原文

请帮助我理解以下内容在做什么。具体来说,变量“c”是什么,第三个数组维度是什么(图像不是二维像素矩形)? 如果需要上下文,我将发布此代码的链接,但上下文通常是将这个棋盘图案映射到旋转立方体。

GLubyte image[TextureSize][TextureSize][3];
GLubyte image2[TextureSize][TextureSize][3];

// Create a checkerboard pattern
for ( int i = 0; i < 64; i++ ) {
    for ( int j = 0; j < 64; j++ ) {
        GLubyte c = (((i & 0x8) == 0) ^ ((j & 0x8)  == 0)) * 255;
        image[i][j][0]  = c;
        image[i][j][1]  = c;
        image[i][j][2]  = c;
        image2[i][j][0] = c;
        image2[i][j][1] = 0;
        image2[i][j][2] = c;
    }
}

Please help me understand what the following is doing. Specifically, what is variable 'c', and what is the third array dimension for (isn't an image a 2-dimensional pixel rectangle)?
I'll post a link to this code if context is needed, but the context in general is mapping this checkerboard pattern to a rotating cube.

GLubyte image[TextureSize][TextureSize][3];
GLubyte image2[TextureSize][TextureSize][3];

// Create a checkerboard pattern
for ( int i = 0; i < 64; i++ ) {
    for ( int j = 0; j < 64; j++ ) {
        GLubyte c = (((i & 0x8) == 0) ^ ((j & 0x8)  == 0)) * 255;
        image[i][j][0]  = c;
        image[i][j][1]  = c;
        image[i][j][2]  = c;
        image2[i][j][0] = c;
        image2[i][j][1] = 0;
        image2[i][j][2] = c;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抽个烟儿 2024-12-25 14:59:40

图像有 2 个空间维度和颜色 - 所以在某种程度上是 3 个维度。
最后一个 [] 是红色、绿色、蓝色像素值,

这只是使用“c”数组语法为您在内存中进行计算。

内存中的布局只是
[row1][col1][红色]、[row1][col1][绿色]、[row1][col1][蓝色]、[row1][col2][红色]、[row1][col2][ green], [row1][col2][blue] ........

所以如果 c 是 0 或 255 那么

// sets all red,green,blue to same value = black (c=0) or white (c=255)
image[i][j][0]  = c;
image[i][j][1]  = c;
image[i][j][2]  = c;

// sets red and blue on but green off = purple
image[i][j][0]  = c;
image[i][j][1]  = 0;
image[i][j][2]  = c;

An image is 2 spatial dimensions and color - so 3 dimensions in a way.
The last [] is the red,green,blue pixel values

This is just using the 'c' array syntax to do the calculations into the memory for you.

The layout in memory is just
[row1][col1][red], [row1][col1][green], [row1][col1][blue], [row1][col2][red], [row1][col2][green], [row1][col2][blue] ........

So if c is either 0 or 255 then

// sets all red,green,blue to same value = black (c=0) or white (c=255)
image[i][j][0]  = c;
image[i][j][1]  = c;
image[i][j][2]  = c;

// sets red and blue on but green off = purple
image[i][j][0]  = c;
image[i][j][1]  = 0;
image[i][j][2]  = c;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文