Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


How to do a Real Copy of TTF_Font (From SDL_ttf),


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Jabor   Members   -  Reputation: 104

Like
0Likes
Like

Posted 13 July 2012 - 08:33 AM

I'm currently developping some class to make my life simplier in SDL (My life haven't been really simpler since)
I have just create a classe named : Boutton, to create ... Boutton.

The class have 3 attributes :

[source lang="cpp"]char *b_t;SDL_Color b_ct;TTF_Font *b_p;[/source]


B_t and b_p are pointer. I have to destruct them or I will have a memory lack.
so I have added in my destructor the following line :

[source lang="cpp"]MISC_Bouton:: ~MISC_Bouton (){ TTF_CloseFont(b_p); delete(b_t);}[/source]

Now, I have to create a copy and an asign constructor,

My problem is, How I can do to do these
[source lang="cpp"] MISC_Bouton (MISC_Bouton const& other)MISC_Bouton& MISC_Bouton ::operator=(MISC_Bouton const& other)[/source])

I already had that kind of problem with SDL_Surface* in my windows class but there are a function to copy SDL_Surface (SDL_ConvertSurface()) so I was abled to copy the SDL_Surface in himself and not the adress.

So anyone knows something to copy a TTF_Surface and not the adress ?

Thanks

Sponsor:

#2 Faelenor   Members   -  Reputation: 396

Like
1Likes
Like

Posted 13 July 2012 - 09:44 AM

I think you should not copy them, but have a kind of resource manager. The resource manager will be responsible for the creation and destruction of the resources like this font. As a font can be shared between different objects, you won't use unnecessary memory to keep a copy for every objects using it. The resources should be ref counted, every object using them increasing the ref count and when the object is destroyed, the ref count is decreased. When the ref count reaches 0, the resource manager will destroy the resource.

#3 Jabor   Members   -  Reputation: 104

Like
0Likes
Like

Posted 13 July 2012 - 10:02 AM

It's ok, I have created a class Font, with the name and the font size in attribut, plus a function Get that return the TFF_Font*, so I won't have to create a TFF_Font* variable anymore.
I replace Char* by a string.


Thanks. =D




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS