PDA

View Full Version : Render context from bitmap?



innocent_bystander
06-18-2003, 06:54 AM
I'm trying to use the video card for processing without anything being displayed on the screen. I really don't want a window, hidden or otherwise, to be created. I am trying to use a bitmap to obtain a render context from which I can get the ARB function entry points I need to render-to-texture. However, although all appears to be well and I appear to have a valid render context, when I call wglGetProcAddress I get zip. I have no idea why, since the error codes are less than helpful. (The error after the wglGetProcAddress call is: The specified procedure could not be found. Well, thanks.)

Is what I want to do possible, and could anyone please help me? The offending code (without any error checking or the like) is below:


// Create bitmap
BITMAPINFOHEADER bih;
void *data;

memset( &bih, 0, sizeof( bih ) );
bih.biSize = sizeof( bih );
bih.biWidth = 256;
bih.biHeight = 256;
bih.biBitCount = 32;
bih.biCompression = BI_RGB;
bih.biPlanes = 1;

HDC memDC = CreateCompatibleDC( NULL );
HBITMAP memBMP = CreateDIBSection( memDC,
(BITMAPINFO*)&bih, DIB_RGB_COLORS, &data, NULL, 0 );

SelectObject( memDC, memBMP );

// Set pixel format
int pixelType = PFD_TYPE_RGBA;
DWORD flags = ( PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI );

PIXELFORMATDESCRIPTOR pfd;
memset( &pfd, 0, sizeof( PIXELFORMATDESCRIPTOR ) );
pfd.nSize = sizeof( PIXELFORMATDESCRIPTOR );
pfd.nVersion = 1;
pfd.dwFlags = flags;
pfd.iPixelType = pixelType;
pfd.cColorBits = 32;
pfd.cDepthBits = 8;
pfd.iLayerType = PFD_MAIN_PLANE;

int pixelFormat = ChoosePixelFormat( memDC, &pfd );
BOOL result = SetPixelFormat( memDC, pixelFormat, &pfd );

// Create context
HGLRC hglrc = wglCreateContext( memDC );
result = wglMakeCurrent( memDC, hglrc );

// Get ARB entry points
wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress("wglGetExtensionsStringARB");
wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC) wglGetProcAddress("wglChoosePixelFormatARB");
wglCreatePbufferARB = (PFNWGLCREATEPBUFFERARBPROC) wglGetProcAddress("wglCreatePbufferARB");


---------
memDC and hglrc appear valid, but all wglGetProcAddresses return NULL.

Cheers.

Relic
06-18-2003, 07:22 AM
That's because the memory DC's are not accelerated and you got Microsoft's OpenGL implementation which doesn't offer any of these extensions.
Check glGetString() with GL_VENDOR, GL_RENDERER, GL_VERSION and GL_EXTENSIONS!

Korval
06-18-2003, 09:17 AM
I'm trying to use the video card for processing without anything being displayed on the screen. I really don't want a window, hidden or otherwise, to be created.

If the window is hidden, what's wrong with creating it? Especially considering that, without an actual window's DC, you can't get an accelerated pixel format.

*Aaron*
06-18-2003, 12:13 PM
I think the window will have to be visible because, some drivers (e.g., nVidia's) won't write to places in the back buffer that correspond to locations on the window that are obscured by another window. I image that if a window were minimized, it wouldn't draw at all. If this is the case, you've got two options: limit yourself to the generic implementation (mostly unextended software GL 1.1) or create a window and make it visible (though, you don't have to swap the buffers).

jra101
06-18-2003, 12:55 PM
You can also create a hidden window, then create a pbuffer and render to this.