So I finally made my wrapper for the use I'll give my openGL backgrounds and I've got an interesting error. When I draw the background alone it's displayed properly (no transformation test yet), but when I draw something with SFML the only thing it's shown is a dark blue mat where the base image should be.
Here's the code of the main function that reproduces the problem:
int main()
{
sf::RenderWindow window(sf::VideoMode(1280, 800, 32), "Bullet Testing", sf::Style::Fullscreen);
sf::Sprite spr;
sf::Time T = sf::seconds(20.f);
sf::Event event;
sf::Clock C;
sf::Image M;
M.loadFromFile("Resources\\Images\\Menus and Others\\PNG\\Stage 1 Screen Cover (Temporary).png");
M.createMaskFromColor(sf::Color::Black);
sf::Texture Tex;
Tex.loadFromImage(M);
spr.setTexture(Tex);
sf::Texture Mask;
Mask.loadFromFile("Resources\\Images\\Misc\\PNG\\Dione Background Pattern.png");
sf::Image Image;
Image.loadFromFile("Resources\\Images\\Misc\\PNG\\Flora Background Pattern.png");
GLBackground B(Mask ,Image);
B.prepareGL();
B.loadBackground();
window.setFramerateLimit(60);
sf::Clock FrameCount;
while (window.isOpen())
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
window.draw(B);
window.draw(spr);
window.display();
while (window.pollEvent(event))
{ if (event.type == sf::Event::Closed || event.key.code == sf::Keyboard::Escape) window.close(); }
}
return 0;
}
The image and texture dependencies are necessary, since the wrapper works around them.
And here's the code for the wrapper functions used:
void GLBackground::draw(sf::RenderTarget& target, sf::RenderStates states) const
{ ///Posiciones fijas por uso.
if(h_Effect) Eff->bind();
glBegin(GL_QUADS);
glTexCoord2f(0.f, 0.f); glVertex2f(68.f, 64.f);
glTexCoord2f(0.f, 1.f); glVertex2f(68.f, 752.f);
glTexCoord2f(1.f, 1.f); glVertex2f(760.f, 752.f);
glTexCoord2f(1.f, 0.f); glVertex2f(760.f, 64.f);
glEnd();
if(h_Effect) Eff->unbind();
}
inline void prepareGL() const
{
glViewport(0, 0, 1280, 800);
glClearColor(0.f, 0.f, 0.f, 0.f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 1280, 800, 0, -100, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
}
inline void loadBackground(bool MaskBlack = false)
{
if(MaskBlack) { Back.createMaskFromColor(sf::Color::Black); }
glGenTextures(index, &index);
glBindTexture(GL_TEXTURE_2D, index);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Back.getSize().x, Back.getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, Back.getPixelsPtr());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
Effect is a polymorphic effect class around sf::Shader, but for this test I am not using it.
The prepareGL and loadBackground are inline because I didn't know whether I would have scope issues with my openGL calls. I have a bunch of transformation functions, but I am not using any yet.
Any help is appreciated once again.
Edit: I made a small change and the background mask is shown now, alongside the dark blue mat, but the spr sprite now doesn't draw. I am not sure if there's something messing SFML contexts that makes it not get drawn. Even when the mask is drawn after the GL stuff it is still below the blue mat thing...