Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - firefly431

Pages: [1]
1
Graphics / Re: sf::Sprite white rectangle
« on: July 16, 2013, 07:44:06 pm »
https://github.com/SFML/SFML/issues/211
Thanks; it worked.
(I moved the Shader::isAvailable() to just before the main loop)

2
Graphics / Re: sf::Sprite white rectangle
« on: July 16, 2013, 07:06:57 am »
#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
    if (!sf::Shader::isAvailable()) {
        std::cerr << "Shaders are unavailable.\n";
        return 1;
    }
    sf::Image im;
    sf::Texture tex;
    sf::Sprite t;
    im.loadFromFile("out.png");
    tex.loadFromImage(im);
    t.setTexture(tex);
    sf::RenderWindow win(sf::VideoMode(640, 480), "Test Window");
    win.setVerticalSyncEnabled(true);
    while (win.isOpen()) {
        sf::Event ev;
        while (win.pollEvent(ev)) {
            if (ev.type == sf::Event::Closed) {
                win.close();
            }
        }
        win.clear(sf::Color::Red);
        win.draw(t);
        win.display();
    }
    return 0;
}
 

3
Graphics / sf::Sprite white rectangle
« on: July 16, 2013, 01:56:37 am »
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.

Pages: [1]
anything