Simple Shader programming with image

Hi ! I’m currently trying to use shaders to modify my 2d images for simple stuff, mainly things like in the tutorials, and I want to implement them in my project.

The thing is, I can’t use GLSL version 150 because some of our existing shaders are using another version and it’s not compatible, I was just wondering if it’s possible to just apply a ahder to an ofImage or something.

I’ve tried so far but it doesn’t seem like the shader is understanding that the texture it has is an image, it just draws colors depending on the ofSetColor.

Here’s some code, and the fragment and vertex shaders I’m using are kinda basic (dummy code I got, dunno if it works)

Fragment shader :

uniform sampler2DRect texture0;

void main()
{
//Getting coordinates of the current pixel in texture
vec2 pos = gl_TexCoord[0].xy;

//Getting the pixel color from the texture texture0 in pos
vec4 color = texture2DRect(texture0, pos);

//Output the color of shader
gl_FragColor = color;
}

Vertex shader :

void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_FrontColor = gl_Color;
}

ofApp.cpp :

void ofApp::setup()
{
ofDisableArbTex();
ofEnableDepthTest();

m_shader.load("shaders/shaderTest");
m_image.loadImage("sunflower.png");
}

void ofApp::draw()
{
ofTexture l_text = m_image.getTextureReference();

m_shader.begin();
m_image.draw(0, 0);
m_shader.end();
}

So basically what I want to know is how to “pass my image” unto the shader so I can change simple things like it’s color, and maybe do some basic distortion effects.

Also, I’m going to use these in a 3D project world (some sandbox).

Any tips on how to get started and maybe help me understand a bit more what I’m doing wrong would help !

Thanks !

You need to pass the image’s associated texture into the shader as a uniform. So, take your variable l_text and right after the shader begin() call m_shader.setUniform(“texture0”, l_text, 0)… Inside your fragment shader, the variable at the top (uniform sampler2DRect) will then hold a reference to your image’s texture.

The shader’s you linked are just pass-through shaders… they aren’t doing anything to image.

Okay, I can do that ! However, I’m still having a problem with using the uniform sampler afterwards… I can’t seem to get the correct coordinates for my texture ? Like how do I get the current pixel and such, if I’m working in a 3D world ? Right now I can’t get the correct color apparently from the texture with the texture2DRect, I think the pos might be wrong or something.

I’m working in a FBO, that I’m drawing in a 3D sandbox world… I think it’s just not getting the right pixel or something.

Any ideas ?

Additional note : right now it’s compiling as and as suggested I am passing the uniform variable to my texture0, but I’m still getting only a black square… It’s not showing the image.