Commit cd9fc04d authored by Geequette's avatar Geequette

Move ressources in the project folder

parent dea7c51f
......@@ -33,7 +33,7 @@ int main()
// Create texture from PNG file
sf::Texture texture;
if (!texture.loadFromFile("../../img/sfml-icon-small.png"))
if (!texture.loadFromFile("../sfml-icon-small.png"))
{
std::cerr << "Error while loading texture" << std::endl;
return -1;
......
......@@ -29,6 +29,9 @@ LIBS += -lsfml-system
# Sources files
SOURCES += main.cpp
DISTFILES += \
sfml-icon-small.png
......@@ -39,7 +39,7 @@ int main()
// Create texture from PNG file
sf::Texture texture;
if (!texture.loadFromFile("../../img/sfml-icon-small.png"))
if (!texture.loadFromFile("../sfml-icon-small.png"))
{
std::cerr << "Error while loading texture" << std::endl;
return -1;
......
......@@ -29,6 +29,9 @@ LIBS += -lsfml-system
# Sources files
SOURCES += main.cpp
DISTFILES += \
sfml-icon-small.png
......@@ -34,9 +34,9 @@ float snoise(vec3 uv, float res)
void main( void ) {
vec2 p = gl_FragCoord.xy / resolution.xy;
p.x = p.x - mouse.x / resolution.x;
p.y = p.y + mouse.y / resolution.y;
vec2 p = gl_FragCoord.xy / resolution.xy*2.;
p.x = p.x - mouse.x / resolution.x*2.;
p.y = p.y + mouse.y / resolution.y*2.;
p.y = p.y - 1.0;
p.x*=resolution.x/resolution.y;
......
......@@ -9,7 +9,8 @@ uniform vec2 resolution;
#define hash(a) fract(sin(a)*12345.0)
#define noise(p) ((old_noise(p, 883.0, 971.0) + old_noise(p + 0.5, 113.0, 157.0)) * 0.5)
float old_noise(vec3 x, float c1, float c2) {
float old_noise(vec3 x, float c1, float c2)
{
vec3 p = floor(x);
vec3 f = fract(x);
f = f*f*(3.0-2.0*f);
......
#ifdef GL_ES
precision mediump float;
#endif
#extension GL_OES_standard_derivatives : enable
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
void main()
{
vec2 uv = gl_FragCoord.xy / resolution.xy;
uv-=.3;
uv*=3.;
vec3 col = vec3(0.1,0.6,0.9);
if (uv.y<cos(0.4*time+uv.x*4.)/1.2) col = vec3(0,.4,0);
if (uv.y<cos(1.2*time+uv.x*8.)/4.) col = vec3(0,.6,0);
if (uv.y<sin(1.4*time+uv.x*6.)/10.) col = vec3(0,8,0);
gl_FragColor = vec4(col,1.0);
}
......@@ -7,58 +7,70 @@
// Example 3 : cells
// Example 4 : fire
// Example 5 : moving circles
//#define SHADER_FILENAME "../../shaders/example_001.frag"
//#define SHADER_FILENAME "../../shaders/example_002.frag"
#define SHADER_FILENAME "../../shaders/example_003.frag"
//#define SHADER_FILENAME "../../shaders/example_004.frag"
//#define SHADER_FILENAME "../../shaders/example_005.frag"
//#define SHADER_FILENAME "../../shaders/example_006.frag"
// Example 6 : smoke
// Example 7 : horizontal scrolling mountains
#define SHADER_FILENAME "../example_001.frag"
//#define SHADER_FILENAME "../example_002.frag"
//#define SHADER_FILENAME "../example_003.frag"
//#define SHADER_FILENAME "../example_004.frag"
//#define SHADER_FILENAME "../example_005.frag"
//#define SHADER_FILENAME "../example_006.frag"
//#define SHADER_FILENAME "../example_007.frag"
int main() {
const float winW = 800;
const float winH = 600;
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
sf::RenderWindow window(sf::VideoMode(winW, winH), "SFML Shader Example");
int main()
{
// Create a texture and a sprite for the shader
// Create a non resizable window
sf::RenderWindow window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "SFML Shader Example", sf::Style::Titlebar | sf::Style::Close);
// Create a window size texture and a sprite for the shader
sf::Texture tex;
tex.create(winW, winH);
tex.create(WINDOW_WIDTH, WINDOW_HEIGHT);
sf::Sprite spr(tex);
sf::Shader shader;
shader.loadFromFile(SHADER_FILENAME, sf::Shader::Fragment); // load the shader
// Create an load the shader from file
sf::Shader shader;
shader.loadFromFile(SHADER_FILENAME, sf::Shader::Fragment);
if (!shader.isAvailable()) {
std::cout << "The shader is not available\n";
return -1;
}
// Set the resolution parameter (the resoltion is divided to make the fire smaller)
shader.setParameter("resolution", sf::Vector2f(winW , winH));
// Set the resolution parameter (initial window size)
shader.setParameter("resolution", sf::Vector2f(WINDOW_WIDTH , WINDOW_HEIGHT));
// Use a timer to obtain the time elapsed
sf::Clock clk;
clk.restart(); // start the timer
// Main loop
while (window.isOpen()) {
// Event handling
sf::Event event;
while (window.pollEvent(event)) {
// Event loop (keyboard, mouse ...
while (window.pollEvent(event))
{
// Close the window if a key is pressed or if requested
if (event.type == sf::Event::Closed) window.close();
// Exit the app when a key is pressed
if (event.type == sf::Event::KeyPressed)
window.close();
if (event.type == sf::Event::KeyPressed) window.close();
}
// Set the others parameters who need to be updated every frames
// Set the others parameters who need to be updated every frames (time and mouse)
shader.setParameter("time", clk.getElapsedTime().asSeconds());
sf::Vector2i mousePos = sf::Mouse::getPosition(window);
shader.setParameter("mouse", sf::Vector2f(mousePos.x, mousePos.y - winH/2));
shader.setParameter("mouse", sf::Vector2f(mousePos.x, mousePos.y - WINDOW_HEIGHT/2));
// Draw the sprite with the shader on it
window.clear();
......
......@@ -34,7 +34,13 @@ DISTFILES += ../shaders/example_001.frag \
../shaders/example_003.frag \
../shaders/example_004.frag \
../shaders/example_005.frag \
../shaders/example_006.frag
example_001.frag \
example_002.frag \
example_003.frag \
example_004.frag \
example_005.frag \
example_006.frag \
example_007.frag
DISTFILES +=
......
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