Jump to content
  • Advertisement
Sign in to follow this  
CableGuy

Libs, headers and external libs.

This topic is 3628 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

Hi. I have created a library to use FreeType and I have a problem:
class FontResource
{
	friend class Renderer;
public:
	FontResource();
	
	bool Load(const string &name);		
	bool Load(const string &name,int size);	
private:
	bool AddChar(char c);
	vector<Glyph> glyph;
	FontPage *page;
	FT_Face face;
	int size;
};

As you can see I need to store FT_Face which is part of FreeType, which forces the users of my code also to include the FreeType headers. One way around it that I came up with is to store a void* and cast it in the source but that's too much hacky... Any ideas how to sort this out? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Pimpl.

Basic idea is, using a different example:

lib.h

class Texture
{
private:
class Imp; Imp *i; // forward declaration, can only use pointers and references

public:
Texture();
~Texture();
};





lib.cpp

#include <d3d9.h>

class Texture::Imp
{
public:
Imp() : Ptr(0) { }
~Imp(){ if(Ptr) Ptr->Release(); }

IDirect3DTexture9 *Ptr;
}

Texture::Texture()
{
i=new Imp(); i->Ptr=CreateTextureSomehow();
}

Texture::~Texture()
{
delete i;
}




This way, users including lib.h do not need to include, or even be aware of, d3d9.h or have any of its symbols dumped into global scope. Indeed you could change the implementation to use OpenGL and you would only have to recompile the library file and relink the project that uses it.

The link at the top will explain in far more detail.

Share this post


Link to post
Share on other sites
Or you can use a pointer to an FT_Face. You don't need to include the FreeType header for that, but you do need to do some extra memory management for it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!