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-03 18:46:06 +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
|
|
|
|
|
|
|
HWND hWnd=NULL; // Holds Our Window Handle
|
|
|
|
HINSTANCE hInstance; // Holds The Instance Of The Application
|
2003-02-25 00:25:07 +00:00
|
|
|
BOOL win_loop_done;
|
|
|
|
BOOL has_failed = false;
|
|
|
|
BOOL painting = false;
|
|
|
|
UINT BOINC_PAINT;
|
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
|
|
|
|
|
|
|
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-02-25 00:25:07 +00:00
|
|
|
if (uMsg == BOINC_PAINT) {
|
|
|
|
if(has_failed) return 0;
|
|
|
|
if(painting) return 0;
|
|
|
|
painting = true;
|
|
|
|
|
|
|
|
HWND bwnd;
|
|
|
|
if(!(bwnd = (HWND)lParam)) {
|
|
|
|
has_failed = true;
|
2003-02-07 00:06:10 +00:00
|
|
|
return 0;
|
2002-09-18 22:15:49 +00:00
|
|
|
}
|
|
|
|
|
2003-02-25 00:25:07 +00:00
|
|
|
HDC bdc;
|
|
|
|
if(!(bdc = GetDC(bwnd))) {
|
|
|
|
has_failed = true;
|
2003-02-07 00:06:10 +00:00
|
|
|
return 0;
|
2003-02-25 00:25:07 +00:00
|
|
|
}
|
2002-09-18 22:15:49 +00:00
|
|
|
|
2003-02-25 00:25:07 +00:00
|
|
|
RECT rt;
|
|
|
|
GetClientRect(bwnd, &rt);
|
|
|
|
int width = rt.right - rt.left;
|
|
|
|
int height = rt.bottom - rt.top;
|
2002-09-18 22:15:49 +00:00
|
|
|
|
2003-02-25 00:25:07 +00:00
|
|
|
PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
|
2002-09-18 22:15:49 +00:00
|
|
|
{
|
2003-02-25 00:25:07 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
int PixelFormat;
|
|
|
|
if(!(PixelFormat = ChoosePixelFormat(bdc, &pfd))) {
|
|
|
|
ReleaseDC(bwnd, bdc);
|
|
|
|
has_failed = true;
|
2002-09-18 22:15:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-02-25 00:25:07 +00:00
|
|
|
if(!SetPixelFormat(bdc, PixelFormat, &pfd)) {
|
|
|
|
ReleaseDC(bwnd, bdc);
|
|
|
|
has_failed = true;
|
2003-02-07 00:06:10 +00:00
|
|
|
return 0;
|
2003-02-25 00:25:07 +00:00
|
|
|
}
|
2002-11-14 00:49:24 +00:00
|
|
|
|
2003-02-25 00:25:07 +00:00
|
|
|
HGLRC hRC;
|
|
|
|
if(!(hRC = wglCreateContext(bdc))) {
|
|
|
|
ReleaseDC(bwnd, bdc);
|
|
|
|
has_failed = true;
|
2003-02-07 00:06:10 +00:00
|
|
|
return 0;
|
2003-02-25 00:25:07 +00:00
|
|
|
}
|
2002-09-18 22:15:49 +00:00
|
|
|
|
2003-02-25 00:25:07 +00:00
|
|
|
if(!wglMakeCurrent(bdc, hRC)) {
|
|
|
|
ReleaseDC(bwnd, bdc);
|
|
|
|
wglDeleteContext(hRC);
|
|
|
|
has_failed = true;
|
2003-02-07 00:06:10 +00:00
|
|
|
return 0;
|
2003-02-25 00:25:07 +00:00
|
|
|
}
|
2002-12-20 20:20:56 +00:00
|
|
|
|
2003-02-25 00:25:07 +00:00
|
|
|
ReSizeGLScene(width, height);
|
|
|
|
InitGL();
|
2003-03-03 18:46:06 +00:00
|
|
|
app_init_gl();
|
2003-02-25 00:25:07 +00:00
|
|
|
|
2003-03-03 18:46:06 +00:00
|
|
|
app_render(width, height, dtime());
|
2003-02-25 00:25:07 +00:00
|
|
|
|
|
|
|
SwapBuffers(bdc);
|
2003-02-07 00:06:10 +00:00
|
|
|
|
2003-02-25 00:25:07 +00:00
|
|
|
if(!wglMakeCurrent(NULL, NULL)) {
|
|
|
|
ReleaseDC(bwnd, bdc);
|
|
|
|
wglDeleteContext(hRC);
|
|
|
|
has_failed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!ReleaseDC(bwnd, bdc)) has_failed = true;
|
|
|
|
if(!wglDeleteContext(hRC)) has_failed = true;
|
2003-02-07 00:06:10 +00:00
|
|
|
|
2003-02-25 00:25:07 +00:00
|
|
|
painting = false;
|
|
|
|
return 1;
|
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-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();
|
|
|
|
BOINC_PAINT = RegisterWindowMessage( "BOINC_PAINT" );
|
2002-11-14 00:49:24 +00:00
|
|
|
|
2002-09-18 22:15:49 +00:00
|
|
|
// Create Our OpenGL Window
|
2003-02-25 00:25:07 +00:00
|
|
|
hWnd = CreateWindowEx(WS_EX_APPWINDOW|WS_EX_WINDOWEDGE, // Extended Style For The Window
|
|
|
|
"BOINC_OpenGL", // Class Name
|
|
|
|
"BOINC App", // Window Title
|
|
|
|
WS_OVERLAPPEDWINDOW | // Defined Window Style
|
|
|
|
WS_CLIPSIBLINGS | // Required Window Style
|
|
|
|
WS_CLIPCHILDREN, // Required Window Style
|
|
|
|
0, 0, 100, 100,
|
|
|
|
NULL, // No Parent Window
|
|
|
|
NULL, // No Menu
|
|
|
|
hInstance, // Instance
|
|
|
|
NULL); // Dont Pass Anything To WM_CREATE
|
|
|
|
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 100, 100, SWP_HIDEWINDOW);
|
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;
|
|
|
|
}
|
|
|
|
|