i create by this way
GPUBuffer gp;
int format;
int pformat[MAX_PFORMATS];
unsigned int nformats;
int iattributes[2MAX_ATTRIBS];
float fattributes[2*MAX_ATTRIBS];
int nfattribs = 0;
int niattribs = 0;
HDC hdc = wglGetCurrentDC();
HGLRC hglrc = wglGetCurrentContext();
gp = (GPUBuffer *) calloc(sizeof(GPUBuffer), 1);
gp->width = width;
gp->height = height;
// ;
// Attribute arrays must be "0" terminated - for simplicity, first
// just zero-out the array entire, then fill from left to right.
memset(iattributes, 0, sizeof(int)*2*MAX_ATTRIBS);
memset(fattributes, 0, sizeof(float)*2*MAX_ATTRIBS);
// 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
if (bitsPerComponent == 32 || bitsPerComponent == 16) {
gp->type = GL_FLOAT;
iattributes[++niattribs] = WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV;
iattributes[++niattribs] = GL_TRUE;
iattributes[++niattribs] = WGL_FLOAT_COMPONENTS_NV;
iattributes[++niattribs] = GL_TRUE;
}
else {
gp->type = GL_UNSIGNED_BYTE;
bitsPerComponent = 8;
iattributes[++niattribs] = WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV;
iattributes[++niattribs] = GL_TRUE;
}
iattributes[++niattribs] = WGL_RED_BITS_ARB;
iattributes[++niattribs] = bitsPerComponent;
iattributes[++niattribs] = WGL_GREEN_BITS_ARB;
iattributes[++niattribs] = bitsPerComponent;
iattributes[++niattribs] = WGL_BLUE_BITS_ARB;
iattributes[++niattribs] = bitsPerComponent;
iattributes[++niattribs] = WGL_ALPHA_BITS_ARB;
iattributes[++niattribs] = bitsPerComponent;
iattributes[++niattribs] = WGL_DOUBLE_BUFFER_ARB;
iattributes[++niattribs] = GL_TRUE;
iattributes[++niattribs] = WGL_SAMPLE_BUFFERS_ARB;
iattributes[++niattribs] = GL_TRUE;
//iattributes[++niattribs] = WGL_SAMPLES_ARB;
//iattributes[++niattribs] = 4;
if (!wglChoosePixelFormatARB) {
QUERY_EXTENSION_ENTRY_POINT(wglChoosePixelFormatARB,
PFNWGLCHOOSEPIXELFORMATARBPROC);
QUERY_EXTENSION_ENTRY_POINT(wglCreatePbufferARB,
PFNWGLCREATEPBUFFERARBPROC);
QUERY_EXTENSION_ENTRY_POINT(wglGetPbufferDCARB,
PFNWGLGETPBUFFERDCARBPROC);
QUERY_EXTENSION_ENTRY_POINT(wglQueryPbufferARB,
PFNWGLQUERYPBUFFERARBPROC);
QUERY_EXTENSION_ENTRY_POINT(wglReleaseTexImageARB,
PFNWGLRELEASETEXIMAGEARBPROC);
QUERY_EXTENSION_ENTRY_POINT(wglBindTexImageARB,
PFNWGLBINDTEXIMAGEARBPROC);
QUERY_EXTENSION_ENTRY_POINT(glActiveTexture,
PFNGLACTIVETEXTUREARBPROC);
}
if ( !wglChoosePixelFormatARB( hdc, iattributes, fattributes, MAX_PFORMATS, pformat, &nformats ) )
{
printf("pbuffer creation error: wglChoosePixelFormatARB() failed.
");
}
// ;
if ( nformats <= 0 )
{
printf("pbuffer creation error: Couldn’t find a suitable pixel format.
");
}
format = pformat[0];
// Set up the pbuffer attributes
memset(iattributes,0,sizeof(int)*2*MAX_ATTRIBS);
niattribs = 0;
// the render texture format is RGBA
iattributes[niattribs] = WGL_TEXTURE_FORMAT_ARB;
if (gp->type == GL_FLOAT) {
iattributes[++niattribs] = WGL_TEXTURE_FLOAT_RGBA_NV;
}
else
iattributes[++niattribs] = WGL_TEXTURE_RGBA_ARB;
// the render texture target is GL_TEXTURE_RECTANGLE_NV
iattributes[++niattribs] = WGL_TEXTURE_TARGET_ARB;
iattributes[++niattribs] = WGL_TEXTURE_RECTANGLE_NV;
// 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] = TRUE;
// Create the p-buffer.
gp->hpbuffer = (HPBUFFERARB) wglCreatePbufferARB( hdc, format, width, height, iattributes );
if ( gp->hpbuffer == 0)
{
printf("pbuffer creation error: wglCreatePbufferARB() failed
");
return 0;
}
// ;
// Get the device context.
gp->hdc = wglGetPbufferDCARB( gp->hpbuffer );
if ( gp->hdc == 0)
{
printf("pbuffer creation error: wglGetPbufferDCARB() failed
");
;
}
;
// Create a gl context for the p-buffer.
gp->hglrc = wglCreateContext(gp->hdc);
if ( gp->hglrc == 0)
{
printf("pbuffer creation error: wglCreateContext() failed
");
;
}
;
wglShareLists(hglrc, gp->hglrc);
// Determine the actual width and height we were able to create.
wglQueryPbufferARB( gp->hpbuffer, WGL_PBUFFER_WIDTH_ARB, &gp->width );
wglQueryPbufferARB( gp->hpbuffer, WGL_PBUFFER_HEIGHT_ARB, &gp->height );
printf("pbuffer created: Width %d height %d
", gp->width, gp->height);
wglMakeCurrent(gp->hdc, gp->hglrc);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glOrtho(0.0, (double) gp->width, 0.0, (double) gp->height, -1.0, 1.0);
wglMakeCurrent(hdc, hglrc);
return gp;
it go failed when excuting
gp->hpbuffer = (HPBUFFERARB) wglCreatePbufferARB( hdc, format, width, height, iattributes );
can anybody help me ?