PDA

View Full Version : OpenGL Screen Saver problem.



jpummill
04-16-2002, 03:16 PM
Hi All,

I have downloaded a demo Screen Saver from called minimal.scr from the following site:
http://www.ite.mh.se/~danli97/opengl/

Which appears to be an adaptation of a Screen Saver called minimal.scr from the following site:
http://www.wischik.com/scr/howtoscr.html

The problem that I am having is that the demo that I downloaded, and the new screen saver that I have developed (my own 3d objects) display perfectly in full screen mode but when I open the "Display Properties" dialog box, select the "Screen Saver" tab, and select either the downloaded demo, or my saver, there is about a 15 second pause where the dialog box is locked up, and the hourglass is showing. After this, the preview window usually shows the saver properly. Any idea why the long pause??? Other OpenGL screen savers do not seem to have this lag effect.

I have included a small sample of the code showing where the Preview window is displayed and the minimal.scr demo is downloadable from the link above if anyone would like to test this on their machines.

An help would be greatly appreciated!!!
jpummill

Source:
void DoSaver(HWND hparwnd, int nCmdShow)
{
WNDCLASS wc;
wc.style=CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = SaverWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "OpenGL";

if( !RegisterClass(&wc) ) {
MessageBox(NULL, "RegisterClass() failed: "
"Cannot register window class.", "Error", MB_OK);
return;
}

int cx, cy;

if( ScrMode==smPreview )
{
RECT rc;
GetWindowRect(hparwnd,&rc);
cx = rc.right - rc.left;
cy = rc.bottom - rc.top;
hScrWindow =
CreateWindow("OpenGL", "SaverWindow", WS_CHILD|WS_VISIBLE,0, 0, cx, cy, hparwnd, NULL, hInstance, NULL);
}
else
{
cx = GetSystemMetrics(SM_CXSCREEN);
cy = GetSystemMetrics(SM_CYSCREEN);
DWORD exstyle, style;

exstyle = WS_EX_TOPMOST;
style = WS_POPUP|WS_VISIBLE;

hScrWindow = CreateWindow ("OpenGL", "SaverWindow", style,0, 0, cx, cy, NULL, NULL, hInstance, NULL);

}

if( hScrWindow==NULL )
return;

UINT oldval;

if( ScrMode==smSaver )
SystemParametersInfo(SPI_SCREENSAVERRUNNING,1,&oldval,0);

HDC hDC = GetDC(hScrWindow);

PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;

int pf = ChoosePixelFormat(hDC, &pfd);
if (pf == 0) {
MessageBox(NULL, "ChoosePixelFormat() failed: "
"Cannot find a suitable pixel format.", "Error", MB_OK);
return;
}

if (SetPixelFormat(hDC, pf, &pfd) == FALSE) {
MessageBox(NULL, "SetPixelFormat() failed: "
"Cannot set format specified.", "Error", MB_OK);
return;
}

DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

HGLRC hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);

initGL(cx, cy);

ShowWindow(hScrWindow, nCmdShow);

MSG msg;

bool done = false;
while(!done) // Loop That Runs While done=FALSE
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
{
if (msg.message==WM_QUIT) // Have We Received A Quit Message?
done=TRUE; // If So done=TRUE
else // If Not, Deal With Window Messages
{
TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message
}
}
else // If There Are No Messages
{
rotationx += 1;
rotationy += 1;
rotationz += 2;

display(ss->Rotate, ss->WireFrame);

if( rotationx >= 360 ) rotationx -= 360;
if( rotationy >= 360 ) rotationy -= 360;
if( rotationz >= 360 ) rotationz -= 360;

SwapBuffers(hDC); // Swap Buffers (Double Buffering)

//Sleep(10);
}
}

wglMakeCurrent(NULL, NULL);
ReleaseDC(hScrWindow, hDC);
wglDeleteContext(hRC);

if( ScrMode==smSaver )
SystemParametersInfo(SPI_SCREENSAVERRUNNING,0,&oldval,0);
return;
}