Page 1 of 1

SFML Texture Loading

PostPosted: Thu Feb 16, 2012 4:33 pm
by LordSupremePerson
Documentation: ... 1Image.php

Sample code pulled from
Code: Select all
void LoadTextures()
   sf::Image img;
      throw 1;

   glGenTextures(1, textures);
   glBindTexture(GL_TEXTURE_2D, textures[0]);
   glTexImage2D(GL_TEXTURE_2D, 0, 3, img.GetWidth(), img.GetHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, img.GetPixelsPtr());


Obviously you need to tweak that to whatever you want to use, (for example the "textures" variable isnt defined in that function), but what is above should be fine for any thinking individual to get started

Re: SFML Texture Loading

PostPosted: Wed Feb 22, 2012 5:15 am
by LordSupremePerson
This will save you kids some time, SFML automatically reformats the image to RGBA so you need:
Code: Select all
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.GetWidth(), img.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, img.GetPixelsPtr());

I also noticed my texture wasnt lining up but then I flipped it vertically and that fixed it... not sure if that was an issue with my implementation or not
Code: Select all

Re: SFML Texture Loading

PostPosted: Thu Feb 23, 2012 4:28 pm
by eawerbaneth
I had to flip my image too. I think it just has to do with the way SFML stores image data.