Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Having trouble feeding syphon into shader

$
0
0

@vibber wrote:

Hi there,
I am trying to add a filter to a syphon source, but I am having problems getting a syphon texture into the shader. I tried with an ofTexture and the shader worked, so there is something about the syphon texture that fails but I can't figure out what exactly. I get a black screen in syphon simple client.

My simple app looks like this:

#ifndef _TEST_APP
#define _TEST_APP


#include "ofMain.h"
#include "ofxSyphon.h"

class ofApp : public ofBaseApp{

public:

	void setup();
	void update();
	void draw();


	ofxSyphonServer syphonServer;
	ofxSyphonClient mClient;
    ofShader shadertoy;
    ofFbo framebuffer;

};

#endif

ofApp.cpp

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){

    //shader stuff

    ofDisableArbTex();
    shadertoy.load("shader/shadertoy");

    //Syphon stuff

    ofSetWindowTitle("ofxSyphon Example");
	syphonServer.setName("Texture Output");
	mClient.setup();
    //using Syphon app Simple Server, found at http://syphon.v002.info/
    mClient.set("","Simple Server");

	ofSetFrameRate(60);

    //FBO stuff
    framebuffer.allocate(400,400, GL_RGBA);

    framebuffer.begin();
    ofClear(255,255,255, 0);
    framebuffer.end();
}

//--------------------------------------------------------------
void ofApp::update(){

}

//--------------------------------------------------------------
void ofApp::draw(){
    framebuffer.begin();

    shadertoy.begin();

    mClient.bind();

    shadertoy.setUniform3f("iResolution", ofGetWidth(), ofGetHeight(), 0.0);
    shadertoy.setUniformTexture("iChannel0", mClient.getTexture(), 1);
    ofDrawRectangle(0, 0, 400, 400);

    mClient.unbind();

    shadertoy.end();

    framebuffer.end();

    syphonServer.publishTexture(&framebuffer.getTexture(0));
}

Shader code

#version 120

// ---> Shadertoy uniforms
uniform vec3 iResolution;
uniform sampler2D iChannel0; // Texture #1


void main( void )
{
 	vec2 uv = gl_FragCoord.xy / iResolution.xy;

    vec3 col = texture2D(iChannel0, uv).rgb;

	gl_FragColor = vec4(col, 1.0);
}

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles