im trying to apply a rotation matrix to my shader and when i try to set it and mult it in the shader my triangle doesn't render

my drawing code:

        var rotmat = Matrix4d.CreateRotationZ(45);

        shader.SetMatrix("transform", rotmat);



    public void SetMatrix(string name,Matrix4d mat)
        int index = GL.GetUniformLocation(Program, name);
        GL.UniformMatrix4(index, false,ref mat);

vertex shader code:

#version 440 core
layout (location = 0) in vec3 position;
layout(location = 1) in vec4 color;
layout(location = 20)uniform mat4 transform;

out vec4 fragcolor;

void main(void)
  gl_Position = transform * vec4(position,1.0);
  fragcolor = color;

This is happening because in OpenGL uniform values (set by glUniform calls) are part of program object state, i.e. specific to the currently bound program.

If you wish to change a uniform value you must bind the program first (via glUseProgram); in your code that means calling shader.Use before shader.SetMatrix.

Depending on your GL version you may alternately be able to call glProgramUniformMatrix4fv which doesn't require the program to be bound first.

  • \$\begingroup\$ it's still not showing my triangle, do i have to use a projection and view matrix too? \$\endgroup\$ Sep 9 '19 at 23:31
  • \$\begingroup\$ it works when i use a float based matrix but it won't work with a double based matrix do you know any way to fix this? im making a minecraft like game and im trying to use double precision \$\endgroup\$ Sep 10 '19 at 0:21
  • \$\begingroup\$ @vincentcastro I think you want dmat4 instead of mat4. Similarly, there are dvec3 and dvec4. See Data Type (GLSL). \$\endgroup\$
    – Theraot
    Sep 10 '19 at 4:07
  • \$\begingroup\$ ... But make sure your GPU supports doubles first. And remember, Minecraft itself doesn't use doubles, so there is always another way. In fact, this would be better as a separate question rather than an ongoing discussion in comments. \$\endgroup\$ Sep 10 '19 at 7:01

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.