I couldn't run your code at all, since you're using global initialize SFML resources, which isn't allowed and instantly crashes most of the time. I would highly recommend to stay away from global variables in general, whether initialized at global scope or not, they break scoping and make it hard or impossible to reason about the application flow.
So I changed your code around and also replaced boost::thread with std::thread.
Now the code works "fine" on my machine, i.e. no flickers. However since you're using OpenGL from two different threads (yes, loading a shader
already does OpenGL calls), you will have to deal with proper context activation, I suggest reading the whole OpenGL tutorial, but especially the part about threading:
https://www.sfml-dev.org/tutorials/2.5/window-opengl.php#rendering-from-threadsModified code:
#include <SFML/Graphics.hpp>
#include <thread>
#include <iostream>
std::thread* loadingThread;
sf::RenderWindow* window;
sf::RenderTexture *preScreenTex;
sf::Shader* speedBarShader;
void Load()
{
sleep(sf::seconds(2));
if (!speedBarShader->loadFromFile("speedbar_shader.frag", sf::Shader::Fragment))
{
std::cout << "speed bar SHADER NOT LOADING CORRECTLY\n";
}
while (true);
}
int main()
{
window = new sf::RenderWindow(sf::VideoMode(1920, 1080), "Breakneck", sf::Style::Fullscreen);
window->setVerticalSyncEnabled(true);
preScreenTex = new sf::RenderTexture;
preScreenTex->create(1920, 1080);
preScreenTex->clear();
speedBarShader = new sf::Shader();
int frame = 0;
bool quit = false;
sf::Event ev;
loadingThread = NULL;
while (!quit)
{
while (window->pollEvent(ev))
{
}
preScreenTex->clear(sf::Color::Black);
window->clear(sf::Color::Red);
if (loadingThread != NULL)
{
preScreenTex->clear(sf::Color::Green);
}
if (frame == 60 * 3)
{
loadingThread = new std::thread(&Load);
}
preScreenTex->display();
sf::Sprite spr;
spr.setTexture(preScreenTex->getTexture());
window->draw(spr);
window->display();
++frame;
}
}