Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MarsuGL

a c++ question

This topic is 6202 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello, i have made two classes for opengl, the first loads textures in memory etc.. Ctexture the second (Cfont)draws bitmap fonts onto the screen and NEEDS to use a Ctexture method. the problem is that the Ctexture and Cfont objects are created in the main, and in the CfontrintFont() method i need to call Ctexture::switchtexture() method wich is not visible there. so, i pass a pointer from my Ctexture object when i call the constructor of the Cfont object and it works, but, i want to be sure that it is OOP correct, i want a clean code wich is ok for C++ concepts is it the common way to do that ? (an object that use an other object). that assumes that in the future, if i want to use Cfont, a Ctexture object MUST be created before. tanks for your help by advance Dominique, OOP newbie.

Share this post


Link to post
Share on other sites
Advertisement
The correct "Object Oriented" way to do it is to use inheritance, you make your cfont class as a child class of ctexture, and this way you can call functions that belong to the parent from the child, however I read in Tricks of the windows game programming gurus that in a game is ok to use C++, just not mae much use of inheritance, overriding, virtual functions and the like, so sometimes what I do is put a class object inside a class, so the Cfont class has a private (or public, your choise) ctexture object, or a pointer to one (if you want to use one texture to for many cfont objects).
my point is, sometimes clean code is not the best way performance wise, to code, and you have to come up with your own tricks, and if it compiles, and you get a better performance, why not go with it? if you want it clean for someone else to understand, use comments.

--------------------------------------------------------
"When you say ''I wrote a program that crashed Windows'',
people just stare at you blankly and say
''Hey, I got those with the system, *for free*''."

Linus Torvalds.

Share this post


Link to post
Share on other sites
tanks for the help,

i will make some benchmarks later,
but there is a problem if i create a Ctexture object in the Cfont class because the texture with the fonts is allready loaded during init(), in the main, when the first texture object is created, so the texture object has an attribute wich is private, it''s a pointer to a dynamic array that is used to generate the texture, so this array will not be visible if i create a new object (there will be a new and empty array).

i havn''t yet thinked to inheritance and how it will work.

marsu

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!