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

Author Topic: Load texture  (Read 1406 times)

0 Members and 1 Guest are viewing this topic.

uXeGen

  • Newbie
  • *
  • Posts: 1
    • ICQ Messenger - 408245433
    • View Profile
Load texture
« on: March 25, 2011, 08:05:35 pm »
Hi all! How to load texture by SFML and convert it in GLuint?

Thanks!

dathoedezt

  • Newbie
  • *
  • Posts: 9
    • View Profile
Load texture
« Reply #1 on: March 25, 2011, 08:20:43 pm »
this is how i do it

Code: [Select]
GLuint LoadGLTexture(const std::string &path) {
    GLuint texture;
    sf::Image img;

    img.LoadFromFile(path);

    glGenTextures(1, &texture);
    glBindTexture(GL_TEXTURE_2D, texture);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.GetWidth(), img.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, img.GetPixelsPtr());

    return texture;
}


prolly better to check if texture power of 2 and all that

devlin

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Load texture
« Reply #2 on: March 26, 2011, 07:44:38 am »
If you just want to bind the image, use the Image::Bind function.

However, (and this is for Laurent) - perhaps it would be an idea to set the internals to protected, rather than private - to allow others to make their own decorated subclass that can return and/or work on "myTexture" and the others for other purposes.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Load texture
« Reply #3 on: March 26, 2011, 08:56:14 am »
Quote
However, (and this is for Laurent) - perhaps it would be an idea to set the internals to protected, rather than private - to allow others to make their own decorated subclass that can return and/or work on "myTexture" and the others for other purposes.

To do anything with a texture you need to bind it first, so the Bind() function is equivalent to a public access on myTexture.
Laurent Gomila - SFML developer