Skip to content

Instantly share code, notes, and snippets.

@osiloke
Created August 5, 2014 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osiloke/51656645fefc051959cf to your computer and use it in GitHub Desktop.
Save osiloke/51656645fefc051959cf to your computer and use it in GitHub Desktop.
Trying to figure out why i can't do something
#include "testApp.h"
#define STRINGIFY(A) "#define QUALITY 32 \n uniform float progress; \n uniform vec2 resolution; \n uniform float time; \n uniform sampler2DRect first; \n uniform sampler2DRect second; \n" #A
float width, height;
//--------------------------------------------------------------
void testApp::setup(){
string shaderProgram = STRINGIFY(
void main (void){
vec2 pos = gl_FragCoord.xy;
vec4 src = texture2DRect(second, pos);
gl_FragColor = src;
}
);
string windTransition = STRINGIFY(
// Custom parameters
uniform float size = 0.2f;
float rand (vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
void main() {
vec2 pos = gl_FragCoord.xy;
float r = rand(vec2(0, pos.y));
float m = smoothstep(0.0, -size, pos.x*(1.0-size) + size*r - (progress * (1.0 + size)));
gl_FragColor = mix(texture2DRect(first, pos), texture2DRect(second, pos), m);
}
);
string blur2Transition = STRINGIFY(
void main() {
vec2 p = gl_FragCoord.xy ;
gl_FragColor = mix(texture2DRect(first, p), texture2DRect(second, p), progress);
}
);
shader.setupShaderFromSource(GL_FRAGMENT_SHADER, wipeTransition);
shader.linkProgram();
width = ofGetWidth();
height = ofGetHeight();
first.loadImage("images/girl1.jpg");
second.loadImage("images/girl2.jpg");
fbo.allocate(width, height);
firstFbo.allocate(width, height);
secondFbo.allocate(width, height);
firstFbo.begin();
ofClear(0,0,0,255);
firstFbo.end();
secondFbo.begin();
ofClear(0,0,0,255);
secondFbo.end();
}
//--------------------------------------------------------------
void testApp::update(){
firstFbo.begin();
first.draw(0, 0, width, height);
firstFbo.end();
secondFbo.begin();
second.draw(0, 0, width, height);
secondFbo.end();
fbo.begin();
ofClear(0, 0, 0, 0);
shader.begin();
float resolution[] = {(float)width, (float)height};
float direction[] = {(1.0f, 0.0f)};
float time = ofGetElapsedTimef();
shader.setUniform1f("time",time);
shader.setUniform2fv("resolution",resolution);
float progress = ofMap(mouseX, 0, width, 0, 1, true);
shader.setUniform1f("progress", progress);
shader.setUniform2fv("direction", direction);
shader.setUniformTexture("first", firstFbo.getTextureReference(), 0);
shader.setUniformTexture("second", secondFbo.getTextureReference(), 1);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(width, 0); glVertex3f(width, 0, 0);
glTexCoord2f(width, height); glVertex3f(width, height, 0);
glTexCoord2f(0,height); glVertex3f(0,height, 0);
glEnd();
shader.end();
fbo.end();
}
//--------------------------------------------------------------
void testApp::draw(){
fbo.draw(0, 0, width, height);
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment