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

Author Topic: So, can't use sf::Texture as a const  (Read 2520 times)

0 Members and 3 Guests are viewing this topic.

ezio160324

  • Newbie
  • *
  • Posts: 11
    • View Profile
So, can't use sf::Texture as a const
« on: August 15, 2014, 02:11:13 pm »
So, I'm using this 3D fork of SFML by binary1248. I've run into a problem. His *.objs require
const sf::texture
as the texture. Only problem, it my program crashes if I try to create an
sf::texture
as const. Any ideas?

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: So, can't use sf::Texture as a const
« Reply #1 on: August 15, 2014, 02:21:50 pm »
His *.objs require
const sf::texture
as the texture.
What do you mean by this? What *.objs are you talking about? What function are you calling? ???
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

ezio160324

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: So, can't use sf::Texture as a const
« Reply #2 on: August 15, 2014, 02:23:28 pm »
        sf::Texture *texture;
texture->loadFromFile("texture.png");

That's the function. I guess.

I'm talking in your *.obj class that came in the 3d example file.
« Last Edit: August 15, 2014, 02:25:02 pm by ezio160324 »

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: So, can't use sf::Texture as a const
« Reply #3 on: August 15, 2014, 02:39:15 pm »
???
There isn't a single sf::Texture in the ObjModel class.
There are no sf::Texture* in that whole file.

https://github.com/binary1248/SFML/blob/master/examples/3d/3d.cpp

Tell me what line you are referring to.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

ezio160324

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: So, can't use sf::Texture as a const
« Reply #4 on: August 15, 2014, 02:45:59 pm »
Quote
There isn't a single sf::Texture in the ObjModel class.
There are no sf::Texture* in that whole file.

https://github.com/binary1248/SFML/blob/master/examples/3d/3d.cpp

Tell me what line you are referring to.

I'm saying that when I have a model
        ObjModel model;
        model.loadFromFile("model.obj")

like that and try to use
sky.setTexture(texture);
it fails because it requires said texture to be like

sf::Texture *texture;
aka a const. But, my problem is, when I try to load a texture with it being
sf::Texture *texture;
my program crashes. I guess I worded my question wrong, initially.
« Last Edit: August 15, 2014, 03:11:58 pm by ezio160324 »

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: So, can't use sf::Texture as a const
« Reply #5 on: August 15, 2014, 03:02:42 pm »
ObjModel model;
if (!model.loadFromFile("model.obj"))
{
    // error
}

sf::Texture texture;
if (!texture.loadFromFile("texture.png"))
{
   // error
}

model.setTexture(&texture);

// ???

// profit
A model and therefore sf::Polyhedron is no different from a standard, vanilla, mainline sf::Shape. The same texture lifetime constraint applies here as well. This is stated in the Polyhedron documentation as well as the official SFML documentation for sf::Shape::setTexture().

Have you used standard SFML much? Because you should get used to the general feeling of its API before trying out 3DEE. It is more advanced, assumes you know how to use SFML to a certain extent and is generally less forgiving than standard SFML. I only recommend it to people who are comfortable with standard SFML as it is and know how to help themselves. You won't get much support for 3DEE as not many people use it.

Judging by your understanding that sf::Texture* is a const, whatever you think that means, I also recommend you to get more familiar with C++ as well. Not being comfortable with C++ or standard SFML is probably the worst position to start using 3DEE from.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

ezio160324

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: So, can't use sf::Texture as a const
« Reply #6 on: August 15, 2014, 03:11:18 pm »
I see where you come from. But sometimes I miss the simplest things. Such as, it can't seem to find the texture. I'm sure I'm missing something so dang simple.

EDIT: Ah, it was indeed something simple. Fixed! :D

Except model is now black. Will be fixed soon! :p

EDIT: How odd, it seems to only take the outer edges of the texture. My texture is black around the edge. So the model is black. I try another texture that is white around the edges, model is white.  ???
« Last Edit: August 15, 2014, 04:16:30 pm by ezio160324 »