我的 C 文件中有以下代码...
static const char gVertexShader[] =
"attribute vec4 vPosition;\n"
"attribute vec4 vid;\n"
"varying vec4 fragColor; \n"
"attribute vec4 inColor; \n"
"void main() {\n"
" gl_Position = vid * vPosition;\n"
" fragColor = inColor; \n"
"}\n";
static const char gFragmentShader[] = "precision mediump float;\n"
"varying vec4 fragColor; \n"
"void main() {\n"
" gl_FragColor = fragColor;\n"
"}\n";
.....
GLuint gvPositionHandle;
GLuint gvColorHandle;
GLuint gvIDHandle;
....
GLfloat id[] = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f};
....
glVertexAttribPointer(gvPositionHandle, 2, GL_FLOAT, GL_FALSE, 0,
gTriangleVertices1);
glVertexAttribPointer(gvColorHandle, 4, GL_FLOAT, GL_FALSE, 0, current1);
glVertexAttribPointer(gvIDHandle, 4, GL_FLOAT, GL_FALSE, 0, id);
checkGlError("glVertexAttribPointer");
glEnableVertexAttribArray(gvPositionHandle);
glEnableVertexAttribArray(gvColorHandle);
glEnableVertexAttribArray(gvIDHandle);
checkGlError("glEnableVertexAttribArray");
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
没有单位矩阵我工作得很好......
然后在我添加单位矩阵之后(所以我不希望有任何变化,因为它是一个ID矩阵)我看到以下内容......
所以这看起来真的是错误的。谁能看到我做错了什么?这是列主要与行主要问题还是什么?
使用 mat4 代替 vec4
所以我注意到我可能应该使用 mat4 进行转换,所以我将其更改为以下......
static const char gVertexShader[] =
"attribute vec4 vPosition;\n"
"uniform mat4 vid;\n"
"varying vec4 fragColor; \n"
"attribute vec4 inColor; \n"
"void main() {\n"
" gl_Position = vid * vPosition ;\n"
" fragColor = inColor; \n"
"}\n";
GLint location = glGetUniformLocation(gProgram, "vid");
glUniformMatrix4fv(location, 1, false, id);
现在起初这似乎可行,但是当我将其更改为这样的...
GLfloat id[] = { 10.0f, 0.0f, 0.0f, 0.0f,
0.0f, 10.0f, 0.0f, 0.0f,
0.0f, 0.0f, 10.0f, 0.0f,
0.0f, 0.0f, 0.0f, 10.0f};
它没有缩放,所以我觉得它还不正确......