Hi,
I have a texture in texture memory. I want to pass the texture into the fragment shader and read the texture value in the fragment. Then, sample to the frame buffer and set the color of the pixel.
I have done the code but not sure whether it correct or not.
static const char *fragment_source = {
// texture global variable, set by application
"uniform sampler2DRect texture;"
"void main()"
"{"
//Read texture coordinates
"vec2 texCoord = gl_TexCoord[0].xy;"
//Read value of texture of current pixel
"vec4 original_value = texture2DRect(texture,texCoord);"
//Perform pattern matching
"if(original_value[0]=='t'){"
//Sampling The Texture And Passing It To The Frame Buffer
"gl_FragColor = texture2DRect(texture,texCoord);"
//Set the particular pixel to Red color
"gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);}"
"else if(original_value[0]=='r'){"
"gl_FragColor = texture2DRect(texture,texCoord);"
"gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);}"
"else if(original_value[0]=='o'){"
"gl_FragColor = texture2DRect(texture,texCoord);"
"gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);}"
"else if(original_value[0]=='j'){"
"gl_FragColor = texture2DRect(texture,texCoord);"
"gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);}"
"else if(original_value[0]=='a'){"
"gl_FragColor = texture2DRect(texture,texCoord);"
"gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);}"
"else if(original_value[0]=='n'){"
"gl_FragColor = texture2DRect(texture,texCoord);"
"gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);}"
"else{"
"gl_FragColor = texture2DRect(texture,texCoord);"
"gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);}"
"}"
};
My texture data is in bytes. And each coordinates only have one value. I use GL_LUMINANCE format for the texture. I hope that I can read the red/white color out only from the frame buffer if it success.
According to rgba format,
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); → red
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); → black
Is it correct? Please correct me if I m wrong. Thank for every one helps.