GLX Pbuffer and glCopyTexImage2D troubles

Hi, I’m having some weird troubles with my pbuffer. I’m successfully creating it, but trying to get the contents from it using glCopyTexImage2D results in either a black texture, no texture (white) or a black with some noise.

There’s more information in this thread in the OpenGL advanced forum. I was adviced to move the thread here for better help.

In that thread there’s also a link to a tarball with my troublesome code.

Some weird things:

  • Using the same code to render to the back buffer, then copy the texture from the back buffer works.
  • Querying the pbuffer for its width and height seems to destroy it. It returns 0!! and the texture goes white. Not querying it gives a black texture.
  • The texture should be red with a teapot.
  • The sample is all black, if you modify glClearColor in foopbuffer.cpp in the display function. You’ll see that there actually is a black quad spinning.
  • I found some code doing what I want in another thread which works, but I’m unable to tell the difference with my code. That code’s located here . It also uses glut and well … why does that work, and not mine??

Any help will be deeply appreciated. My frustration over not getting this to work has stalled all other work the last couple of days.

I don’t want to whine, but won’t anyone try to help me?

I’m completely unable to see what I’m doing different from the other bloke. (See link in sibling thread.)

Sincerely, desperate programmer.

do you use the nvidia driver? I have a simular problem. Its IMHO a bug so I waiting for FBO’s.

Yes, I’m using nVidia drivers, but the other program (mentioned in the sibling thread) works, and it does exactly what I’m doing. (Well obviusly not exactly.) So I can’t really see how it could be a driver issue.

But, thank you for replying.

EDIT
I was actually trying to answer hillar’s similar question and ended up downloading your code and finding the issues - see below
*EDIT

I ended up downloading and looking at your code.

  1. Create the pbuffer but use the original context. You still need to make the pbuffer current using glXMakeCurrent.

glXMakeCurrent( display, window, context );
and
glXMakeCurrent( display, pbuffer, context );
to switch between them.

  1. When you set the FBConfig for the pbuffer do something like:
bool PBuffer::setfbconfig()
{
  int fbconfigindex = 0;
  int query = 0;
  if( query = glXQueryContext( display, context_saved,
        GLX_FBCONFIG_ID, &fbconfigindex ) )
  {
    printf( "ERROR: Could not query FBConfig - query: %d   index: %d
",
            query, fbconfigindex );
    exit(-1);
  }
  // This is a crude list. It may not be the best, but it works.
  int attribute_list[] = {
    GLX_FBCONFIG_ID, fbconfigindex,
    None
  };

  int screen = XDefaultScreen(display);
  int tmp = 0;
  GLXFBConfig* config;
  if((config = glXChooseFBConfig(display, screen, attribute_list, &tmp)) == NULL)
    return 0;
  printf( "FBConfigs: %d
", tmp );
  fbconfig = config[0];
  XFree(config);
  return 1;
}
  1. Your buf_attribs in mk_pbuffer method should contain GLX_PBUFFER_WIDTH and GLX_PBUFFER_HEIGHT not GLX_MAX_PBUFFER_WIDTH…

  2. I think I remember seeing 2 save_context calls and one was after the glXMakeCurrent which would cause an overwrite of the saved drawable with the pbuffer drawable and thereby you would be unable to switch back - you would probably catch that but figured I’d mention it.

I think that was the extent of the issues I found. Sorry for the previous erroneous message about creating second context specifically for the pbuffer - completely wrong. Also, any context with the same FBConfig as a pbuffer can render into that pbuffer but it must have the same FBConfig to use it correctly.

Thank you, thank you, thank you, thank you. I’d almost given up. You nailed it with number 3. (The others weren’t really any problems. 4 is because there might be a switch from another context than the one the pbuffer was created in. I then want to return to that context.)

Again, thank you, you just made my life much better.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.