Help needed to load uniforms in Rust / GTK / OpenGL

I am using Open GL to draw in a GLArea. I have a working prototype and am now trying to add the required matrix stuff for aspect ratio rotation etc.

I have my shaders and GlProgram loading and working, but can’t successfully get the uniform location.
The vertex shader is

#version 330

layout (location = 0) in vec3 Position;
out vec3 vColor;

uniform mat4 perspective;
uniform mat4 matrix;

void main()
{
    gl_Position = vec4(Position, 1.0) * perspective * matrix;
    vColor = vec3(0.75, 1.0, 1.0);
}

and I try to get the uniform location in my render code with

let p = gl::GetUniformLocation(program_id, "perspective".as_ptr() as *const gl::types::GLchar);

but this always returns -1

I have also tried making this call directly after linking the program, but still get -1

Solution is obvious once you work it out. The uniform name needs to be a null terminated “C” style string. The following did the trick:

let p = gl::GetUniformLocation(program_id, b"perspective\0".as_ptr() as *const gl::types::GLchar);
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.