0
\$\begingroup\$

I am trying to convert this C++ gml code to C and am getting the same array but I cannot see anything on the screen, is there something I am doing wrong maybe on the shader?

GML code in C++:

GLuint MatrixID = glGetUniformLocation(programID, "MVP");
...
glm::mat4 MVP = Projection * View * Model;
printf("MVP:\n");
for(int i=0;i<4;i++)
  for(int j=0;j<4;j++)
    printf("%.2f\n",MVP[i][j]);  //prints the same list as in C
...
//durante el loop
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]); //draw a cube

C code:

GLuint MatrixID = glGetUniformLocation(programID, "MVP");
...
t_mat4 MVP;  //t_mat4 defined as typedef double t_mat4[16];
mulMatrix(Projection,View,MVP);
mulMatrix(MVP,Model,MVP);
printf("proj*view*model\n");
inrange(i,16)
    printf("%.2f\n",MVP[i]); //unidimensional array
...
//durante el loop
glUniformMatrix4dv(MatrixID, 1, GL_FALSE, MVP); //Nothing shows up

vertex shader:

#version 330 core

// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec3 vertexColor;

// Output data ; will be interpolated for each fragment.
out vec3 fragmentColor;
// Values that stay constant for the whole mesh.
uniform mat4 MVP;

void main(){    

    // Output position of the vertex, in clip space : MVP * position
    gl_Position =  MVP * vec4(vertexPosition_modelspace,1);

    // The color of each vertex will be interpolated
    // to produce the color of each fragment
    fragmentColor = vertexColor;
}
\$\endgroup\$
0
\$\begingroup\$

glUniformMatrix4dv(MatrixID, 1, GL_FALSE, MVP); //Nothing shows up

This will yield an OpenGL GL_INVALID_OPERATION error. The reason being that the MatrixID variable is of type mat4, which is a float matrix, not a dmat4 (which, BTW, is not supported in GLSL 3.30). You almost certainly meant 4fv.

And of course, your C code should be using float arrays, not doubles.

\$\endgroup\$
  • \$\begingroup\$ ok, I'm not sure why but the cgml library only uses double types. Thank you by the way. \$\endgroup\$ – shuji Jun 30 '17 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.