【发布时间】:2012-11-26 01:39:03
【问题描述】:
以下简单的片段着色器表现出非常奇怪的行为。没有循环,输出都是红色的,正如预期的那样。但是随着循环它变成黄色,我。 e. RGB(1,1,0)。有人可以告诉我这里发生了什么吗?
void main(void)
{
mat4 redUnit = mat4(
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0
);
mat4 greenUnit = mat4(
0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0
);
mat4 blueUnit = mat4(
0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0
);
for (int x = -1; x < 3; x++) {
for (int y = -1; y < 3; y++) {
redUnit[x+1][y+1] = 1.0;
greenUnit[x+1][y+1] = 0.0;
blueUnit[x+1][y+1] = 0.0;
}
}
gl_FragColor = vec4(redUnit[0][0], greenUnit[0][0], blueUnit[0][0], 1.0);
}
编辑:输出颜色取决于声明变量的顺序。所以不知何故,内存边界被违反了。但是仍然没有解释这种行为。
【问题讨论】:
-
操作系统? GL 实施供应商?
#version指令? -
Windows 7 32bit,Intel (OpenGL 2.0),无#version 指令。