Page 1 of 1
SDL_Surface* load_image( std::string filename ) Question
Posted: Wed May 19, 2010 12:01 am
by GameDevver4Evr
Hey guys, this might sound stupid, but im not sure exactly on this.
is there any hope of using this function, or similar within a class?, as in defining it within a class.
SDL_Surface* load_image( std::string filename )
{
return 0;
}
or will it always need to remain Global?, sorry if it's a stupid question.
Re: SDL_Surface* load_image( std::string filename ) Question
Posted: Wed May 19, 2010 1:30 am
by Ginto8
The short answer: it depends. You can have it hidden somewhere in the depths of your graphics engine, lurking like a troll under a bridge, or you could lightly encapsulate it in some other class that adds certain functionality to your surfaces. I could go even more into the possibilities, but I'm tired and don't really want to right now; but you get the point.
Re: SDL_Surface* load_image( std::string filename ) Question
Posted: Wed May 19, 2010 5:32 pm
by eatcomics
Well like ginto said, it depends. I would usually have a function to load them like that, then load the textures I need at the beginning so that I can access them with my class which would have a pointer to that surface
Re: SDL_Surface* load_image( std::string filename ) Question
Posted: Wed May 19, 2010 7:26 pm
by dandymcgee
Yes, I always put it into a class. In the past I've used something like
Code: Select all
Renderer.LoadSurface( "example.png" );
Re: SDL_Surface* load_image( std::string filename ) Question
Posted: Wed May 19, 2010 7:29 pm
by XianForce
What I did is encapsulated an SDL_Surface* within it's own class so I had something like this:
Code: Select all
class Surface
{
private:
SDL_Surface* m_pSurface;
public:
bool LoadImage(std::string filename);
};
So basically I'd have it load in the file, then assign whatever it would normally return, to m_pSurface. If m_pSurface is NULL, return false, otherwise return true =D
Re: SDL_Surface* load_image( std::string filename )[Solved]
Posted: Wed May 19, 2010 8:02 pm
by GameDevver4Evr
Cool, thanks all for the replies, and thanks Xian, that was kinda of what I was looking for!
Re: SDL_Surface* load_image( std::string filename ) Question
Posted: Wed May 19, 2010 8:09 pm
by dandymcgee
XianForce wrote:What I did is encapsulated an SDL_Surface* within it's own class so I had something like this:
Code: Select all
class Surface
{
private:
SDL_Surface* m_pSurface;
public:
bool LoadImage(std::string filename);
};
So basically I'd have it load in the file, then assign whatever it would normally return, to m_pSurface. If m_pSurface is NULL, return false, otherwise return true =D
I have personally used this approach as well, and I've found it works great for smaller projects where one doesn't necessarily need a complete rendering or video class.
Re: SDL_Surface* load_image( std::string filename ) Question
Posted: Wed May 19, 2010 9:40 pm
by XianForce
dandymcgee wrote:XianForce wrote:What I did is encapsulated an SDL_Surface* within it's own class so I had something like this:
Code: Select all
class Surface
{
private:
SDL_Surface* m_pSurface;
public:
bool LoadImage(std::string filename);
};
So basically I'd have it load in the file, then assign whatever it would normally return, to m_pSurface. If m_pSurface is NULL, return false, otherwise return true =D
I have personally used this approach as well, and I've found it works great for smaller projects where one doesn't necessarily need a complete rendering or video class.
Well I have a Video class, but it just takes a reference to my surface class instead of an SDL_Surface*... I decided to split it, because I thought that loading the files had less to do with the video system, than actually rendering them =p
Re: SDL_Surface* load_image( std::string filename ) Question
Posted: Mon May 31, 2010 9:02 am
by WSPSNIPER
ya you can use it in a class, i always usto but using it as a global may be simpler if you dont have much exp. with oo programming. but on the other hand how will you learn. I use to think the same way i always wanted things global but once i learned about oo programming i always use it and i find it makes life easier