SDL_Surface* load_image( std::string filename ) Question
Moderator: Coders of Rage
-
- Chaos Rift Newbie
- Posts: 33
- Joined: Mon Mar 08, 2010 9:34 pm
SDL_Surface* load_image( std::string filename ) Question
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.
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.
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: SDL_Surface* load_image( std::string filename ) Question
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.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Re: SDL_Surface* load_image( std::string filename ) Question
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
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: SDL_Surface* load_image( std::string filename ) Question
Yes, I always put it into a class. In the past I've used something like
Code: Select all
Renderer.LoadSurface( "example.png" );
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
Re: SDL_Surface* load_image( std::string filename ) Question
What I did is encapsulated an SDL_Surface* within it's own class so I had something like this:
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
Code: Select all
class Surface
{
private:
SDL_Surface* m_pSurface;
public:
bool LoadImage(std::string filename);
};
-
- Chaos Rift Newbie
- Posts: 33
- Joined: Mon Mar 08, 2010 9:34 pm
Re: SDL_Surface* load_image( std::string filename )[Solved]
Cool, thanks all for the replies, and thanks Xian, that was kinda of what I was looking for!
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: SDL_Surface* load_image( std::string filename ) Question
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.XianForce wrote:What I did is encapsulated an SDL_Surface* within it's own class so I had something like this:
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 =DCode: Select all
class Surface { private: SDL_Surface* m_pSurface; public: bool LoadImage(std::string filename); };
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
Re: SDL_Surface* load_image( std::string filename ) Question
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 =pdandymcgee wrote: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.XianForce wrote:What I did is encapsulated an SDL_Surface* within it's own class so I had something like this:
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 =DCode: Select all
class Surface { private: SDL_Surface* m_pSurface; public: bool LoadImage(std::string filename); };
- WSPSNIPER
- Chaos Rift Regular
- Posts: 145
- Joined: Sun Jan 03, 2010 6:19 pm
- Current Project: top down shooter
- Favorite Gaming Platforms: ps3
- Programming Language of Choice: c++
Re: SDL_Surface* load_image( std::string filename ) Question
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