Test compare shader (not working D:)
This commit is contained in:
parent
4953051965
commit
74051fe676
2 changed files with 89 additions and 0 deletions
19
compare.glsl
Normal file
19
compare.glsl
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
// Compute the pixelwise diff between two textures.
|
||||||
|
// Computes the diff for each color chanel separately (r, g, b).
|
||||||
|
// Assumes both images are not transparent.
|
||||||
|
|
||||||
|
// try isampler2D, ivec4 etc.? Probably not
|
||||||
|
uniform vec2 size;
|
||||||
|
uniform sampler2D base;
|
||||||
|
uniform sampler2D curr;
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
vec2 pos = gl_FragCoord.xy/size;
|
||||||
|
// vec4 color = texture(curr, pos); // fails for some reason!?
|
||||||
|
// vec4 basecolor = texture(base, pos); // fails too...
|
||||||
|
// color.xyz = abs(color.xyz - basecolor.xyz);
|
||||||
|
// gl_FragColor = color;
|
||||||
|
// gl_FragColor = basecolor;
|
||||||
|
gl_FragColor = vec4(1.0);
|
||||||
|
}
|
||||||
70
src/main.cpp
70
src/main.cpp
|
|
@ -42,6 +42,75 @@
|
||||||
* - invisible?
|
* - invisible?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
const float winW = 480;
|
||||||
|
const float winH = 480;
|
||||||
|
|
||||||
|
sf::RenderWindow window(sf::VideoMode(winW, winH), "gross");
|
||||||
|
window.setMouseCursorVisible(false); // hide the cursor
|
||||||
|
|
||||||
|
// load images
|
||||||
|
sf::Texture base;
|
||||||
|
sf::Texture comp;
|
||||||
|
base.loadFromFile("tom-face.png");
|
||||||
|
comp.loadFromFile("tom-face-christmas.png");
|
||||||
|
sf::Sprite sprbase(base);
|
||||||
|
sf::Sprite sprcomp(comp);
|
||||||
|
|
||||||
|
sf::Shader compshdr;
|
||||||
|
compshdr.loadFromFile("compare.glsl", sf::Shader::Fragment);
|
||||||
|
|
||||||
|
if (!compshdr.isAvailable()) {
|
||||||
|
std::cout << "The shader is not available\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
compshdr.setUniform("base", base);
|
||||||
|
compshdr.setUniform("curr", comp);
|
||||||
|
compshdr.setUniform("size", 240, 240);
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
|
||||||
|
// Draw the sprites, one with the shader on it
|
||||||
|
window.clear();
|
||||||
|
|
||||||
|
window.draw(sprbase);
|
||||||
|
|
||||||
|
sprcomp.setPosition(240, 0);
|
||||||
|
window.draw(sprcomp);
|
||||||
|
|
||||||
|
sprcomp.setPosition(0, 240);
|
||||||
|
window.draw(sprcomp, &compshdr);
|
||||||
|
|
||||||
|
window.display();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// old main - keep for testing purposes
|
||||||
|
/*
|
||||||
int main() {
|
int main() {
|
||||||
const float winW = 800;
|
const float winW = 800;
|
||||||
const float winH = 600;
|
const float winH = 600;
|
||||||
|
|
@ -92,3 +161,4 @@ int main() {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue