#ifdef WIN32
//Windows screensaver code borrowed from Rachel Grey
// http://www.cityintherain.com/howtoscr.html
#include <direct.h>
#include <windows.h>
#include <scrnsave.h>
#include <GL/gl.h>
#include "World.h"
//globals used by the function below to hold the screen size
int Width;
int Height;
//define a Windows timer
#define TIMER 1
//the World of the screensaver
World* world;
static void InitGL(HWND hWnd, HDC & hDC, HGLRC & hRC)
{
PIXELFORMATDESCRIPTOR pfd;
ZeroMemory( &pfd, sizeof pfd );
pfd.nSize = sizeof pfd;
pfd.nVersion = 1;
pfd.dwFlags = PFD_SUPPORT_OPENGL;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
hDC = GetDC( hWnd );
int i = ChoosePixelFormat( hDC, &pfd );
SetPixelFormat( hDC, i, &pfd );
hRC = wglCreateContext( hDC );
wglMakeCurrent( hDC, hRC );
}
static void CloseGL(HWND hWnd, HDC hDC, HGLRC hRC)
{
wglMakeCurrent( NULL, NULL );
wglDeleteContext( hRC );
ReleaseDC( hWnd, hDC );
}
// Screen Saver Procedure
LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
static HDC hDC;
static HGLRC hRC;
static RECT rect;
int argc = 0;
char** argv = 0;
switch ( message ) {
case WM_CREATE:
// get window dimensions
GetClientRect( hWnd, &rect );
Width = rect.right;
Height = rect.bottom;
//set up OpenGL
InitGL( hWnd, hDC, hRC );
//Initialize perspective, viewpoint, and
//any objects you wish to animate
world = new World( Width, Height );
//create a timer that ticks every 500 milliseconds
SetTimer( hWnd, TIMER, 500, NULL );
return 0;
case WM_DESTROY:
KillTimer( hWnd, TIMER );
//delete any objects created during animation
//and close down OpenGL nicely
delete world;
CloseGL( hWnd, hDC, hRC );
return 0;
case WM_TIMER:
//call some function to advance your animation
world->Step();
world->Render();
glFlush();
return 0;
}
return DefScreenSaverProc(
hWnd, message, wParam, lParam );
}
BOOL WINAPI
ScreenSaverConfigureDialog(HWND hDlg, UINT message,
WPARAM wParam, LPARAM lParam)
{
return true;
}
// needed for SCRNSAVE.LIB
BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
{
return true;
}
#endif //WIN32
# |
Change |
User |
Description |
Committed |
|
#1
|
4772 |
Sam Stafford |
Something I've been doodling with. |
|
|