PDA

View Full Version : Segmentation fault while using PBO



SagoO
04-03-2011, 04:58 AM
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_UNSIGNE D_BYTE,0);
//checkError("Readpixel");
printf("Data after roundtrip:\n");

//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("\n\n");

glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);


Is it my code got problems? Please correct me as well.

mhagain
04-03-2011, 06:29 AM
Which point do you get the segfault at? glReadBuffer? glBindBuffer? glReadPixels?

Have you run it in a debugger and checked the values of variables and function pointers? Doing so should clue you in on what's wrong very quickly.

Otherwise can you post your PBO creation code? And where exactly do you call glMapBuffer anyway?

SagoO
04-03-2011, 07:03 AM
Which point do you get the segfault at? glReadBuffer? glBindBuffer? glReadPixels?

Have you run it in a debugger and checked the values of variables and function pointers? Doing so should clue you in on what's wrong very quickly.

Otherwise can you post your PBO creation code? And where exactly do you call glMapBuffer anyway?

I got try use debugger. But I cant solve the debugger problem.



The following system libraries are missing:
/usr/lib/libGL.so.1

Please ask your system administrator to install the missing libraries or create symbolic links from the above paths to the place where the libraries are installed.


It shows me this message when I want to debug my program.

I try to fix it by installing the library using getlibs.



root@goo5257-laptop:~/Desktop# getlibs libGL.so.1
libGL is installed from video drivers, please install or reinstall your video drivers


Ask me to reinstall the driver!!!Sweat ~~~