#include #include #include #include #include #include #include #include #include "resource.h" HINSTANCE hInstance; // Holds The Instance Of The Application GLuint texture[3]; //stores texture objects and display list LPCTSTR registryPath = ("Software\\Microsoft\\ScreenSavers\\Butterflies"); BOOL dRotate; struct object // Create A Structure Called Object { int tex; // Integer Used To Select Our Texture float x; // X Position float y; // Y Position float z; // Z Position float yi; // Y Increase Speed (Fall Speed) float spinz; // Z Axis Spin float spinzi; // Z Axis Spin Speed float flap; // Flapping Triangles :) float fi; // Flap Direction (Increase Value) }; struct object obj[50]; //object obj[50]; // Create 50 Objects Using The Object Structure void SetDefaults() { dRotate = TRUE; } void ReadRegistry(){ LONG result; HKEY skey; DWORD valtype, valsize, val; SetDefaults(); result = RegOpenKeyEx(HKEY_CURRENT_USER, registryPath, 0, KEY_READ, &skey); if(result != ERROR_SUCCESS) return; valsize=sizeof(val); result = RegQueryValueEx(skey, "Rotate", 0, &valtype, (LPBYTE)&val, &valsize); if(result == ERROR_SUCCESS) dRotate = val; RegCloseKey(skey); } void WriteRegistry(){ LONG result; HKEY skey; DWORD val, disp; result = RegCreateKeyEx(HKEY_CURRENT_USER, registryPath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &skey, &disp); if(result != ERROR_SUCCESS) return; val = dRotate; RegSetValueEx(skey, "Rotate", 0, REG_DWORD, (CONST BYTE*)&val, sizeof(val)); RegCloseKey(skey); } void SetObject(int loop) // Sets The Initial Value Of Each Object (Random) { obj[loop].tex=rand()%3; // Texture Can Be One Of 3 Textures obj[loop].x=rand()%34-17.0f; // Random x Value From -17.0f To 17.0f obj[loop].y=18.0f; // Set y Position To 18 (Off Top Of Screen) obj[loop].z=-((rand()%30000/1000.0f)+10.0f); // z Is A Random Value From -10.0f To -40.0f obj[loop].spinzi=(rand()%10000)/5000.0f-1.0f; // spinzi Is A Random Value From -1.0f To 1.0f obj[loop].flap=0.0f; // flap Starts Off At 0.0f; obj[loop].fi=0.05f+(rand()%100)/1000.0f; // fi Is A Random Value From 0.05f To 0.15f obj[loop].yi=0.001f+(rand()%1000)/10000.0f; // yi Is A Random Value From 0.001f To 0.101f } void LoadGLTextures() // Creates Textures From Bitmaps In The Resource File { HBITMAP hBMP; // Handle Of The Bitmap BITMAP BMP; // Bitmap Structure int loop; // The ID Of The 3 Bitmap Images We Want To Load From The Resource File byte Texture[]={ IDB_BUTTERFLY1, IDB_BUTTERFLY2, IDB_BUTTERFLY3 }; glGenTextures(sizeof(Texture), &texture[0]); // Generate 3 Textures (sizeof(Texture)=3 ID's) for (loop=0; loop1.0f) || (obj[loop].flap<-1.0f)) // Time To Change Flap Direction? { obj[loop].fi=-obj[loop].fi; // Change Direction By Making fi = -fi } } Sleep(15); // Create A Short Delay (15 Milliseconds) glFlush (); } BOOL AboutProc(HWND hdlg, UINT msg, WPARAM wpm, LPARAM lpm){ switch(msg){ case WM_CTLCOLORSTATIC: if(((HWND)lpm == GetDlgItem(hdlg, WEBPAGE1)) || ((HWND)lpm == GetDlgItem(hdlg, WEBPAGE2))) { SetTextColor((HDC)wpm, RGB(0,0,255)); SetBkColor((HDC)wpm, (COLORREF)GetSysColor(COLOR_3DFACE)); return((int)GetSysColorBrush(COLOR_3DFACE)); } break; case WM_COMMAND: switch(LOWORD(wpm)){ case IDOK: EndDialog(hdlg, LOWORD(wpm)); break; case WEBPAGE1: ShellExecute(NULL, "open", "http://nehe.gamedev.net", NULL, NULL, SW_SHOWNORMAL); break; case WEBPAGE2: ShellExecute(NULL, "open", "http://www.thaputer.com", NULL, NULL, SW_SHOWNORMAL); break; } } return FALSE; } LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HGLRC hRC; static DWORD timer = 1; HDC hDC; RECT WindowRect; int width; int height; switch (message) { case WM_CREATE: ReadRegistry(); hRC = InitOGLWindow(hWnd); GetClientRect (hWnd, &WindowRect); width = WindowRect.right - WindowRect.left; height = WindowRect.bottom - WindowRect.top; InitOpenGL(width,height); SetTimer(hWnd, timer, 5, NULL); break; case WM_TIMER: hDC = GetDC(hWnd); Display(); SwapBuffers(hDC); ReleaseDC(hWnd, hDC); break; case WM_DESTROY: wglMakeCurrent(NULL, NULL); wglDeleteContext(hRC); break; } return DefScreenSaverProc(hWnd, message, wParam, lParam); } BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: ReadRegistry(); CheckDlgButton(hDlg, ROTATE, dRotate); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: dRotate = (IsDlgButtonChecked(hDlg, ROTATE) == BST_CHECKED); WriteRegistry(); EndDialog(hDlg, TRUE); return TRUE; case IDCANCEL: EndDialog(hDlg, TRUE); break; case IDABOUT: DialogBox(hInstance, MAKEINTRESOURCE(IDD_DLG_ABOUT), hDlg, (DLGPROC)AboutProc); break; } } return FALSE; } BOOL WINAPI RegisterDialogClasses(HANDLE hInst) { return TRUE; }