2002-10-25 18:23:59 +00:00
|
|
|
// The contents of this file are subject to the Mozilla Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2002-11-20 22:57:43 +00:00
|
|
|
/* This Code Was Created By Jeff Molofee 2000
|
2002-09-18 22:15:49 +00:00
|
|
|
* A HUGE Thanks To Fredric Echols For Cleaning Up
|
|
|
|
* And Optimizing This Code, Making It More Flexible!
|
|
|
|
* If You've Found This Code Useful, Please Let Me Know.
|
|
|
|
* Visit My Site At nehe.gamedev.net
|
|
|
|
* Adapted to BOINC by Eric Heien
|
|
|
|
*/
|
|
|
|
|
2002-10-06 00:43:54 +00:00
|
|
|
#include <afxwin.h>
|
2002-09-18 22:15:49 +00:00
|
|
|
#include <gl\gl.h> // Header File For The OpenGL32 Library
|
2003-02-25 00:25:07 +00:00
|
|
|
#include <gl\glu.h> // Header File For The GLu32 Library
|
2002-09-18 22:15:49 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "graphics_api.h"
|
2003-03-04 23:57:25 +00:00
|
|
|
#include "util.h"
|
2003-02-25 00:25:07 +00:00
|
|
|
#include "win_idle_tracker.h"
|
2002-09-18 22:15:49 +00:00
|
|
|
|
2003-03-19 18:42:51 +00:00
|
|
|
HDC hdc;
|
|
|
|
HGLRC hRC;
|
2002-09-18 22:15:49 +00:00
|
|
|
HWND hWnd=NULL; // Holds Our Window Handle
|
|
|
|
HINSTANCE hInstance; // Holds The Instance Of The Application
|
2003-03-04 06:01:46 +00:00
|
|
|
RECT rect = {50, 50, 50+640, 50+480};
|
|
|
|
int nPrevMode = MODE_NO_GRAPHICS;
|
|
|
|
int nMode = MODE_NO_GRAPHICS;
|
|
|
|
POINT mousePos;
|
|
|
|
|
2003-02-25 00:25:07 +00:00
|
|
|
BOOL win_loop_done;
|
2003-03-04 06:01:46 +00:00
|
|
|
UINT SET_MODE, GET_MODE;
|
2002-10-24 16:39:00 +00:00
|
|
|
|
2002-11-26 21:33:43 +00:00
|
|
|
extern bool using_opengl;
|
2003-02-06 00:24:30 +00:00
|
|
|
extern HANDLE hQuitEvent;
|
2002-09-18 22:15:49 +00:00
|
|
|
|
|
|
|
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
|
|
|
|
DWORD WINAPI win_graphics_event_loop( LPVOID duff );
|
2002-11-18 21:20:54 +00:00
|
|
|
BOOL reg_win_class();
|
|
|
|
BOOL unreg_win_class();
|
2002-09-18 22:15:49 +00:00
|
|
|
|
2003-03-04 06:01:46 +00:00
|
|
|
void SetMode(int mode, int pmode)
|
|
|
|
{
|
|
|
|
RECT WindowRect = {0,0,0,0};
|
2003-03-19 18:42:51 +00:00
|
|
|
int width, height;
|
2003-03-04 06:01:46 +00:00
|
|
|
|
|
|
|
if(pmode == MODE_DEFAULT) nPrevMode = nMode;
|
|
|
|
else nPrevMode = pmode;
|
|
|
|
nMode = mode;
|
|
|
|
|
|
|
|
if(hWnd) {
|
2003-03-19 18:42:51 +00:00
|
|
|
if (hRC) wglDeleteContext(hRC);
|
|
|
|
if (hdc) ReleaseDC(hWnd, hdc);
|
|
|
|
|
2003-03-04 06:01:46 +00:00
|
|
|
if(nPrevMode != MODE_FULLSCREEN) GetWindowRect(hWnd, &rect);
|
|
|
|
KillTimer(hWnd, 1);
|
|
|
|
DestroyWindow(hWnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD dwExStyle;
|
|
|
|
DWORD dwStyle;
|
|
|
|
|
|
|
|
if (nMode == MODE_FULLSCREEN) {
|
|
|
|
HDC screenDC=GetDC(NULL);
|
|
|
|
WindowRect.left = WindowRect.top = 0;
|
|
|
|
WindowRect.right=GetDeviceCaps(screenDC, HORZRES);
|
|
|
|
WindowRect.bottom=GetDeviceCaps(screenDC, VERTRES);
|
|
|
|
ReleaseDC(NULL, screenDC);
|
|
|
|
dwExStyle=WS_EX_TOPMOST;
|
|
|
|
dwStyle=WS_POPUP;
|
|
|
|
while(ShowCursor(false) >= 0);
|
|
|
|
} else {
|
|
|
|
WindowRect = rect;
|
|
|
|
dwExStyle=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE;
|
|
|
|
dwStyle=WS_OVERLAPPEDWINDOW;
|
|
|
|
while(ShowCursor(true) < 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
hWnd = CreateWindowEx(dwExStyle, "BOINC_OpenGL", "BOINC Graphics",
|
|
|
|
dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, WindowRect.left, WindowRect.top,
|
|
|
|
WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top,
|
|
|
|
NULL, NULL, hInstance, NULL);
|
|
|
|
|
|
|
|
SetTimer(hWnd, 1, 100, NULL);
|
|
|
|
|
|
|
|
GetCursorPos(&mousePos);
|
|
|
|
|
|
|
|
PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
|
|
|
|
{
|
|
|
|
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
|
|
|
|
1, // Version Number
|
|
|
|
PFD_DRAW_TO_WINDOW | // Format Must Support Window
|
|
|
|
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
|
|
|
|
PFD_DOUBLEBUFFER, // Format Must Support OpenGL
|
|
|
|
PFD_TYPE_RGBA, // Request An RGBA Format
|
|
|
|
16, // Select Our Color Depth
|
|
|
|
0, 0, 0, 0, 0, 0, // Color Bits Ignored
|
|
|
|
0, // No Alpha Buffer
|
|
|
|
0, // Shift Bit Ignored
|
|
|
|
0, // No Accumulation Buffer
|
|
|
|
0, 0, 0, 0, // Accumulation Bits Ignored
|
|
|
|
16, // 16Bit Z-Buffer (Depth Buffer)
|
|
|
|
0, // No Stencil Buffer
|
|
|
|
0, // No Auxiliary Buffer
|
|
|
|
PFD_MAIN_PLANE, // Main Drawing Layer
|
|
|
|
0, // Reserved
|
|
|
|
0, 0, 0 // Layer Masks Ignored
|
|
|
|
};
|
|
|
|
|
2003-03-19 18:42:51 +00:00
|
|
|
hdc = GetDC(hWnd);
|
2003-03-04 06:01:46 +00:00
|
|
|
int PixelFormat;
|
|
|
|
PixelFormat = ChoosePixelFormat(hdc, &pfd);
|
|
|
|
SetPixelFormat(hdc, PixelFormat, &pfd);
|
2003-03-19 18:42:51 +00:00
|
|
|
|
|
|
|
if(!(hRC = wglCreateContext(hdc))) {
|
|
|
|
ReleaseDC(hWnd, hdc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!wglMakeCurrent(hdc, hRC)) {
|
|
|
|
ReleaseDC(hWnd, hdc);
|
|
|
|
wglDeleteContext(hRC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
width = WindowRect.right-WindowRect.left;
|
|
|
|
height = WindowRect.bottom-WindowRect.top;
|
|
|
|
|
|
|
|
ReSizeGLScene(width, height);
|
|
|
|
InitGL();
|
|
|
|
app_init_gl();
|
2003-03-04 06:01:46 +00:00
|
|
|
|
|
|
|
if(nMode == MODE_FULLSCREEN || nMode == MODE_WINDOW) {
|
|
|
|
ShowWindow(hWnd, SW_SHOW);
|
|
|
|
if(nMode == MODE_FULLSCREEN) SetForegroundWindow(hWnd);
|
|
|
|
} else {
|
|
|
|
ShowWindow(hWnd, SW_HIDE);
|
|
|
|
}
|
|
|
|
SetFocus(hWnd);
|
|
|
|
|
|
|
|
PostMessage(HWND_BROADCAST, RegisterWindowMessage( "BOINC_APP_MODE" ), nMode, GetCurrentProcessId());
|
|
|
|
}
|
|
|
|
|
2002-09-18 22:15:49 +00:00
|
|
|
LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
|
|
|
|
UINT uMsg, // Message For This Window
|
2003-02-25 00:25:07 +00:00
|
|
|
WPARAM wParam, // Additional Message Information
|
|
|
|
LPARAM lParam) // Additional Message Information
|
2002-09-18 22:15:49 +00:00
|
|
|
{
|
2003-03-19 18:42:51 +00:00
|
|
|
RECT rt;
|
|
|
|
int width, height;
|
|
|
|
|
2003-03-04 06:01:46 +00:00
|
|
|
switch(uMsg) {
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
case WM_MBUTTONDOWN:
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
if(nMode == MODE_FULLSCREEN) SetMode(nPrevMode, MODE_DEFAULT);
|
2003-02-07 00:06:10 +00:00
|
|
|
return 0;
|
2003-03-04 06:01:46 +00:00
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
if(nMode == MODE_FULLSCREEN) {
|
|
|
|
POINT cPos;
|
|
|
|
GetCursorPos(&cPos);
|
|
|
|
if(cPos.x != mousePos.x || cPos.y != mousePos.y) SetMode(nPrevMode, MODE_DEFAULT);
|
|
|
|
}
|
2003-02-07 00:06:10 +00:00
|
|
|
return 0;
|
2003-03-04 06:01:46 +00:00
|
|
|
case WM_CLOSE:
|
|
|
|
SetMode(MODE_NO_GRAPHICS, MODE_DEFAULT);
|
2002-09-18 22:15:49 +00:00
|
|
|
return 0;
|
2003-03-04 06:01:46 +00:00
|
|
|
case WM_PAINT:
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
RECT winRect;
|
|
|
|
HDC pdc;
|
|
|
|
pdc = BeginPaint(hWnd, &ps);
|
|
|
|
GetClientRect(hWnd, &winRect);
|
|
|
|
FillRect(pdc, &winRect, (HBRUSH)GetStockObject(BLACK_BRUSH));
|
|
|
|
EndPaint(hWnd, &ps);
|
2003-02-07 00:06:10 +00:00
|
|
|
return 0;
|
2003-03-19 18:42:51 +00:00
|
|
|
case WM_SIZE:
|
|
|
|
ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));
|
|
|
|
return 0;
|
2003-03-04 06:01:46 +00:00
|
|
|
case WM_TIMER:
|
2003-03-10 23:20:39 +00:00
|
|
|
if(nMode == MODE_NO_GRAPHICS) return 0;
|
2002-11-14 00:49:24 +00:00
|
|
|
|
2003-03-04 06:01:46 +00:00
|
|
|
GetClientRect(hWnd, &rt);
|
2003-03-19 18:42:51 +00:00
|
|
|
width = rt.right-rt.left;
|
|
|
|
height = rt.bottom-rt.top;
|
2003-02-25 00:25:07 +00:00
|
|
|
|
2003-03-04 23:57:25 +00:00
|
|
|
app_render(width, height, dtime());
|
2003-03-04 06:01:46 +00:00
|
|
|
|
|
|
|
SwapBuffers(hdc);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-02-25 00:25:07 +00:00
|
|
|
|
2003-03-04 06:01:46 +00:00
|
|
|
if(uMsg == SET_MODE) {
|
|
|
|
SetMode(wParam, lParam);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-02-07 00:06:10 +00:00
|
|
|
|
2003-03-04 06:01:46 +00:00
|
|
|
if(uMsg == GET_MODE) {
|
|
|
|
return MAKELONG(nMode, nPrevMode);
|
2002-09-18 22:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pass All Unhandled Messages To DefWindowProc
|
|
|
|
return DefWindowProc(hWnd,uMsg,wParam,lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI win_graphics_event_loop( LPVOID gi ) {
|
2003-02-07 00:29:38 +00:00
|
|
|
MSG msg; // Windows Message Structure
|
2002-09-18 22:15:49 +00:00
|
|
|
|
2003-03-04 06:01:46 +00:00
|
|
|
double start = (double)time(0);
|
|
|
|
|
2003-02-07 00:06:10 +00:00
|
|
|
// Register window class and graphics mode message
|
2003-02-25 00:25:07 +00:00
|
|
|
reg_win_class();
|
2003-03-04 06:01:46 +00:00
|
|
|
GET_MODE = RegisterWindowMessage( "BOINC_APP_GET" );
|
|
|
|
SET_MODE = RegisterWindowMessage( "BOINC_APP_SET" );
|
|
|
|
|
|
|
|
SetMode(MODE_NO_GRAPHICS, MODE_NO_GRAPHICS);
|
2003-02-07 00:06:10 +00:00
|
|
|
|
2003-02-25 00:25:07 +00:00
|
|
|
win_loop_done = false;
|
2002-11-26 21:33:43 +00:00
|
|
|
using_opengl = true;
|
2003-02-25 00:25:07 +00:00
|
|
|
while(!win_loop_done) {
|
|
|
|
if (GetMessage(&msg,NULL,0,0)) {
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
2002-12-20 20:20:56 +00:00
|
|
|
} else {
|
2003-02-07 00:06:10 +00:00
|
|
|
win_loop_done = true;
|
2002-09-18 22:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-18 21:20:54 +00:00
|
|
|
unreg_win_class();
|
2002-11-14 00:49:24 +00:00
|
|
|
|
|
|
|
SetEvent(hQuitEvent); // Signal to the worker thread that we're quitting
|
|
|
|
return (msg.wParam); // Exit The thread
|
2002-09-18 22:15:49 +00:00
|
|
|
}
|
|
|
|
|
2003-02-25 00:25:07 +00:00
|
|
|
BOOL VerifyPassword(HWND hwnd)
|
|
|
|
{ // Under NT, we return TRUE immediately. This lets the saver quit,
|
2002-09-18 22:15:49 +00:00
|
|
|
// and the system manages passwords. Under '95, we call VerifyScreenSavePwd.
|
|
|
|
// This checks the appropriate registry key and, if necessary,
|
|
|
|
// pops up a verify dialog
|
|
|
|
OSVERSIONINFO osv; osv.dwOSVersionInfoSize=sizeof(osv); GetVersionEx(&osv);
|
|
|
|
if (osv.dwPlatformId==VER_PLATFORM_WIN32_NT) return TRUE;
|
|
|
|
HINSTANCE hpwdcpl=::LoadLibrary("PASSWORD.CPL");
|
|
|
|
if (hpwdcpl==NULL) {return TRUE;}
|
|
|
|
typedef BOOL (WINAPI *VERIFYSCREENSAVEPWD)(HWND hwnd);
|
|
|
|
VERIFYSCREENSAVEPWD VerifyScreenSavePwd;
|
|
|
|
VerifyScreenSavePwd=
|
|
|
|
(VERIFYSCREENSAVEPWD)GetProcAddress(hpwdcpl,"VerifyScreenSavePwd");
|
2003-02-25 00:25:07 +00:00
|
|
|
if (VerifyScreenSavePwd==NULL)
|
|
|
|
{
|
2002-09-18 22:15:49 +00:00
|
|
|
FreeLibrary(hpwdcpl);return TRUE;
|
|
|
|
}
|
|
|
|
BOOL bres=VerifyScreenSavePwd(hwnd); FreeLibrary(hpwdcpl);
|
|
|
|
return bres;
|
2002-11-18 21:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL reg_win_class() {
|
|
|
|
WNDCLASS wc; // Windows Class Structure
|
|
|
|
|
|
|
|
hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
|
2003-02-25 00:25:07 +00:00
|
|
|
wc.style = 0; // Redraw On Size, And Own DC For Window.
|
2002-11-18 21:20:54 +00:00
|
|
|
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages
|
|
|
|
wc.cbClsExtra = 0; // No Extra Window Data
|
|
|
|
wc.cbWndExtra = 0; // No Extra Window Data
|
|
|
|
wc.hInstance = hInstance; // Set The Instance
|
|
|
|
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
|
|
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
|
|
|
|
wc.hbrBackground = NULL; // No Background Required For GL
|
|
|
|
wc.lpszMenuName = NULL; // We Don't Want A Menu
|
2003-02-25 00:25:07 +00:00
|
|
|
wc.lpszClassName = "BOINC_OpenGL"; // Set The Class Name
|
2002-11-18 21:20:54 +00:00
|
|
|
|
2003-02-25 00:25:07 +00:00
|
|
|
if (!RegisterClass(&wc)) // Attempt To Register The Window Class
|
|
|
|
{
|
2002-11-18 21:20:54 +00:00
|
|
|
MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
|
|
|
|
return FALSE; // Return FALSE
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL unreg_win_class() {
|
2003-02-25 00:25:07 +00:00
|
|
|
if (!UnregisterClass("BOINC_OpenGL",hInstance)) // Are We Able To Unregister Class
|
|
|
|
{
|
2002-11-18 21:20:54 +00:00
|
|
|
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
|
|
|
|
hInstance=NULL; // Set hInstance To NULL
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|