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

Author Topic: Enabling textures  (Read 1972 times)

0 Members and 1 Guest are viewing this topic.

yetti

  • Newbie
  • *
  • Posts: 3
    • View Profile
Enabling textures
« on: November 06, 2010, 10:19:58 pm »
Hi,
I'm trying to enable textures in SFML (OpenGL) but I simply can't get it working.

I had a project done SDL/Windows GDI, I ported it to SFML and everything works except textures.

I'm using DevIL for loading image files and it was working under SDL/GDI. I tried sf::Image but no, all objects are white (glColor works).

Can anyone provide me a simple snippet how to enable textures?

I'm sorry, I can't provide you source files.

VC2010/SFML 1.6

Thanks,
yetti

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Enabling textures
« Reply #1 on: November 06, 2010, 10:41:54 pm »
It depends how you use sf::Image: only to load pixels to your own GL texture, or directly?
Laurent Gomila - SFML developer

yetti

  • Newbie
  • *
  • Posts: 3
    • View Profile
Enabling textures
« Reply #2 on: November 06, 2010, 10:56:23 pm »
well, something like this

Code: [Select]
sf::Image image = sf::Image();
// loading texture
if(!image.LoadFromFile("assets/missing.jpg")) {
 // breakpoint
}
const sf::Uint8* ptr = image.GetPixelsPtr();
GLuint tex;
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,256,256,0,GL_RGB,GL_UNSIGNED_BYTE,ptr);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, textures[0]);


This might not be ok, but the DevIL code was working before so I wonder why it doesn't work under SFML.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Enabling textures
« Reply #3 on: November 06, 2010, 10:57:38 pm »
Your code looks ok. You should have a look at the OpenGL example of the SFML SDK, it does exactly the same thing.
Laurent Gomila - SFML developer

yetti

  • Newbie
  • *
  • Posts: 3
    • View Profile
Enabling textures
« Reply #4 on: November 06, 2010, 11:09:39 pm »
Sorry to start this thread then, I missed the file ;). It works so I have an error in the rest of the code somewhere.

Thanks for the quick help and btw great work on SFML, respect to all SFML developers

 

anything