Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: GLSL & Matrix Math

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Newbie
    Join Date
    Dec 2012

    GLSL & Matrix Math

    I'm new to 3-D math so I'm not sure if I'm doing this correctly.

    I currently have a GLfloat[ 36 ] pyramid set to the buffer, and that data is sent to an vec4 Vertex in the shader.

    Code :
        #version 400 core
        layout( location = 0 ) in vec4 Vertex;
        uniform mat4 Model;
        void main()
            gl_Position = Model * Vertex;

    I have a 4x4 matrix to rotate around the y-axis, and send that as a uniform to the "Model" variable in the shader.

    Code :
        glm::mat4 ModelR(
                cos( rStepAngle ), 0.f, -sin( rStepAngle ), 0.f,
                0.f, 1.f, 0.f, 0.f,
                sin( rStepAngle ), 0.f, cos( rStepAngle ), 0.f,
                0.f, 0.f, 0.f, 0.f
        GLint ModelLoc = glGetUniformLocation( programs.basicShader, "Model" );
        glUniformMatrix4fv( ModelLoc, 1, GL_FALSE, glm::value_ptr( ModelR ) );

    I'm getting nothing on my screen except the clear color. I think I may be misunderstanding something here. Vertex is going to be 3 components (technically 4, with 1 at the end), that gets multiplied by the Model rotation. How many times is the main() of the shader being run? My understanding of it was that main() is run until all 12 vertices of the pyramid are multiplied by the Model matrix. Is this correct?

    There's probably something wrong with my math...
    Last edited by Qoheleth; 12-29-2012 at 11:27 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts