SFML community forums

Help => Window => Topic started by: uXeGen on March 25, 2011, 08:05:35 pm

Title: Load texture
Post by: uXeGen on March 25, 2011, 08:05:35 pm
Hi all! How to load texture by SFML and convert it in GLuint?

Thanks!
Title: Load texture
Post by: dathoedezt 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
Title: Load texture
Post by: devlin 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.
Title: Load texture
Post by: Laurent 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.