forked from patriciogonzalezvivo/thebookofshaders
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request patriciogonzalezvivo#354 from eXpl0it3r/feature/sf…
…ml-framework Add SFML to the framework list
- Loading branch information
Showing
13 changed files
with
88 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
|
||
project(TheBookOfShaders LANGUAGES CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
find_package(SFML 2.5 COMPONENTS graphics REQUIRED) | ||
|
||
add_executable(TheBookOfShaders | ||
src/main.cpp | ||
) | ||
|
||
target_link_libraries(TheBookOfShaders sfml-graphics) | ||
|
||
install(TARGETS TheBookOfShaders | ||
RUNTIME DESTINATION .) | ||
install(DIRECTORY data | ||
DESTINATION .) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifdef GL_ES | ||
precision mediump float; | ||
#endif | ||
|
||
uniform vec2 u_resolution; | ||
uniform vec3 u_mouse; | ||
uniform float u_time; | ||
|
||
void main() { | ||
vec2 st = gl_FragCoord.st/u_resolution; | ||
gl_FragColor = vec4(st.x,st.y,0.0,1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <SFML/Graphics.hpp> | ||
|
||
#include <iostream> | ||
|
||
int main() | ||
{ | ||
auto window = sf::RenderWindow{ { 800U, 800U }, "The Book of Shaders" }; | ||
window.setFramerateLimit(144); | ||
|
||
auto clock = sf::Clock{}; | ||
|
||
auto shape = sf::RectangleShape{ sf::Vector2f{ window.getSize() } }; | ||
|
||
auto shader = sf::Shader{}; | ||
if (!shader.loadFromFile("data/shader.frag", sf::Shader::Fragment)) | ||
{ | ||
std::cerr << "Couldn't load fragment shader\n"; | ||
return -1; | ||
} | ||
|
||
auto mouse_position = sf::Vector2f{}; | ||
|
||
while (window.isOpen()) | ||
{ | ||
for (auto event = sf::Event{}; window.pollEvent(event);) | ||
{ | ||
if (event.type == sf::Event::Closed) | ||
{ | ||
window.close(); | ||
} | ||
else if (event.type == sf::Event::MouseMoved) | ||
{ | ||
mouse_position = window.mapPixelToCoords({ event.mouseMove.x, event.mouseMove.y }); | ||
} | ||
} | ||
|
||
shader.setUniform("u_resolution", sf::Glsl::Vec2{ window.getSize() }); | ||
shader.setUniform("u_mouse", sf::Glsl::Vec2{ mouse_position }); | ||
shader.setUniform("u_time", clock.getElapsedTime().asSeconds()); | ||
|
||
window.clear(); | ||
window.draw(shape, &shader); | ||
window.display(); | ||
} | ||
} |