Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Get program ID in shaders object of opengl context  (Read 2389 times)

0 Members and 1 Guest are viewing this topic.

Afendar

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Afendar Website
Get program ID in shaders object of opengl context
« on: December 17, 2017, 02:26:29 pm »
Hello everyone,

Let me explain, I try to create a simple camera in free fly mode. I now pass my camera in openGL compatibility 3. So I try to remove the deprecated gluLookAt method to use the MVP matrices.

So I made a sample code below to simulate the returns of the matrix view and projection of my camera.

glm::mat4 projection = glm::perspective(glm::radians(0.0f), (float)1280 / (float)720, 0.1f, 100.f);
glm::mat4 view = glm::lookAt(
        glm::vec3(-10, 30, 3),
        glm::vec3(0, 0, 0),
        glm::vec3(0, 1, 0)
);

glm::mat4 model = glm::mat4(1.0f);
glm::mat4 mvp = projection * view * model;
 

Now the cruel question is how to send the matrices to the GLSL. So I use this kind of code but I miss the programID I can not get in the object sf :: RenderWindow.

GLuint matrixID = glGetUniformLocation(shaderId, "MVP");
GLuint viewMatrixID = glGetUniformLocation(shaderId, "V");
GLuint modelMatrixID = glGetUniformLocation(shaderId, "M");

glUniformMatrix4fv(matrixID, 1, GL_FALSE, &mvp[0][0]);
glUniformMatrix4fv(modelMatrixID, 1, GL_FALSE, &model[0][0]);
glUniformMatrix4fv(viewMatrixID, 1, GL_FALSE, &view[0][0]);
 

Is there another way to recover this? Or is the method I am trying to do not at all suitable? If so, could you put me back on track?

I thank you in advance for your feedback.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Get program ID in shaders object of opengl context
« Reply #1 on: December 17, 2017, 03:38:42 pm »
Either you manage shaders on your own with direct OpenGL calls, and you obviously have the program ID available, or you use sf::Shader and you should use its setUniform function to send the matrices.
Laurent Gomila - SFML developer

Afendar

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Afendar Website
Re: Get program ID in shaders object of opengl context
« Reply #2 on: December 18, 2017, 10:47:05 am »
Thanks a lot !

I have resolve my problem. Thanks again.

Have nice day.

 

anything