Skip to main content
gamedev.net
🔒 Locked

Windows PBuffer without a window

Started by GKW Apr 23, 2004 at 5:15 PM 4 replies 2.4k views
Original Post
GKW
GKW
Is this possible? I have looked at several posts that say it is but I am unable to do it. If I have to go the hidden window route I will do that but if someone can show me a spot of code on how to do this I would appreciate it. "... we should have such an empire for liberty as she has never surveyed since the creation ..." Thomas Jefferson
"... we should have such an empire for liberty as she has never surveyed since the creation ..."Thomas Jefferson
dslprog
dslprog
If I understand you right, you want to create a PBuffer without creating a window. Here is a standard code to create a PBuffer:

HDC hDC = wglGetCurrentDC();

// Get ready to query for a suitable pixel format that meets our minimum requirements.

int iAttributes[2*MAX_ATTRIBS];
float fAttributes[2*MAX_ATTRIBS];
int nfAttribs = 0;
int niAttribs = 0;
// Attribute arrays must be "0" terminated - for simplicity, first

// just zero-out the array then fill from left to right.

for (i=0; i<2*MAX_ATTRIBS; i++ ){
iAttributes[i] = 0;
fAttributes[i] = 0;
}
// Since we are trying to create a pbuffer, the pixel format we

//request (and subsequently use) must be "p-buffer capable".

iAttributes[2*niAttribs]=WGL_DRAW_TO_PBUFFER_ARB;
iAttributes[2*niAttribs+1]=true;
niAttribs++;
// We require a minimum of 24-bit depth.

iAttributes[2*niAttribs ]=WGL_DEPTH_BITS_ARB;
iAttributes[2*niAttribs+1]=24;
niAttribs++;
// We require a minimum of 8-bits for each R, G, B, and A.

iAttributes[2*niAttribs]=WGL_RED_BITS_ARB;
iAttributes[2*niAttribs+1]=8;
niAttribs++;
iAttributes[2*niAttribs]=WGL_GREEN_BITS_ARB;
iAttributes[2*niAttribs+1]=8;
niAttribs++;
iAttributes[2*niAttribs]=WGL_BLUE_BITS_ARB;
iAttributes[2*niAttribs+1]=8;
niAttribs++;
iAttributes[2*niAttribs]=WGL_ALPHA_BITS_ARB;
iAttributes[2*niAttribs+1]=8;
niAttribs++;
// Now obtain a list of pixel formats that meet these minimum requirements.

int pformat;
unsigned int nformats;
if(!wglChoosePixelFormatARB( hDC, iAttributes, fAttributes, 1, &pformat, &nformats)){
printf("pbuffer creation error: Couldn't find a suitable pixel format.\n" );
return false;
}

for (i=0; i<2*MAX_ATTRIBS; i++ )iAttributes[i] = 0;

g_hPBuffer=wglCreatePbufferARB( hDC, pformat, PBUFFERSIZE, PBUFFERSIZE, iAttributes );
g_hPBufDC=wglGetPbufferDCARB( g_hPBuffer );

int w,h;
wglQueryPbufferARB( g_hPBuffer, WGL_PBUFFER_WIDTH_ARB, &w );
wglQueryPbufferARB( g_hPBuffer, WGL_PBUFFER_HEIGHT_ARB, &h );
printf("PBuffer size: %d x %d\n",w,h);

g_hPBufRC=wglCreateContext(g_hPBufDC);
return true;

As you can see the most functions uses de current device context which is activated when you create an OpenGL window.
You could try to create a DC of the screen and use it. I'm not sure if that will work.

[edited by - dslprog on April 23, 2004 6:39:32 PM]
_the_phantom_
_the_phantom_
basicaly, as dslprog says, you need a device context which I belive needs to be setup for OpenGL.

The reason being, before that point OGL isnt setup and, on windows at least, you need OGL to be set up in order to get at the extra WGL functions for making pbuffers.
GKW
GKW
I know how to make a pbuffer. If I do the hidden window thing it works fine. I want to be able to create a pbuffer without making the hidden window. I can create a DC without error. I get a valid pixel format. When I set the format it returns true but sets GetLastError to INVALID_HANDLE. After that wglCreateContext returns a nonzero number but if I try to make the context current I get a error in the 3 billion range. I have looked at several posts that say it can be done but I have never seen any code that works. If someone can generate working code I would appreciate it a lot.

"... we should have such an empire for liberty as she has never surveyed since the creation ..."
Thomas Jefferson
"... we should have such an empire for liberty as she has never surveyed since the creation ..."Thomas Jefferson
GKW
GKW
CreateDC with a device string from enumdisplaydevices.

"... we should have such an empire for liberty as she has never surveyed since the creation ..."
Thomas Jefferson
"... we should have such an empire for liberty as she has never surveyed since the creation ..."Thomas Jefferson

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.