@Koji_Kanao wrote:
I’m trying to manipulate frames from webcam but seems my input has issues.
I could pass texture from oF to shader, but the input is flipped and a little bit glitchyAny suggestions are really appreciated.
Also would like to get advice about u_resolution.
I’m writing this, but feel this isn’t a good way.float fw =ofMap(w, 0, w, .0, 1.0); float fh =ofMap(h, 0, h, .0, 1.0); shader.setUniform2f("u_resolution", fw, fh);
My code is the following
ofApp.cpp
//-------------------------------------------------------------- void ofApp::setup(){ w = ofGetWidth(); h = ofGetHeight(); vidGrabber.setDeviceID(0); vidGrabber.initGrabber(w, h); } //-------------------------------------------------------------- void ofApp::update(){ vidGrabber.update(); } //-------------------------------------------------------------- void ofApp::draw(){ shader.load("", "test.frag"); shader.begin(); shader.setUniform1f("u_time", ofGetElapsedTimef()); float fw =ofMap(w, 0, w, .0, 1.0); float fh =ofMap(h, 0, h, .0, 1.0); shader.setUniform2f("u_resolution", fw, fh); shader.setUniformTexture("tex0",vidGrabber.getTexture(),0); ofDrawRectangle(0,0, ofGetWidth(), ofGetHeight()); shader.end(); }
fragment shader
uniform vec2 u_resolution; uniform sampler2DRect tex0; void main(){ vec2 uv=gl_FragCoord.xy/u_resolution.xy; gl_FragColor=texture2DRect(tex0, uv); }
Posts: 7
Participants: 4