0
\$\begingroup\$

Just basing how sfml does it, I get the globalbound of the object and then check if the mouseposition is within the object. I tried do something like that but I dont know exactly how to do it with opengl. I tried changing the projection from -1 to 1 coords to the size of the application in the hope I could just get the position of the object, but when doing std::cout, it still shows the position in -1 to 1 coords.

So my question is: "How would I convert my mouseposition to -1 to 1 or vi-versa."

Its actually 0 to 2 and not -1 to 1

So far i have this:

I dont know exactly how to get the top left right with opengl I know with sfml. I would use the position and subtract the half of the width and height to get it but like I said, idk how to do that in opengl. I tried doing that but the object position i still -1 to 1 even though I passed in the

 glm::mat4 proj = glm::ortho(0,width, 0, height,-1,1);

I know my projection is working, because when I enter any big number, my object gets really small.

FYI, just because I see these types of answers alot; I'm not asking you to write me a fully functional button class. I just want a general idea on how it would be done or some article that could help me do that (or a very basic example).

void contain(glm::vec2 position)
{
    if (position.x >= button.left && position.x <= button.right
    && position.y >= button.top && position.y <= button.bottom) {
        std::cout << "True\n";
    }
    else {
        std::cout << "False\n";
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy