创建纹理的棋盘图像
请帮助我理解以下内容在做什么。具体来说,变量“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
图像有 2 个空间维度和颜色 - 所以在某种程度上是 3 个维度。
最后一个 [] 是红色、绿色、蓝色像素值,
这只是使用“c”数组语法为您在内存中进行计算。
内存中的布局只是
[row1][col1][红色]、[row1][col1][绿色]、[row1][col1][蓝色]、[row1][col2][红色]、[row1][col2][ green], [row1][col2][blue] ........
所以如果
c
是 0 或 255 那么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