Well. I am not sure whether is my fragment shader program got error or the pointer of the PBO is wrong.
Here is my shader:
static const char *fragment_source = {
“uniform sampler2DRect texture;”
“void main()”
“{”
//Read texture coordinates
“vec2 texCoord = gl_TexCoord[0].xy;”
//Read value of texture of current pixel
“vec4 color = text2DRect(texture,texCoord.x);”
//Perform pattern matching
“if(color==‘t’)”
“gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0);”
“else if(color==‘r’)”
“gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0);”
“else if(color==‘o’)”
“gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0);”
“else if(color==‘j’)”
“gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0);”
“else if(color==‘a’)”
“gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0);”
“else if(color==‘n’)”
“gl_FragColor = vec4(1.0, 0.0, 0.0, 0.0);”
“else”
“gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);”
“}”
The gl_Fragcolor will output red color in that fragment on the frame buffer right?
When I want to read pixels into PBO from frame buffer. It comes out the segmentation error.
/Read values back/
//Set the target framebuffer to read
glReadBuffer(GL_FRONT);
//Read the packet payload from framebuffer to PBO
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboread);
glReadPixels(0,0,size,noOfpacket,GL_RED,GL_UNSIGNED_BYTE,0);
//checkError(“Readpixel”);
printf("Data after roundtrip:
");//Map the PBO to process its data by CPU
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboread);
ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB,GL_READ_ONLY_ARB);
for (i=0; i<noOfpacket*size; i++) printf("%c",ptr[i]);
printf("
");
glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);
Is it my code got problems? Please correct me as well.