void initpBuffer()
{
initpb = true;
GLuint PixelFormat;
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 16;
pfd.cDepthBits = 16;
//PixelFormat = ChoosePixelFormat( g_hDC, &pfd );
g_hDC = wglGetCurrentDC();
PixelFormat = ChoosePixelFormat( g_hDC, &pfd );
SetPixelFormat( g_hDC, PixelFormat, &pfd);
g_hRC = wglCreateContext( g_hDC );
wglMakeCurrent( g_hDC, g_hRC );
wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
char *ext = NULL;
if( wglGetExtensionsStringARB )
ext = (char*)wglGetExtensionsStringARB( wglGetCurrentDC() );
else
{
// MessageBox(NULL,"Unable to get address for wglGetExtensionsStringARB!",
// "ERROR",MB_OK|MB_ICONEXCLAMATION);
exit(-1);
}
//
// WGL_ARB_pbuffer
//
if( strstr( ext, "WGL_ARB_pbuffer" ) == NULL )
{
exit(-1);
}
else
{
wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC)wglGetProcAddress("wglCreatePbufferARB");
wglGetPbufferDCARB = (PFNWGLGETPBUFFERDCARBPROC)wglGetProcAddress("wglGetPbufferDCARB");
wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)wglGetProcAddress("wglReleasePbufferDCARB");
wglDestroyPbufferARB = (PFNWGLDESTROYPBUFFERARBPROC)wglGetProcAddress("wglDestroyPbufferARB");
wglQueryPbufferARB = (PFNWGLQUERYPBUFFERARBPROC)wglGetProcAddress("wglQueryPbufferARB");
if( !wglCreatePbufferARB || !wglGetPbufferDCARB || !wglReleasePbufferDCARB ||
!wglDestroyPbufferARB || !wglQueryPbufferARB )
{
exit(-1);
}
}
//
// WGL_ARB_pixel_format
//
if( strstr( ext, "WGL_ARB_pixel_format" ) == NULL )
{
return;
}
else
{
wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
if( !wglChoosePixelFormatARB )
{
exit(-1);
}
}
//
// WGL_ARB_render_texture
//
if( strstr( ext, "WGL_ARB_render_texture" ) == NULL )
{
exit(-1);
}
else
{
wglBindTexImageARB = (PFNWGLBINDTEXIMAGEARBPROC)wglGetProcAddress("wglBindTexImageARB");
wglReleaseTexImageARB = (PFNWGLRELEASETEXIMAGEARBPROC)wglGetProcAddress("wglReleaseTexImageARB");
wglSetPbufferAttribARB = (PFNWGLSETPBUFFERATTRIBARBPROC)wglGetProcAddress("wglSetPbufferAttribARB");
if( !wglBindTexImageARB || !wglReleaseTexImageARB || !wglSetPbufferAttribARB )
{
exit(-1);
}
}
//-------------------------------------------------------------------------
// Create a p-buffer for off-screen rendering.
//-------------------------------------------------------------------------
g_pbuffer.hPBuffer = NULL;
g_pbuffer.nWidth = streetRes;
g_pbuffer.nHeight = streetRes;
//
// Define the minimum pixel format requirements we will need for our
// p-buffer. A p-buffer is just like a frame buffer, it can have a depth
// buffer associated with it and it can be double buffered.
//
int pf_attr[] =
{
WGL_SUPPORT_OPENGL_ARB, TRUE, // P-buffer will be used with
OpenGL
WGL_DRAW_TO_PBUFFER_ARB, TRUE, // Enable render to p-buffer
WGL_BIND_TO_TEXTURE_RGBA_ARB, TRUE, // P-buffer will be used as a texture
WGL_RED_BITS_ARB, 8, // At least 8 bits for RED channel
WGL_GREEN_BITS_ARB, 8, // At least 8 bits for GREEN channel
WGL_BLUE_BITS_ARB, 8, // At least 8 bits for BLUE channel
WGL_ALPHA_BITS_ARB, 8, // At least 8 bits for ALPHA channel
WGL_DEPTH_BITS_ARB, 16, // At least 16 bits for depth buffer
WGL_DOUBLE_BUFFER_ARB, FALSE, // We don't require double buffering
0 // Zero terminates the list
};
unsigned int count = 0;
int pixelFormat;
wglChoosePixelFormatARB( g_hDC,(const int*)pf_attr, NULL, 1, &pixelFormat, &count);
if( count == 0 )
{
exit(-1);
}
//
// Set some p-buffer attributes so that we can use this p-buffer as a
// 2D RGBA texture target.
//
int pb_attr[] =
{
WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB, // Our p-buffer will have a texture format of RGBA
WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB, // Of texture target will be GL_TEXTURE_2D
0 // Zero terminates the list
};
//
// Create the p-buffer...
//
g_pbuffer.hPBuffer = wglCreatePbufferARB( g_hDC, pixelFormat, g_pbuffer.nWidth, g_pbuffer.nHeight, pb_attr );
g_pbuffer.hDC = wglGetPbufferDCARB( g_pbuffer.hPBuffer );
g_pbuffer.hRC = wglCreateContext( g_pbuffer.hDC );
if( !g_pbuffer.hPBuffer )
{
exit(-1);
}
int h;
int w;
wglQueryPbufferARB( g_pbuffer.hPBuffer, WGL_PBUFFER_WIDTH_ARB, &h );
wglQueryPbufferARB( g_pbuffer.hPBuffer, WGL_PBUFFER_WIDTH_ARB, &w );
if( h != g_pbuffer.nHeight || w != g_pbuffer.nWidth )
{
exit(-1);
}
//
// We were successful in creating a p-buffer. We can now make its context
// current and set it up just like we would a regular context
// attached to a window.
//
if( !wglMakeCurrent( g_pbuffer.hDC, g_pbuffer.hRC ) )
{
exit(-1);
}
drawpBuffer();
}