0

我确信有更好的方法可以让我从四元数计算我的变换矩阵,但这就是我现在所拥有的。我需要将 16 个值传递到着色器中,但遇到了问题。我不断收到类型不兼容错误。另外,一旦我把它放在那里,我必须对它做任何事情来将它乘以我已经拥有的吗?

这是我的显示和着色器

void display()
{    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
if (trackballMove) 
{
   glRotatef(angle, axis[0], axis[1], axis[2]);
}
//colorcube();
glUniform3fv( theta, 1, Theta );

float a = angle;
float b = axis[0];
float c = axis[1];
float d = axis[2];
float xform[16] = {(a*a+b*b-c*c-d*d),(2*b*c-2*a*d),(2*b*d+2*a*c),0.0,
(2*b*c+2*a*d),(a*a-b*b+c*c-d*d),(2*c*d-2*a*b),0.0,
(2*b*d-2*a*c),(2*c*d+2*a*b),(a*a-b*b-c*c+d*d),0.0,
0.0,0.0,0.0,1.0};
        GLuint Transform = glGetUniformLocation( program, "vTransform");
        glUniformMatrix4fv(Transform,  xform);
glDrawArrays( GL_TRIANGLES, 0, NumVertices );
glutSwapBuffers();
}    

这是着色器

#version 150
in vec4 vPosition;
in vec4 vColor;
out vec4 color;
uniform vec3 theta;
uniform vec4 vTransform;

void main()
{
// Compute the sines and cosines of theta for each of
// the three axes in one computation.
vec3 angles = radians( theta );
vec3 c = cos( angles );
vec3 s = sin( angles );

// Remember: these matrices are column-major
mat4 rx = mat4( 1.0, 0.0, 0.0, 0.0,
0.0, c.x, -s.x, 0.0,
0.0, s.x, c.x, 0.0,
0.0, 0.0, 0.0, 1.0 );
mat4 ry = mat4( c.y, 0.0, s.y, 0.0,
0.0, 1.0, 0.0, 0.0,
-s.y, 0.0, c.y, 0.0,
0.0, 0.0, 0.0, 1.0 );
mat4 rz = mat4( c.z, -s.z, 0.0, 0.0,
s.z, c.z, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0 );
color = vColor;

gl_Position = vTransform *(rx * ry * rz * vPosition);
}
4

1 回答 1

2

您的 glUniformMatrix4fv 没有足够数量的参数。函数签名是

glUniformMatrix4fv(GLint location, GLsizei count,
    GLboolean transpose, const GLfloat *value);

在此处查看完整的 API 文档: http ://www.opengl.org/sdk/docs/man4/xhtml/glUniform.xml

于 2012-10-17T21:02:02.793 回答