4

I can't get the call to glm::rotate(mat4, int, vec3(x,y,z)); to work. VS 2010 is telling me

Intellisense: no instance of function template "glm::gtc::matrix_transform::rotate" matches the argument

I'm using glm-0.9.1

I've seen this stack overflow question, but the solution still triggers an error with the intellisense: glm rotate usage in Opengl

I can't really get it to accept any of the overload methods. I might just be missing something obvious though.

I tried to make the rotate call apparent in the code, it is a bit of the way down.

here is some code:

#include <GL/glew.h>
#include <GL/glfw.h>
#include <GL/glut.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>

#include "loadShader.h"

#include <stdio.h>
#include <stdlib.h>

glm::mat4 Projection;
glm::mat4 View;
glm::mat4 Model;
glm::mat4 MVP;

glm::mat4 t;
glm::mat4 s;
glm::mat4 r;


GLuint programID;


int main()
{

    // Initialise GLFW
    if( !glfwInit() )
    {
        fprintf( stderr, "Failed to initialize GLFW\n" );
        return -1;
    }

    glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    // Open a window and create its OpenGL context
    if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) )
    {
        fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
        glfwTerminate();
        return -1;
    }

    // Initialize GLEW
    if (glewInit() != GLEW_OK) {
        fprintf(stderr, "Failed to initialize GLEW\n");
        return -1;
    }

    glfwSetWindowTitle( "Tutorial 02" );

    // Ensure we can capture the escape key being pressed below
    glfwEnable( GLFW_STICKY_KEYS );

    glewExperimental = GL_TRUE;
    glewInit();




    // Dark blue background
    glClearColor(0.0f, 0.0f, 0.3f, 0.0f);

    GLuint VertexArrayID;

    glGenVertexArrays(1, &VertexArrayID);

    glBindVertexArray(VertexArrayID);



    // Create and compile our GLSL program from the shaders
    programID = LoadShaders( "vertexShader.glsl", "fragmentShader.glsl" );


        //Pojectio matrix : 45 degree Field of view, 4:3 ratio, display range : 0.1 unit <-> 100 units
    Projection = glm::perspective( 45.0f, 4.0f / 3.0f, 0.1f, 100.0f );
    // Camera matrix
    View = glm::lookAt(
        glm::vec3(4,3,3), // Camera is at (4,3,3), in World Space
        glm::vec3(0,0,0), // and looks at the origin
        glm::vec3(0,1,0) // Head is up (set to 0, -1,0 to look upside down)
        );
    // Model matrix : an identity matrix (model will be at the origin)




    Model = glm::mat4(1.0f); // Changes for each Model !

    //INTELLISENSE ERROR ==================================================================>>>>
    r = glm::rotate(Model, 45, glm::vec3(1,0,0));

    // Our ModelViewProjection : multiplication of our 3 matrices
    MVP = Projection * View * Model; // Remember matrix multiplication is the other way around


        // Get a handle for our "MVP" uniform.
    // Only at initialisation time.
    GLuint MatrixID = glGetUniformLocation(programID, "MVP");

    // Send our transformation to the currently bound shader,
    // in the "MVP" uniform
    // For each model you fender, since the MVP will be different (at least the M part)


    static const GLfloat g_vertex_buffer_data[] = { 
        -1.0f, -1.0f, 0.0f,
         1.0f, -1.0f, 0.0f,
         0.0f,  1.0f, 0.0f,
    };

    GLuint vertexbuffer;
    glGenBuffers(1, &vertexbuffer);
    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);





    do{

        // Clear the screen
        glClear( GL_COLOR_BUFFER_BIT );

        // Use our shader
        glUseProgram(programID);

        glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);

        // 1rst attribute buffer : vertices
        glEnableVertexAttribArray(0);
        glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
        glVertexAttribPointer(
            0,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
            3,                  // size
            GL_FLOAT,           // type
            GL_FALSE,           // normalized?
            0,                  // stride
            (void*)0            // array buffer offset
        );

        // Draw the triangle !
        glDrawArrays(GL_TRIANGLES, 0, 3); // From index 0 to 3 -> 1 triangle

        glDisableVertexAttribArray(0);

        // Swap buffers
        glfwSwapBuffers();

    } // Check if the ESC key was pressed or the window was closed
    while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
           glfwGetWindowParam( GLFW_OPENED ) );

    // Close OpenGL window and terminate GLFW
    glfwTerminate();

    // Cleanup VBO
    glDeleteBuffers(1, &vertexbuffer);
    glDeleteVertexArrays(1, &VertexArrayID);

    return 0;
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
not_shitashi
  • 281
  • 2
  • 4
  • 12
  • Does it actually *compile*? If not, what compiler error do you get? – Nicol Bolas Aug 23 '12 at 05:30
  • Not related, but since this code comes from my website : why do you include glut AND glfw at the same time ? – Calvin1602 Aug 23 '12 at 13:11
  • @Nicol Bolas: it does not compile. Calvin1602: does glfw include glut? I've never heard of glfw before your website. I thought it was just for setting up and opening the window, keyboard etc. – not_shitashi Aug 24 '12 at 16:33

