1
出於測試目的,我試圖將每個頂點的位置設置爲零。但是,如果我嘗試改變兩個以上的維度(哪一個並不重要),則着色器會自動崩潰。有人可以告訴我這裏發生了什麼嗎?我的代碼:GLSL:更改兩個以上的頂點尺寸會導致着色器崩潰
static const float vertices[12] = {
-0.5,-0.5, 0.0,
0.5,-0.5, 0.0,
-0.5, 0.5, 0.0,
0.5, 0.5, 0.0,
};
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)vertices);
glEnableVertexAttribArray(vertexHandle);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]);
glDrawArrays(GL_POINTS, 0, 4);
我的着色器:
attribute vec4 vertexPosition;
uniform mat4 modelViewProjectionMatrix;
void main()
{
vec4 temp = vertexPosition;
temp.x = 0.0;
temp.y = 0.0;
temp.z = 0.0; // Can set any 2 dimensions (e.g. x and y or y and z)
// to zero, but not all three or the shader crashes.
gl_Position = modelViewProjectionMatrix * vec4(temp.xyz, 1.0);
}
什麼意思是「着色器崩潰」?着色器不會崩潰;也許你的意思是它有未定義的行爲? – Luca 2012-04-07 08:06:57
對不起,我的意思是,iOS應用程序(運行在iPhone 4S上)凍結(沒有堆棧跟蹤或任何東西),但我認爲它是負責的着色器。 – Josh 2012-04-07 09:00:23
你能發佈你所有的C代碼嗎?還有一些東西比着色器中的更多。 – 2012-04-08 02:23:29