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-05-07 23:42:17 +00:00
|
|
|
#include "app_ipc.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-05-07 23:42:17 +00:00
|
|
|
static HDC hdc;
|
|
|
|
static HGLRC hRC;
|
2003-05-08 22:53:52 +00:00
|
|
|
static HWND hWnd=NULL; // Holds Our Window Handle
|
2003-05-07 23:42:17 +00:00
|
|
|
static HINSTANCE hInstance; // Holds The Instance Of The Application
|
2003-05-08 22:53:52 +00:00
|
|
|
static RECT rect = {50, 50, 50+640, 50+480};
|
|
|
|
static int current_graphics_mode = MODE_HIDE_GRAPHICS;
|
2003-05-07 23:42:17 +00:00
|
|
|
static POINT mousePos;
|
2003-05-08 22:53:52 +00:00
|
|
|
static UINT m_uEndSSMsg;
|
2003-03-04 06:01:46 +00:00
|
|
|
|
2003-02-25 00:25:07 +00:00
|
|
|
BOOL win_loop_done;
|
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-05-07 23:42:17 +00:00
|
|
|
// switch to the given graphics mode. This is called:
|
|
|
|
// - on initialization
|
|
|
|
// - when get mode change msg (via shared mem)
|
|
|
|
// - when in SS mode and get user input
|
|
|
|
//
|
|
|
|
void SetMode(int mode) {
|
2003-03-04 06:01:46 +00:00
|
|
|
RECT WindowRect = {0,0,0,0};
|
2003-03-19 18:42:51 +00:00
|
|
|
int width, height;
|
2003-05-07 23:42:17 +00:00
|
|
|
DWORD dwExStyle;
|
|
|
|
DWORD dwStyle;
|
2003-03-04 06:01:46 +00:00
|
|
|
|
|
|
|
if(hWnd) {
|
2003-03-19 18:42:51 +00:00
|
|
|
if (hRC) wglDeleteContext(hRC);
|
|
|
|
if (hdc) ReleaseDC(hWnd, hdc);
|
|
|
|
|
2003-05-07 23:42:17 +00:00
|
|
|
if (current_graphics_mode != MODE_FULLSCREEN) GetWindowRect(hWnd, &rect);
|
2003-03-04 06:01:46 +00:00
|
|
|
KillTimer(hWnd, 1);
|
|
|
|
DestroyWindow(hWnd);
|
|
|
|
}
|
|
|
|
|
2003-05-07 23:42:17 +00:00
|
|
|
current_graphics_mode = mode;
|
2003-03-04 06:01:46 +00:00
|
|
|
|
2003-05-07 23:42:17 +00:00
|
|
|
if (current_graphics_mode == MODE_FULLSCREEN) {
|
2003-03-04 06:01:46 +00:00
|
|
|
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
|
|
|
|
2003-05-07 23:42:17 +00:00
|
|
|
if(current_graphics_mode == MODE_FULLSCREEN || current_graphics_mode == MODE_WINDOW) {
|
2003-03-04 06:01:46 +00:00
|
|
|
ShowWindow(hWnd, SW_SHOW);
|
2003-03-25 00:03:25 +00:00
|
|
|
SetFocus(hWnd);
|
2003-03-04 06:01:46 +00:00
|
|
|
} else {
|
|
|
|
ShowWindow(hWnd, SW_HIDE);
|
|
|
|
}
|
|
|
|
|
2003-05-07 23:42:17 +00:00
|
|
|
app_client_shm->send_graphics_mode_msg(APP_CORE_GFX_SEG, current_graphics_mode);
|
2003-03-04 06:01:46 +00:00
|
|
|
}
|
|
|
|
|
2003-05-07 23:42:17 +00:00
|
|
|
// message handler (includes timer, Windows msgs)
|
|
|
|
//
|
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;
|
2003-05-07 23:42:17 +00:00
|
|
|
int width, height, new_mode;
|
2003-03-19 18:42:51 +00:00
|
|
|
|
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:
|
2003-05-08 22:53:52 +00:00
|
|
|
if(current_graphics_mode == MODE_FULLSCREEN) {
|
|
|
|
SetMode(MODE_HIDE_GRAPHICS);
|
|
|
|
PostMessage(HWND_BROADCAST, m_uEndSSMsg, 0, 0);
|
|
|
|
}
|
2003-02-07 00:06:10 +00:00
|
|
|
return 0;
|
2003-03-04 06:01:46 +00:00
|
|
|
case WM_MOUSEMOVE:
|
2003-05-07 23:42:17 +00:00
|
|
|
if(current_graphics_mode == MODE_FULLSCREEN) {
|
2003-03-04 06:01:46 +00:00
|
|
|
POINT cPos;
|
|
|
|
GetCursorPos(&cPos);
|
2003-05-08 22:53:52 +00:00
|
|
|
if(cPos.x != mousePos.x || cPos.y != mousePos.y) {
|
|
|
|
SetMode(MODE_HIDE_GRAPHICS);
|
|
|
|
PostMessage(HWND_BROADCAST, m_uEndSSMsg, 0, 0);
|
|
|
|
}
|
2003-03-04 06:01:46 +00:00
|
|
|
}
|
2003-02-07 00:06:10 +00:00
|
|
|
return 0;
|
2003-03-04 06:01:46 +00:00
|
|
|
case WM_CLOSE:
|
2003-05-07 23:42:17 +00:00
|
|
|
SetMode(MODE_HIDE_GRAPHICS);
|
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-05-07 23:42:17 +00:00
|
|
|
if (app_client_shm->get_graphics_mode_msg(CORE_APP_GFX_SEG, new_mode)) {
|
|
|
|
SetMode(new_mode);
|
|
|
|
}
|
|
|
|
if (current_graphics_mode == MODE_HIDE_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
|
|
|
|
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-05-08 22:53:52 +00:00
|
|
|
m_uEndSSMsg = RegisterWindowMessage(END_SS_MSG);
|
2003-03-04 06:01:46 +00:00
|
|
|
|
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
|
|
|
|
2003-05-07 23:42:17 +00:00
|
|
|
SetMode(MODE_HIDE_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;
|
|
|
|
}
|
|
|
|
|