Using the following code:
static void loadCourier(sf::Texture &courier, sf::Image &im)
{
sf::Uint8 pxls[256 * 96 * 4];
std::ifstream fl("Courier.pbm", std::ios_base::binary);
if (!fl.good()) {
std::runtime_error e("Could not load Courier.pbm");
throw e;
}
fl.seekg(10, std::ios_base::beg);
char c;
unsigned int i = 0;
while (fl.good()) {
fl.get(c);
pxls[i]=pxls[i+1]=pxls[i+2]=pxls[i+3]=((c&128)?255:0);
pxls[i+4]=pxls[i+5]=pxls[i+6]=pxls[i+7]=((c&64)?255:0);
pxls[i+8]=pxls[i+9]=pxls[i+10]=pxls[i+11]=((c&32)?255:0);
pxls[i+12]=pxls[i+13]=pxls[i+14]=pxls[i+15]=((c&16)?255:0);
pxls[i+16]=pxls[i+17]=pxls[i+18]=pxls[i+19]=((c&8)?255:0);
pxls[i+20]=pxls[i+21]=pxls[i+22]=pxls[i+23]=((c&4)?255:0);
pxls[i+24]=pxls[i+25]=pxls[i+26]=pxls[i+27]=((c&2)?255:0);
pxls[i+28]=pxls[i+29]=pxls[i+30]=pxls[i+31]=((c&1)?255:0);
i += 32;
}
im.create(256, 96, pxls);
courier.loadFromImage(im);
std::cout << "Loaded.\n";
}
Resources::Resources()
: courier(), textshader(), im()
{
loadCourier(courier, im);
// ...
}
// In .h file
class Resources
{
public:
Resources();
~Resources();
sf::Texture courier;
sf::Shader textshader;
sf::Image im;
static Resources &get();
};
// ...
class CourierText : public sf::Drawable, public sf::Transformable
{
// ...
public:
sf::Sprite s;
// ...
}
// In .cpp file
s.setTexture(Resources::get().courier, true);
states.blendMode = sf::BlendAlpha;
states.transform *= getTransform();
target.draw(s, states);
The sprite is a white rectangle.