PDA

View Full Version : Pixel Buffer Problemo



robert
02-17-2003, 11:08 PM
Hi, I am trying to get my pixel buffer going with shared contexts (for render-to-texture). The code I use is basically copied from the nvidia sdk examples, but there is a problem with wglCreatePbufferARB which returns null.

Has anyone else had this problem? It only happens when it follows the shared context path (ie mShare == true)





// Grab the parameters for the main render window (the one that displays)
oldhDC= wglGetCurrentDC();
oldhGLC = wglGetCurrentContext();

mShare = set.share;

// Query for a suitable pixel format based on the specified mode.
int format = 0;
int pformat[MAX_PFORMATS];
unsigned int nformats;
int iattributes[2*MAX_ATTRIBS];
float fattributes[2*MAX_ATTRIBS];
int nfattribs = 0;
int niattribs = 0;


if ( mShare )
{
// Get the pixel format for the on-screen window.
format = GetPixelFormat( oldhDC );
}
else
{
// Attribute arrays must be "0" terminated
for ( int a = 0; a < 2*MAX_ATTRIBS; a++ )
{
iattributes[a] = 0;
fattributes[a] = 0;
}

// Since we are trying to create a pbuffer, the pixel format we
// request (and subsequently use) must be "p-buffer capable".
iattributes[niattribs ] = WGL_DRAW_TO_PBUFFER_ARB;
iattributes[++niattribs] = GL_TRUE;
// we are asking for a pbuffer that is meant to be bound
// as an RGBA texture - therefore we need a color plane
iattributes[++niattribs] = WGL_BIND_TO_TEXTURE_RGBA_ARB;
iattributes[++niattribs] = GL_TRUE;

iattributes[++niattribs ] = WGL_SUPPORT_OPENGL_ARB;
iattributes[++niattribs ] = true;

if ( !wglChoosePixelFormatARB( oldhDC,
iattributes,
fattributes,
MAX_PFORMATS,
pformat,
&amp;nformats ) )
{
Error stuff;return false;
}

if ( nformats <= 0 )
{
Error stuff;return false;
}
format = pformat[0];

}


// End if(mShare)
// set the pbuffer attributes...
for (int i = 0; i < 2*MAX_ATTRIBS; ++i)
iattributes[i] = 0;

niattribs = 0;


// the render texture format is RGBA
// iattributes[niattribs] = WGL_SUPPORT_OPENGL_ARB;
// iattributes[++niattribs] = TRUE;

// the render texture target is GL_TEXTURE_2D
iattributes[niattribs++] = WGL_TEXTURE_TARGET_ARB;
iattributes[niattribs++] = WGL_TEXTURE_2D_ARB;


// ask to allocate room for the mipmaps
iattributes[niattribs++ ] = WGL_MIPMAP_TEXTURE_ARB;
iattributes[niattribs++] = TRUE;

// ask to allocate the largest pbuffer it can, if it is
// unable to allocate for the width and height
iattributes[niattribs++ ] = WGL_PBUFFER_LARGEST_ARB;
iattributes[niattribs++] = FALSE;
iattributes[niattribs++] = WGL_TEXTURE_FORMAT_ARB;
iattributes[niattribs++] = WGL_TEXTURE_RGBA_ARB;


hpBuffer = wglCreatePbufferARB( oldhDC, format, set.width, set.height, iattributes ); // error here



[This message has been edited by robert (edited 02-18-2003).]

[This message has been edited by robert (edited 02-18-2003).]