GLX-PBuffer for rendering to texture problem

Hi

I want to use a p-buffer for creating a dynamic texture, but all i get is a black window. I am setting up the pbuffer like this:

  
				Display* pbuff_display = glXGetCurrentDisplay();
				
				int errorBase, eventBase, major, minor;
				
				if (glXQueryExtension(pbuff_display, &errorBase, &eventBase)) {
					bool glxqv;
					glxqv = glXQueryVersion(pbuff_display, &major, &minor);
					std::cout<<"GLX-Version: "<<major<<"."<<minor<<std::endl;
					std::cout<<"GLX-ErrorBase: "<<errorBase<<" EventBase: "<<eventBase<<std::endl;
				}

				int pbuff_screen = DefaultScreen(pbuff_display);
				
				int pbuff_WishAttributeList[] = {
					GLX_RENDER_TYPE, GLX_RGBA_BIT,
					GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
					GLX_DOUBLEBUFFER, GL_FALSE,
					GLX_X_RENDERABLE, GL_TRUE,
					GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
					GLX_RED_SIZE, 8,
					GLX_GREEN_SIZE, 8,
					GLX_BLUE_SIZE, 8,
					GLX_ALPHA_SIZE, 8,
					0 };

				int nFBConfigElements;

				GLXFBConfig* glxXChooseFBConfig_array = 
					glXChooseFBConfig(	pbuff_display,
										pbuff_screen,
										pbuff_WishAttributeList,
										&nFBConfigElements);
				std::cout<<"Number of matching FB-Configs: "<<nFBConfigElements<<std::endl;

				
				GLXContext pbuff_context = glXCreateNewContext(
					pbuff_display,
					glxXChooseFBConfig_array[0],
					GLX_RGBA_TYPE,
					0,
					GL_TRUE);

						
				int pbuff_AttributeList[] = {
					GLX_PBUFFER_WIDTH, ib,
					GLX_PBUFFER_HEIGHT, ih,
//					GLX_PRESERVED_CONTENTS, GL_TRUE,
					0};


				GLXPbuffer pbuff_pbuffer = glXCreatePbuffer(
					pbuff_display,
					glxXChooseFBConfig_array[0],
					pbuff_AttributeList);

					
				bool bind_success = glXMakeContextCurrent(
					pbuff_display,
					pbuff_pbuffer,
					pbuff_pbuffer,
					pbuff_context);

				if (bind_success) {
					std::cout<<"Bound PBuffer!"<<std::endl;
				} else {
					std::cout<<"Bound PBuffer not possible!"<<std::endl;
				}

and get for output:
GLX-Version: 1.3
GLX-ErrorBase: 152 EventBase: 70
Number of matching FB-Configs: 3
Bound PBuffer!

after that i render my scene using a display-list that was generated before. then i want to grab the texture:

GLuint render_texture;
glGenTextures (1, &render_texture);
glBindTexture(GL_TEXTURE_2D, render_texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA8, GL_UNSIGNED_BYTE, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 512, 512);
 

now i destroy the pbuffer-stuff and render a quad with the texture applied to it:

 
			glXDestroyPbuffer(pbuff_display, pbuff_pbuffer);
			glXDestroyContext(pbuff_display, pbuff_context);
			glDisable(GL_LIGHTING);
			glDrawBuffer(GL_BACK);
			lClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			glEnable(GL_DEPTH_TEST);
			glDepthMask(GL_TRUE);
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
			glBegin(GL_QUADS);
				glTexCoord2f(0,0);
				glVertex3f(-10, -10, 0);
				glTexCoord2f(1,0);
				glVertex3f(+10, -10, 0);
				glTexCoord2f(1,1);
				glVertex3f(+10, +10, 0);
				glTexCoord2f(0,1);
				glVertex3f(-10, +10, 0);
			glEnd();

 

then comes a buffer-switch. but everything i get is a black window.

What am i doing wrong?

Two things you might try:
When you create the pbuffer with glXCreateNewContext set the share_list parameter to the GLXContext of your rendering (drawing/non-pbuffer) context so textures are shared - once shared textures and display lists are not destroyed until all shared contexts are destroyed or the textures/display lists are deleted by any one of the shared contexts regardless of which context created the display list or texture.

Second, you might also try making your rendering context current after destroying your pbuffer - not sure if there is any guarantee the previous context is automatically made current - it might work on yours but the behaviour may be undefined on other systems/hardware.

Hi

thanks, i tried your sugestions like this:
before p-buffer init:

				Display* pbuff_display = glXGetCurrentDisplay();
				GLXContext pbuff_oldcontext = glXGetCurrentContext();
				GLXDrawable pbuff_olddrawable = glXGetCurrentDrawable();

and after destroying the pbuffer:

			glXMakeCurrent(pbuff_display, pbuff_olddrawable, pbuff_oldcontext);

now i get a texture and see my quad, but it looks very strange. i took some screenshots from the objekt:

screenshots

if you know where to look at, you can recognize a part of the object :wink: .
I think its a wrong parameter anywhere, but where?

EDIT
Sorry - just realized I was answering jonkje84’s question… the same does apply to you though as written below in items 1 & 2.
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.

Thanks a lot.

Querying the old context and setting FBConfig to the same values did the trick (2)

hillar

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