我的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};
它没有变焦所以我感觉它还不对......