3 Answers3

24

I don't know enough about templates to give you a great answer, but I believe from my memory of GLM is that it was very picky about types.

Can you try explicitly changing 45 to 45.f to see if it accepts that? I think you need to have consistent parameters (float matrix, float, float vector). I think the int confuses it somehow.

Tim
  • 35,413
  • 11
  • 95
  • 121
2
glm::rotate(Model, (glm::mediump_float)45, glm::vec3(1,0,0));

I found that this cast is helping because of the type used in glm::vec3 as template.

This function is that defined:

glm::detail::tmat4x4<glm::lowp_float> glm::rotate<glm::lowp_float> ( const glm::detail::tmat4x4<glm::lowp_float> &m, const glm::lowp_float &angle, const glm::detail::tvec3<glm::mediump_float> &axis)

So you must use appropriate type in your angle value.

Ren
  • 1,111
  • 5
  • 15
  • 24
RadekJ
  • 2,835
  • 1
  • 19
  • 25
  • glm::mediump_float is just a typedef for float – Twometer Jun 07 '18 at 12:20
  • Yes it is, but function is definied with `glm::mediump_float` so I would keep prefer to use `(glm::mediump_float)45.f` to be sure which function will be called. – RadekJ Jun 08 '18 at 05:08
  • You can keep it for clarity if you like, but the compiler will replace the `glm::mediump_float` with a regular `float` anyway since it is a `typedef` so if you do `45.f` (which defines a float) this will suffice to define which function is called. – Twometer Jun 08 '18 at 07:23
-2

I think problems actually at "glm.h" file. To be honest, I don't know much about technical knowledge to explain why but as I try to fix this error, it worked. So I just want to share my experience to someone that is in need.

As you know that library files that we define our-self should be (or need to be) put between the double quotes (" ") rather than the angle brackets (< >).

So when I right clicked at #include"glm.h" (Go To Document "glm.h") to see what happened, it directed me to that file. Inside it, I can see 3 other lines:

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

Then I changed the <> by " " as I said before:

#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/type_ptr.hpp"

My glm::rotate() function now work!!!

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • 1
    This answer definitely does not match the question (solves a different problem, if any). It is also dangerous and should never be treated seriously (NEVER ever change manually external library source code, unless you want to fork it and turn into an internal library). – zkoza Mar 05 '21 at 08:03
  • Of course it is not a good answer but as I told, you can choose not to follow and it is easy to fix back - change " " by < > and everything become normal with your original errors. I am here just to give a solution, it may not work for you, for anyone but It maybe work for me or someone else. It rather a solution to try rather than nothing bro. I do it by my experience - my chance, maybe I am lucky, not my knowledge, I already said that!!! – San Andreas Mar 07 '21 at 14:42