Index: 3dtext.c =================================================================== --- 3dtext.c (revision 68470) +++ 3dtext.c (working copy) @@ -40,20 +40,18 @@ #define APPNAME _T("3DText") HINSTANCE hInstance; -BOOL fullscreen = FALSE; +#define APP_TIMER 1 +#define APP_TIMER_INTERVAL USER_TIMER_MINIMUM + // Build Our Bitmap Font GLvoid BuildFont(GLvoid) { - // Address Buffer For Font Storage - GLYPHMETRICSFLOAT gmf[256]; - // Windows Font Handle - HFONT font; + HFONT font; // Windows Font Handle + GLYPHMETRICSFLOAT gmf[256]; // Address Buffer For Font Storage size_t i; TCHAR c; - GLfloat cellOriginX = 0.0f; - GLfloat stringOriginX; - GLfloat stringExtentX = 0.0f; + GLfloat stringCellX = 0.0f; GLfloat stringExtentY = 0.0f; // Storage For 256 Characters @@ -90,17 +88,12 @@ for (i = 0; i < _tcslen(m_Text); i++) { c = m_Text[i]; - - stringOriginX = cellOriginX + gmf[c].gmfptGlyphOrigin.x; - - stringExtentX = stringOriginX + gmf[c].gmfBlackBoxX; if (gmf[c].gmfBlackBoxY > stringExtentY) stringExtentY = gmf[c].gmfBlackBoxY; - - cellOriginX = cellOriginX + gmf[c].gmfCellIncX; + stringCellX += gmf[c].gmfCellIncX; } - extentX = stringExtentX; + extentX = stringCellX; extentY = stringExtentY; } @@ -114,7 +107,6 @@ // Custom GL "Print" Routine GLvoid glPrint(LPTSTR text) { - // If there's no text, do nothing if (text == NULL) return; @@ -121,7 +113,7 @@ // Pushes The Display List Bits glPushAttrib(GL_LIST_BIT); - // Sets The Base Character to 32 + // Sets The Base Character glListBase(base); // Draws The Display List Text @@ -181,7 +173,7 @@ } // Handles Window Resizing -GLvoid ReSizeGLScene(GLsizei Width, GLsizei Height) +GLvoid ReSizeGLScene(GLsizei Width, GLsizei Height) { // Is Window Too Small (Divide By Zero Error) if (Height == 0) @@ -255,6 +247,7 @@ LRESULT CALLBACK ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { + static BOOL fullscreen = FALSE; RECT Screen; // Used Later On To Get The Size Of The Window GLuint PixelFormat; // Pixel Format Storage static PIXELFORMATDESCRIPTOR pfd= // Pixel Format Descriptor @@ -263,7 +256,7 @@ 1, // Version Number (?) PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL - PFD_DOUBLEBUFFER, // Must Support Double Buffering + PFD_DOUBLEBUFFER, // Format Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format 16, // Select A 16Bit Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored (?) @@ -282,6 +275,8 @@ switch (message) { case WM_CREATE: + fullscreen = GetParent(hWnd) ? FALSE : TRUE; //Screensaver in fullscreen has no window-owner + LoadSettings(); // Gets A Device Context For The Window @@ -338,6 +333,13 @@ // Initialize The GL Screen Using Screen Info InitGL(Screen.right, Screen.bottom); + + // When it's not fullscreen we should release DC, + // because each wm_paint call needs its own DC. + if (!fullscreen){ + ReleaseDC(hWnd, hDC); + } + SetTimer(hWnd, APP_TIMER, APP_TIMER_INTERVAL, NULL); break; case WM_DESTROY: @@ -358,15 +360,36 @@ break; case WM_PAINT: + { + PAINTSTRUCT ps; + if (!fullscreen){ + hDC = BeginPaint(hWnd, &ps); //new DC is necessary because screensaver overlaps other windows + wglMakeCurrent(hDC, hRC); //and cant be moved to another place + } + DrawGLScene(); - SwapBuffers(hDC); + SwapBuffers(hDC); + + if (!fullscreen){ + EndPaint(hWnd, &ps); //don't release DC to support double buffering in fullscreen mode + } else { + ValidateRect(hWnd, NULL); //don't generate wm_paint message till next timer signal + } break; + } case WM_SIZE: // Resizing The Screen // Resize To The New Window Size + ReSizeGLScene(LOWORD(lParam), HIWORD(lParam)); break; + case WM_TIMER: //timer sets rate of update + { + InvalidateRect(hWnd, NULL, 1); + break; + } + default: // Pass Windows Messages to the default screensaver window procedure return DefScreenSaverProc(hWnd, message, wParam, lParam);