Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / wgl & pbuffers & fltk Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Kruzty

May 02, 2005, 12:54 PM

I am trying to create an off-screen pbuffer to render to and use as a texture using the wgl openGL extensions in windows (obviously).

I'm also using fltk (www.fltk.org) for my gui and I am rendering in an fltk openGL window

Is there any reason this shouldn't work right with a fltk openGL window? I'm doing things as described in: www.ati.com/developer/ATIpbuffer.pdf and it seems to work until I try to call wglCreatePbufferARB(). This function fails (returns a NULL pointer) unless the attribute list (the last argument) I pass it has no entries (just a 0 to terminate).

Has anyone else tried to do this? Is there something else I need to do to make this work with fltk? My code is posted below in case someone is willing to take a peek and see if anything is wrong...

This is the constructor for my pbuffer class, I think it should be understandable without seeing the rest of my code...




  1.  
  2.  
  3. PBuffer::PBuffer( int widthIn, int heightIn ) : initOK( false ), w( widthIn ), h( heightIn ),
  4.                                                     hGLDC( NULL ), hGLRC( NULL ), pbufferTextureID( 0 )
  5. {
  6.     PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
  7.     if( wglGetExtensionsStringARB )
  8.     {
  9.         GLubyte *extensionString = (GLubyte *)wglGetExtensionsStringARB(wglGetCurrentDC());
  10.         printf( "Available extentions: %sn", extensionString );
  11.     }
  12.     else
  13.     {
  14.         printf("Failed to get stringn");
  15.         return;
  16.     }
  17.  
  18.     // initialize extension entry points
  19.     wglMakeContextCurrentARB = (PFNWGLMAKECONTEXTCURRENTARBPROC)wglGetProcAddress("wglMakeContextCurrentARB");
  20.     wglChoosePixelFormatARB  = (PFNWGLCHOOSEPIXELFORMATARBPROC) wglGetProcAddress("wglChoosePixelFormatARB");
  21.     wglCreatePbufferARB      = (PFNWGLCREATEPBUFFERARBPROC)     wglGetProcAddress("wglCreatePbufferARB");
  22.     wglDestroyPbufferARB     = (PFNWGLDESTROYPBUFFERARBPROC)    wglGetProcAddress("wglDestroyPbufferARB");
  23.     wglGetPbufferDCARB       = (PFNWGLGETPBUFFERDCARBPROC)      wglGetProcAddress("wglGetPbufferDCARB");
  24.     wglReleasePbufferDCARB   = (PFNWGLRELEASEPBUFFERDCARBPROC)  wglGetProcAddress("wglReleasePbufferDCARB");
  25.     wglQueryPbufferARB       = (PFNWGLQUERYPBUFFERARBPROC)      wglGetProcAddress("wglQueryPbufferARB");
  26.     wglBindTexImageARB       = (PFNWGLBINDTEXIMAGEARBPROC)      wglGetProcAddress("wglBindTexImageARB");
  27.     wglReleaseTexImageARB    = (PFNWGLRELEASETEXIMAGEARBPROC)   wglGetProcAddress("wglReleaseTexImageARB");
  28.     wglSetPbufferAttribARB   = (PFNWGLSETPBUFFERATTRIBARBPROC)  wglGetProcAddress("wglSetPbufferAttribARB");
  29.  
  30.     // do some error checking to make sure function pointers were initialized correctly
  31.     if (wglMakeContextCurrentARB == NULL)
  32.     {
  33.         printf ("Can't init wglMakeContextCurrentARB");
  34.         return;
  35.     }
  36.     if (wglChoosePixelFormatARB == NULL)
  37.     {
  38.         printf ("Can't init wglChoosePixelFormatARB");
  39.         return;
  40.     }
  41.     if (wglCreatePbufferARB == NULL)
  42.     {
  43.         printf ("Can't init wglCreatePbufferARB");
  44.         return;
  45.     }
  46.     if (wglDestroyPbufferARB == NULL)
  47.     {
  48.         printf ("Can't init wglDestroyPbufferARB");
  49.  
  50.         return;
  51.     }
  52.     if (wglGetPbufferDCARB == NULL)
  53.     {
  54.         printf ("Can't init wglGetPbufferDCARB");
  55.         return;
  56.     }
  57.     if (wglReleasePbufferDCARB == NULL)
  58.     {
  59.         printf ("Can't init wglReleasePbufferDCARB");
  60.         return;
  61.     }
  62.     if (wglQueryPbufferARB == NULL)
  63.     {
  64.         printf ("Can't init wglQueryPbufferARB");
  65.         return;
  66.     }
  67.     if (wglBindTexImageARB == NULL)
  68.     {
  69.         printf ("Can't init wglBindTexImageATIX");
  70.         return;
  71.     }
  72.     if (wglReleaseTexImageARB == NULL)
  73.     {
  74.         printf ("Can't init wglReleaseTexImageATIX");
  75.         return;
  76.     }
  77.     if (wglSetPbufferAttribARB == NULL)
  78.     {
  79.         printf ("Can't init wglSetPbufferAttribATIX");
  80.         return;
  81.     }
  82.  
  83.     // get the current opengl device and render context
  84.     hGLDC = wglGetCurrentDC();
  85.     hGLRC = wglGetCurrentContext();
  86.     if (hGLDC == NULL)
  87.     {
  88.         printf("Error: unable to get GL Device Context");
  89.         return;
  90.     }
  91.     if (hGLRC == NULL)
  92.     {
  93.         printf("Error: unable to get GL Render Context");
  94.         return;
  95.     }
  96.  
  97.     // define the minimum pixel format requirements we will need for our pbuffer
  98.     // a pbuffer is just like a frame buffer, it can have a depth buffer associated
  99.     // with it and it can be double buffered.
  100.     int attr[] =
  101.     {
  102.         WGL_SUPPORT_OPENGL_ARB, TRUE,       // pbuffer will be used with gl
  103.         WGL_DRAW_TO_PBUFFER_ARB, TRUE,      // enable render to pbuffer
  104.         WGL_BIND_TO_TEXTURE_RGBA_ARB, TRUE, // pbuffer will be used as a texture
  105.         WGL_RED_BITS_ARB, 8,                // at least 8 bits for RED channel
  106.         WGL_GREEN_BITS_ARB, 8,              // at least 8 bits for GREEN channel
  107.         WGL_BLUE_BITS_ARB, 8,               // at least 8 bits for BLUE channel
  108.         WGL_ALPHA_BITS_ARB, 8,              // at least 8 bits for ALPHA channel
  109.         WGL_DEPTH_BITS_ARB, 24,             // at least 24 bits for depth buffer
  110.         WGL_DOUBLE_BUFFER_ARB, FALSE,       // we don�t require double buffering
  111.         0                                   // zero terminates the list
  112.     };
  113.  
  114.     // choose a pixel format that meets our minimum requirements
  115.     unsigned int count = 0;
  116.     int pixelFormat;
  117.     wglChoosePixelFormatARB(hGLDC,(const int*)attr, NULL, 1,&pixelFormat,&count);
  118.     if(count == 0)
  119.     {
  120.         printf("P-buffer Error: Unable to find an acceptable pixel format");
  121.         return;
  122.     }
  123.  
  124.     // set some pbuffer attributes so that we can use this pbuffer as a
  125.     // 2D RGBA texture target
  126.     int pAttrib[] =
  127.     {
  128.         0,
  129.         WGL_TEXTURE_FORMAT_ARB, // our pbuffer will have texture format RGBA
  130.         WGL_TEXTURE_RGBA_ARB,
  131.         WGL_TEXTURE_TARGET_ARB, // of texture type GL_TEXTURE_2D
  132.         WGL_TEXTURE_2D_ARB,
  133.         0                       // zero terminates the list
  134.     };
  135.  
  136.     // allocate the pbuffer
  137.     hPBuffer = wglCreatePbufferARB(hGLDC, pixelFormat, w, h, pAttrib);
  138.     hPBufferDC = wglGetPbufferDCARB(hPBuffer);
  139.     hPBufferRC = wglCreateContext(hPBufferDC);
  140.  
  141.     if( !hPBuffer )
  142.     {
  143.         printf("P-buffer Error: Unable to create P-buffer");
  144.         return;
  145.     }
  146.  
  147.     // make a texture object for binding the pbuffer to
  148.     glGenTextures(1, &pbufferTextureID);
  149.     glBindTexture(GL_TEXTURE_2D, pbufferTextureID);
  150.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE_EXT);
  151.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE_EXT);
  152.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  153.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  154.  
  155.     initOK = true;
  156. }
  157.  
  158.  

 
Reedbeta

May 02, 2005, 03:33 PM

WGL_DOUBLE_BUFFER_ARB, FALSE,

As far as I know, you can't actually put in "false" arguments to these attribute lists - remember, FALSE has a value of zero, so it will think that the list has been terminated there. I would try removing this line and seeing if it works.

Another thing you might try is specifying WGL_COLOR_BITS_ARB as 24, rather than the red/green/blue bits individually.

I'm pointing these things out because in my experience, wglChoosePixelFormat (and the other pbuffer-related functions) can be very finicky - but I've never used fltk, so I don't know if some other issue might interfere related to that.

 
This thread contains 2 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.