Hello Siwko,
Thank you very much for your help and prompt reply, but I am still unable
to initiate the change from render to screen to render to an off screen bitmap
followed by a return to on screen without editing and recompiling my code.
I am including a simplified version of my test code incase you
have time to look at it and let me know where I am going wrong.
Best regards,
Peter Lee.
//globals
static HDC hDC; //GDI DC for main window
static HGLRC hRC; //RC for main window
static HDC dc; //GDI DCt for bitmap
static HGLRC rc; //RC for bimap
void ChangeSize(long width, long hieght)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70.0f, fAspect, 100.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
glTranslatef(0.0f, 0.0f, -200.0f);
}
void PreRender(HDC hDC, HGLRC hRC)
{
if(render_screen == TRUE)
{
wglMakeCurrent(hDC, hRC);
RenderScene();
glFinish();
}
SwapBuffers(hDC);
}
void RenderScene(void)
{
//OGL drawing code
glFlush();
}
HPALETTE GetOpenGLPalette(HDC hDC)
{
//create a palette for the DC listed
return hRetPal; //return the handle to the new palette
}
void SetDCPixelFormat(HDC hDC)
{
//select the pixel format for a given DC
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
//code
}
LRESULT CALLBACK WndProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
hDC = GetDC(hWnd);
SetDCPixelFormat(hDC);
hRC = wglCreateContext(hDC);
//wglMakeCurrent(hDC, hRC);
hPalette = GetOpenGLPalette(hDC);
break;
case WM_DESTROY:
wglMakeCurrent(hDC,NULL);
wglDeleteContext(hRC);
if(hPalette != NULL)
{
DeleteObject(hPalette);
}
PostQuitMessage(0);
break;
case WM_SIZE:
maxX = LOWORD(lParam);
maxY = HIWORD(lParam);
ChangeSize(LOWORD(lParam), HIWORD(lParam));
InvalidateRect(hWnd,NULL,FALSE);
break;
case WM_KEYDOWN: //initiates on screen or off screen rendering
{
if(wParam == VK_END)
{
InvalidateRect(hWnd,NULL,FALSE);
Make_DIB();
}
if(wParam == VK_HOME)
{
render_screen = FALSE;
InvalidateRect(hWnd,NULL,FALSE);
}
break;
}
case WM_PAINT:
{
PreRender(hDC, hRC);
//RenderScene();
//SwapBuffers(hDC);
ValidateRect(hWnd,NULL);
}
break;
case WM_QUERYNEWPALETTE:
//code
case WM_PALETTECHANGED:
//code
default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return (0L);
}
void Make_DIB(void)
{
//declare variables etc
dc = CreateCompatibleDC(NULL);
//code
memset(&info, 0, sizeof(info));
//code - info
bitmap = CreateDIBSection(dc, &info, DIB_RGB_COLORS, &bits, NULL, 0);
//code
SelectObject(dc, bitmap);
memset(&pfd, 0, sizeof(pfd));
//code - pfd
pf = ChoosePixelFormat(dc, &pfd);
SetPixelFormat(dc, pf, &pfd);
rc = wglCreateContext(dc);
wglMakeCurrent(dc, rc);
glClearColor(0.3f, 0.2f, 0.4f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gluPerspective(80.0f, (float)Width/Height, 100.0, 1000.0);
glTranslatef(0.0f, 0.0f, -200.0f);
RenderScene();
glFlush();
render_screen = TRUE; //resets render destination logic
SaveDIBitmap(“PJL_Contour.bmp”, &info, bits);
//Free everything:
wglDeleteContext(rc);
DeleteObject(bitmap);
DeleteDC(dc);
}
int SaveDIBitmap(const char *filename,
BITMAPINFO *info,
GLubyte *bits)
{
//code
}