Sign in to follow this  
long_xz

how to creat a multisample pbuffer

Recommended Posts

i create by this way
GPUBuffer *gp;
int format;
int pformat[MAX_PFORMATS];
unsigned int nformats;
int iattributes[2*MAX_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.\n");
}
// ;
if ( nformats <= 0 )
{
printf("pbuffer creation error: Couldn't find a suitable pixel format.\n");
}
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\n");
return 0;
}
// ;

// Get the device context.
gp->hdc = wglGetPbufferDCARB( gp->hpbuffer );
if ( gp->hdc == 0)
{
printf("pbuffer creation error: wglGetPbufferDCARB() failed\n");
;
}
;

// Create a gl context for the p-buffer.
gp->hglrc = wglCreateContext(gp->hdc);
if ( gp->hglrc == 0)
{
printf("pbuffer creation error: wglCreateContext() failed\n");
;
}
;
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\n", 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 ?

Share this post


Link to post
Share on other sites
Am I reading "pbuffer" in 2010?
Most likely your OpenGL driver doesn't support pbuffers anymore and that's why it's failing.
IIRC NVIDIA implemented in their drivers only for a short period of time. AFAIK they're also no longer supported by ATI

Go for FBO (Frame Buffer Object), forget about pbuffers.

FBOs do the same as pbuffers, but they're much more stable, easier to use, and better defined.
FBOs are the future (and by "future", I mean they've replaced pbuffers like 5 years ago)

Share this post


Link to post
Share on other sites
Quote:
Original post by Matias Goldberg
Am I reading "pbuffer" in 2010?
Most likely your OpenGL driver doesn't support pbuffers anymore and that's why it's failing.
IIRC NVIDIA implemented in their drivers only for a short period of time. AFAIK they're also no longer supported by ATI

Go for FBO (Frame Buffer Object), forget about pbuffers.

FBOs do the same as pbuffers, but they're much more stable, easier to use, and better defined.
FBOs are the future (and by "future", I mean they've replaced pbuffers like 5 years ago)


how to create fbo supporting multisample?and how to used it ?can u give me an example,please?i haven't used it!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this