Commit f7590e4a authored by Geequette's avatar Geequette

finalized part 005

parent f8775ad8
......@@ -58,10 +58,11 @@ int main()
// Set origin in the middle of the sprite
sprite.setOrigin(spriteSize.width/2.,spriteSize.height/2.);
// _______________
// ::: Shaders :::
// Check if shaders are available
if (!sf::Shader::isAvailable())
{
......@@ -69,6 +70,7 @@ int main()
return -1;
}
// Load shaders
sf::Shader shader;
if (!shader.loadFromFile("../../shaders/example_001.vert", "../../shaders/example_001.frag"))
{
......@@ -77,26 +79,28 @@ int main()
}
// ___________________________
// ::: Load distortion map :::
sf::Texture distortionMap;
// It is important to set repeated to true to enable scrolling upwards
distortionMap.setRepeated(true);
// Setting smooth to true lets us use small maps even on larger images
distortionMap.setSmooth(true);
if (!distortionMap.loadFromFile("../../img/distortion_map.png"))
{
sf::err() << "Error while loading distortion map" << std::endl;
return -1;
}
// It is important to set repeated to true to enable scrolling upwards
distortionMap.setRepeated(true);
// Setting smooth to true lets us use small maps even on larger images
distortionMap.setSmooth(true);
// Set texture to the shader
shader.setParameter("currentTexture", sf::Shader::CurrentTexture);
shader.setParameter("distortionMapTexture", distortionMap);
// Shader parameters
float distortionFactor = .05f;
float riseFactor = .2f;
......@@ -104,7 +108,6 @@ int main()
// _________________
// ::: Main loop :::
sf::Clock timer;
while (window.isOpen())
{
......@@ -123,7 +126,7 @@ int main()
// If escape is pressed, close the application
case sf::Keyboard::Escape : window.close(); break;
// Process the up, down, left and right keys
// Process the up, down, left and right keys to modify parameters
case sf::Keyboard::Up : distortionFactor *= 2.f; break;
case sf::Keyboard::Down: distortionFactor /= 2.f; break;
case sf::Keyboard::Left: riseFactor *= 2.f; break;
......@@ -132,8 +135,8 @@ int main()
}
}
}
std::cout << distortionFactor << "\t" << riseFactor << std::endl;
// Set shader parameters
shader.setParameter("time", timer.getElapsedTime().asSeconds());
shader.setParameter("distortionFactor", distortionFactor);
shader.setParameter("riseFactor", riseFactor);
......@@ -142,9 +145,8 @@ int main()
// Clear the window and apply grey background
window.clear( sf::Color(127,127,127));
// Rotate and draw the sprite
// Draw the sprite and apply shader
sprite.setPosition(window.getSize().x/2.,window.getSize().y/2.);
//sprite.setRotation( timer.getElapsedTime().asSeconds() / M_PI * 90.f );
window.draw(sprite,&shader);
// Update display and wait for vsync
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment