Set up project

This commit is contained in:
Joscha 2017-04-23 16:53:26 +00:00
commit 5d9d0ef716
4 changed files with 106 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
build/*
!build/.keep
gross

47
Makefile Normal file
View file

@ -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)

0
build/.keep Normal file
View file

55
src/main.cpp Normal file
View file

@ -0,0 +1,55 @@
// sample code from http://www.glusoft.com/tuto/SFML-shader-example.php
#include <SFML/Graphics.hpp>
#include <iostream>
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;
}