SFML community forums
Help => Window => Topic started by: uXeGen on March 25, 2011, 08:05:35 pm
-
Hi all! How to load texture by SFML and convert it in GLuint?
Thanks!
-
this is how i do it
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
-
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.
-
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.