Unable to set uniform value in OpenGL shader

I am currently studying OpenGL programming, and I have achieved some success, but it seems to be stuck right now.

I'm currently trying to get simple shaders to work. To be more specific, I am trying to set a uniform shader value . Shaders compile successfully and work correctly if I exclude a uniform value. Here is the shader (vertex) code:

#version 440 core

layout(location = 0) in vec3 vertex;

uniform mat4 mvp;

void main()
{
    gl_Position = mvp * vec4(vertex, 1);
}

And the code that I use to set the value ( glGetUniformLocationreturns 0, as expected):

mvp = glm::mat4(
    glm::vec4(3.0f, 0.0f, 0.0f, 0.0f),
    glm::vec4(0.0f, 1.0f, 0.0f, 0.0f),
    glm::vec4(0.0f, 0.0f, 1.0f, 0.0f),
    glm::vec4(0.0f, 0.0f, 0.0f, 2.0f)
);

GLuint matrix = glGetUniformLocation(program, "mvp");
glUniformMatrix4fv(matrix, 1, GL_FALSE, glm::value_ptr(mvp));

, , , . glGetUniformfv, ( , ), ( , ).

, , ( , glGetUniformfv), .

#version 440 core

layout(location = 0) in vec3 vertex;

uniform mat4 mvp = mat4(
    vec4(1.0f, 0.0f, 0.0f, 0.0f),
    vec4(0.0f, 1.0f, 0.0f, 0.0f),
    vec4(0.0f, 0.0f, 1.0f, 0.0f),
    vec4(0.0f, 0.0f, 0.0f, 2.0f)
);

void main()
{
    gl_Position = mvp * vec4(vertex, 1);
}

, ? OpenGL 4.4, .

,
Levente

+3
1

glUseProgram ? , , - (https://github.com/prabindh/sgxperf/blob/master/sgxperf_gles20_vg.cpp), :

glCreateProgram();

     

glAttachShader()

     

glLinkProgram

     

glUseProgram()

     

glGetUniformLocation()

     

glUniformMatrix4fv

+10

All Articles