Thanks Josh, the binding part makes a lot of sense, I was wondering how it knew what to grab from where.
I’m not as clear on the gl_MultiTexCoord0 bit. I tried swapping instances of texcoord in my fragment shader with gl_FragColor but that isn’t working out either.
Is using the OpenGl Shader Builder that comes with the graphical developer tools a reasonable one to test things out on if I’m just doing image processing, not lighting/geometry stuff?
I had gotten it non-black at some point, but I broke something somewhere and it’s back to black.
Here are the shaders for anyone who doesn’t have time to download
Frag:
const vec3 LumCoeff = vec3 (0.2125, 0.7154, 0.0721);
varying vec2 texcoord;
uniform sampler2DRect image;
uniform vec3 avgluma;
uniform float saturation;
uniform float contrast;
uniform float brightness;
uniform float alpha;
void main (void)
{
vec3 texColor = texture2DRect(image, texcoord).rgb;
vec3 intensity = vec3 (dot(texColor, LumCoeff));
vec3 color = mix(intensity, texColor, saturation);
color = mix(avgluma, color, contrast);
color *= brightness;
gl_FragColor = vec4 (color, color.g*alpha);
}
Vertex:
varying vec2 texcoord;
void main (void)
{
gl_Position = ftransform();
texcoord = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
}
Other relevant code:
void testApp::setup(){
ofSetLogLevel(OF_LOG_VERBOSE);
ofSetVerticalSync(false);
//ofEnableAlphaBlending();
// ofDisableArbTex();
camWidth=640;
camHeight = 480;
vidGrabber.initGrabber(camWidth, camHeight);
tex1.allocate(camWidth,camHeight,GL_RGB);
shader.load("shaders/brcosa.vert", "shaders/brcosa.frag");
shader.setUniform3f("avgluma", 0.62,0.62,0.62);
shader.setUniform1f("contrast", 1.0);
shader.setUniform1f("brightness", 1.0);
shader.setUniform1f("saturation", 1.0);
shader.setUniform1f("alpha", 1.0);
}
//--------------------------------------------------------------
void testApp::update(){
vidGrabber.grabFrame();
if (vidGrabber.isFrameNew()) {
tex1=vidGrabber.getTextureReference();
}
}
//--------------------------------------------------------------
void testApp::draw(){
ofBackgroundGradient(ofColor::gray, ofColor::black);
shader.begin();
shader.setUniformTexture("image", tex1, 1);
tex1.draw(0,0);
shader.end();
}