Here is my fragment:
static const char *fragment_source = {
// texture global variable, set by application
"uniform sampler2DRect texture;"
"void main(void)"
"{"
//Read texture coordinates
"vec2 texCoord = gl_TexCoord[0].xy;"
//Read value of texture of current pixel
"vec4 value = texture2DRect(texture,texCoord);"
//Perform pattern matching
"if(value[0]==116){"
//Set the pixel to maximum value
"gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);}"
"else if(value[0]==114){"
"gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);}"
"else if(value[0]==111){"
"gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);}"
"else if(value[0]==106){"
"gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);}"
"else if(value[0]==97){"
"gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);}"
"else if(value[0]==110){"
"gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);}"
"else{"
//Set the pixel to zero
"gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);}"
"}"
};
My output should be have some values. But it always zeros when I read it out. I using the following method to read:
/*Read values back*/
/*Set the target framebuffer to read*/
glReadBuffer(GL_FRONT);
/*Read pixels from framebuffer to PBO*/ glReadPixels(0,0,size,noOfpacket,GL_RGBA,GL_UNSIGNED_BYTE,(void*)0);
checkError("glReadPixels error!");
/*Map the PBO to process its data by CPU*/
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboread);
result = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB,GL_READ_ONLY_ARB);
printf("Data in frame buffer:
");
for (i=0;i<noOfpacket*size;i++)
printf("%d",result[i]);
printf("
");
glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB,0);
I am not sure where is the problem. So, I test my fragment.I change to this:
"void main(void){"
"gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);"
"}"
Or
"void main(void){"
"gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);"
"}"
Unfortunately, I still get zeros. Where is problem actually?