I’m developing an OpenGL screensaver for Windows. I’ve taken the example ScreenSaver from the MSDN library (the one that links to scrnsave.h) and adapted it for OpenGL.
It works fine on my Diamond FireGL 1000. On another machine with a Voodoo 3, it goes to fullscreen mode, brings up the 3DFX logo, then quits. It’s almost as if the spinning 3DFX logo is a separate program that, on quitting, tells Windows that the screensaver’s finished. However I’ve seen other OpenGL Screensavers that work happily.
Does anyone have any suggestions? I’m posting the code that does the initialisation and termination below, sorry for the length of the posting!
Stormcloud
LONG CALLBACK ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HGLRC hRC; // Permenant Rendering context
static HDC hDC; // Private GDI Device context
int i;
switch(message)
{
case WM_CREATE:
// Store the device context
hDC = GetDC(hWnd);
// Select the pixel format
SetDCPixelFormat(hDC);
// Create the rendering context and make it current
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
// Create the palette
hPalette = GetOpenGLPalette(hDC);
// Create a timer that fires every millisecond
SetTimer(hWnd,101,1,NULL);
// Set up initial viewport position.
iScreenX = ((LPCREATESTRUCT)lParam)->cx;
iScreenY = ((LPCREATESTRUCT)lParam)->cy;
//Perform initialisation
GetRegistryInfo();
srand( (unsigned)time( NULL ) );
InitDisplay();
for (i = 0; i < iNoOfSquares; i++)
{
RecalcSquareCols();
}
InitVariables();
break;
case WM_ERASEBKGND:
/*
* The WM_ERASEBKGND message is issued before the
* WM_TIMER message, allowing the screen saver to
* paint the background as appropriate.
*/
break;
case WM_TIMER:
/*
*
*/
TimerTick();
Display();
SwapBuffers(hDC);
//InvalidateRect(hWnd,NULL,FALSE);
break;
case WM_DESTROY:
/*
* Destroy timers and rendering context etc.
*/
// Kill the timer that we created
KillTimer(hWnd,101);
// Deselect the current rendering context and delete it
wglMakeCurrent(hDC,NULL);
wglDeleteContext(hRC);
// Delete the palette
if(hPalette != NULL)
DeleteObject(hPalette);
// Tell the application to terminate after the window
// is gone.
PostQuitMessage(0);
break;
}
/*
* DefScreenSaverProc processes any messages
* ignored by ScreenSaverProc.
*/
return DefScreenSaverProc(hWnd, message, wParam, lParam);
}