From 5d9d0ef716cbdd0791e34fdcc9873563da399250 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 23 Apr 2017 16:53:26 +0000 Subject: [PATCH] Set up project --- .gitignore | 4 ++++ Makefile | 47 ++++++++++++++++++++++++++++++++++++++++++++ build/.keep | 0 src/main.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 build/.keep create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9768419 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +build/* +!build/.keep + +gross diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4d0dcb6 --- /dev/null +++ b/Makefile @@ -0,0 +1,47 @@ +CC = g++ -std=c++17 +CFLAGS = -g -O0 -Wall --pedantic +LFLAGS = -lsfml-system -lsfml-network -lsfml-window -lsfml-graphics + +RM = rm -f + +SOURCEFILES = cpp +SRCDIR = src +TMPDIR = build +TARGET = gross +FILES = main + +#SOURCES = $(patsubst %,$(SRCDIR)/%.cpp,$(FILES)) +OBJECTS = $(patsubst %,$(TMPDIR)/%.o,$(FILES)) +DEPS = $(patsubst %,$(TMPDIR)/%.d,$(FILES)) + +.PHONY: clean run remake + +all: $(TARGET) + +# run the target +run: $(TARGET) + ./$< + +# clean up the build directory +clean: + $(RM) $(TARGET) + $(RM) $(OBJECTS) + $(RM) $(DEPS) + +# clean up and make again +remake: clean $(TARGET) + +# link the final target +$(TARGET): $(OBJECTS) + $(CC) $(OBJECTS) $(LFLAGS) -o $@ + +# compiling to .o file +$(TMPDIR)/%.o: $(SRCDIR)/%.$(SOURCEFILES) + $(CC) $(CFLAGS) -c $< -o $@ + +# generating .d dependency files +$(TMPDIR)/%.d: $(SRCDIR)/%.$(SOURCEFILES) + $(CC) $(CFLAGS) -MM $< -MT $(TMPDIR)/$*.o -MF $(TMPDIR)/$*.d + +# using dependency files +-include $(DEPS) diff --git a/build/.keep b/build/.keep new file mode 100644 index 0000000..e69de29 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..ade0610 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,55 @@ +// sample code from http://www.glusoft.com/tuto/SFML-shader-example.php + +#include +#include + +int main() { + const float winW = 800; + const float winH = 600; + + sf::RenderWindow window(sf::VideoMode(winW, winH), "gross"); + window.setMouseCursorVisible(false); // hide the cursor + + // Create a texture and a sprite for the shader + sf::Texture tex; + tex.create(winW, winH); + sf::Sprite spr(tex); + + sf::Shader shader; + shader.loadFromFile("fire.glsl", sf::Shader::Fragment); // load the shader + + if (!shader.isAvailable()) { + std::cout << "The shader is not available\n"; + } + + // Set the resolution parameter (the resoltion is divided to make the fire smaller) + shader.setParameter("resolution", sf::Vector2f(winW / 2, winH / 2)); + + // Use a timer to obtain the time elapsed + sf::Clock clk; + clk.restart(); // start the timer + + while (window.isOpen()) { + // Event handling + sf::Event event; + + while (window.pollEvent(event)) { + // Exit the app when a key is pressed + if (event.type == sf::Event::KeyPressed) + window.close(); + } + + // Set the others parameters who need to be updated every frames + shader.setParameter("time", clk.getElapsedTime().asSeconds()); + + sf::Vector2i mousePos = sf::Mouse::getPosition(window); + shader.setParameter("mouse", sf::Vector2f(mousePos.x, mousePos.y - winH/2)); + + // Draw the sprite with the shader on it + window.clear(); + window.draw(spr, &shader); + window.display(); + } + + return 0; +}