2010-07-10 08:20:50 +00:00
|
|
|
/* ZZ Open GL graphics plugin
|
|
|
|
* Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
|
|
|
|
* Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
|
2010-03-19 05:24:36 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-07-04 22:49:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2010-03-19 05:24:36 +00:00
|
|
|
*/
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 05:24:36 +00:00
|
|
|
#include "GS.h"
|
2010-09-01 10:28:37 +00:00
|
|
|
#include "GLWin.h"
|
2010-03-19 05:24:36 +00:00
|
|
|
|
|
|
|
#ifdef GL_WIN32_WINDOW
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
2010-03-19 05:24:36 +00:00
|
|
|
{
|
|
|
|
static int nWindowWidth = 0, nWindowHeight = 0;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
switch (msg)
|
|
|
|
{
|
2010-03-19 05:24:36 +00:00
|
|
|
case WM_DESTROY:
|
2010-05-01 20:33:53 +00:00
|
|
|
PostQuitMessage(0);
|
2010-03-19 05:24:36 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
// switch(wParam) {
|
|
|
|
// case VK_ESCAPE:
|
|
|
|
// SendMessage(hWnd, WM_DESTROY, 0L, 0L);
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_SIZE:
|
2010-05-01 20:33:53 +00:00
|
|
|
nWindowWidth = lParam & 0xffff;
|
|
|
|
nWindowHeight = lParam >> 16;
|
2010-11-14 02:21:18 +00:00
|
|
|
GLWin.UpdateWindowSize(nWindowWidth, nWindowHeight);
|
2010-03-19 05:24:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_SIZING:
|
|
|
|
// if button is 0, then just released so can resize
|
2010-05-01 20:33:53 +00:00
|
|
|
if (GetSystemMetrics(SM_SWAPBUTTON) ? !GetAsyncKeyState(VK_RBUTTON) : !GetAsyncKeyState(VK_LBUTTON))
|
|
|
|
{
|
2010-11-14 01:38:10 +00:00
|
|
|
SetDeviceSize(nWindowWidth, nWindowHeight);
|
2010-03-19 05:24:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_SETCURSOR:
|
|
|
|
SetCursor(NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
return DefWindowProc(hWnd, msg, wParam, lParam);
|
2010-03-19 05:24:36 +00:00
|
|
|
}
|
|
|
|
|
2010-03-29 21:15:49 +00:00
|
|
|
bool GLWindow::CreateWindow(void *pDisplay)
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
2010-03-19 05:24:36 +00:00
|
|
|
RECT rc, rcdesktop;
|
2010-05-01 20:33:53 +00:00
|
|
|
rc.left = 0;
|
|
|
|
rc.top = 0;
|
|
|
|
rc.right = conf.width;
|
|
|
|
rc.bottom = conf.height;
|
2010-03-19 05:24:36 +00:00
|
|
|
|
|
|
|
WNDCLASSEX wc;
|
2010-09-19 08:01:48 +00:00
|
|
|
HINSTANCE hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
|
2010-03-19 05:24:36 +00:00
|
|
|
DWORD dwExStyle, dwStyle;
|
|
|
|
|
|
|
|
wc.cbSize = sizeof(WNDCLASSEX);
|
2010-09-19 08:01:48 +00:00
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Move, And Own DC For Window
|
|
|
|
wc.lpfnWndProc = (WNDPROC) MsgProc; // MsgProc Handles Messages
|
|
|
|
wc.cbClsExtra = 0; // No Extra Window Data
|
|
|
|
wc.cbWndExtra = 0; // No Extra Window Data
|
|
|
|
wc.hInstance = hInstance; // Set The Instance
|
|
|
|
wc.hIcon = NULL;
|
|
|
|
wc.hIconSm = NULL; // Load The Default Icon
|
|
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
|
|
|
|
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); // No Background Required For GL
|
|
|
|
wc.lpszMenuName = NULL; // We Don't Want A Menu
|
2010-12-25 04:38:44 +00:00
|
|
|
wc.lpszClassName = L"PS2EMU_ZEROGS"; // Set The Class Name
|
2010-03-19 05:24:36 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
RegisterClassEx(&wc);
|
2010-03-19 05:24:36 +00:00
|
|
|
|
2010-06-19 06:23:40 +00:00
|
|
|
if (conf.fullscreen())
|
2010-03-19 05:24:36 +00:00
|
|
|
{
|
|
|
|
dwExStyle = WS_EX_APPWINDOW;
|
|
|
|
dwStyle = WS_POPUP;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
|
2010-09-19 08:01:48 +00:00
|
|
|
dwStyle = WS_OVERLAPPEDWINDOW | WS_BORDER;
|
2010-03-19 05:24:36 +00:00
|
|
|
}
|
|
|
|
|
2010-09-19 08:01:48 +00:00
|
|
|
dwStyle |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
|
2010-05-01 23:34:44 +00:00
|
|
|
AdjustWindowRectEx(&rc, dwStyle, false, dwExStyle);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 05:24:36 +00:00
|
|
|
GetWindowRect(GetDesktopWindow(), &rcdesktop);
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
NativeWindow = CreateWindowEx( dwExStyle, // Extended Style For The Window
|
2010-12-25 04:38:44 +00:00
|
|
|
L"PS2EMU_ZEROGS", // Class Name
|
|
|
|
L"ZZOgl", // Window Title
|
2010-09-19 08:01:48 +00:00
|
|
|
dwStyle, // Selected Window Style
|
|
|
|
(rcdesktop.right - (rc.right - rc.left)) / 2, // Window Position
|
|
|
|
(rcdesktop.bottom - (rc.bottom - rc.top)) / 2, // Window Position
|
|
|
|
rc.right - rc.left, // Calculate Adjusted Window Width
|
|
|
|
rc.bottom - rc.top, // Calculate Adjusted Window Height
|
|
|
|
NULL, // No Parent Window
|
|
|
|
NULL, // No Menu
|
|
|
|
hInstance, // Instance
|
|
|
|
NULL); // Don't Pass Anything To WM_CREATE
|
2010-03-19 05:24:36 +00:00
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
if (NativeWindow == NULL)
|
2010-11-10 11:15:48 +00:00
|
|
|
{
|
|
|
|
ZZLog::Error_Log("Failed to create window. Exiting...");
|
|
|
|
return false;
|
|
|
|
}
|
2010-03-19 05:24:36 +00:00
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
if (pDisplay != NULL) *(HWND*)pDisplay = NativeWindow;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
// set just in case
|
2012-10-21 18:10:13 +00:00
|
|
|
SetWindowLongPtr(NativeWindow, GWLP_WNDPROC, (LPARAM)(WNDPROC)MsgProc);
|
2010-04-30 04:40:31 +00:00
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
ShowWindow(NativeWindow, SW_SHOWDEFAULT);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
UpdateWindow(NativeWindow);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
SetFocus(NativeWindow);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-11-10 11:15:48 +00:00
|
|
|
if (pDisplay == NULL) ZZLog::Error_Log("Failed to create window. Exiting...");
|
2010-03-19 05:24:36 +00:00
|
|
|
return (pDisplay != NULL);
|
|
|
|
}
|
|
|
|
|
2010-09-01 10:28:37 +00:00
|
|
|
bool GLWindow::ReleaseContext()
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
2012-10-21 18:10:13 +00:00
|
|
|
if (wglContext) // Do We Have A Rendering Context?
|
2010-03-19 05:24:36 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
if (!wglMakeCurrent(NULL, NULL)) // Are We Able To Release The DC And RC Contexts?
|
2010-03-19 05:24:36 +00:00
|
|
|
{
|
2010-12-25 04:38:44 +00:00
|
|
|
MessageBox(NULL, L"Release Of DC And RC Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
|
2010-03-19 05:24:36 +00:00
|
|
|
}
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
if (!wglDeleteContext(wglContext)) // Are We Able To Delete The RC?
|
2010-03-19 05:24:36 +00:00
|
|
|
{
|
2010-12-25 04:38:44 +00:00
|
|
|
MessageBox(NULL, L"Release Rendering Context Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
|
2010-03-19 05:24:36 +00:00
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
wglContext = NULL; // Set RC To NULL
|
2010-03-19 05:24:36 +00:00
|
|
|
}
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
CloseWGLDisplay();
|
2010-03-19 05:24:36 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLWindow::CloseWindow()
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
2012-10-21 18:10:13 +00:00
|
|
|
if (NativeWindow != NULL)
|
2010-03-19 05:24:36 +00:00
|
|
|
{
|
2012-10-21 18:10:13 +00:00
|
|
|
DestroyWindow(NativeWindow);
|
|
|
|
NativeWindow = NULL;
|
2010-03-19 05:24:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GLWindow::DisplayWindow(int _width, int _height)
|
|
|
|
{
|
|
|
|
DWORD dwExStyle; // Window Extended Style
|
|
|
|
DWORD dwStyle; // Window Style
|
|
|
|
|
|
|
|
RECT rcdesktop;
|
|
|
|
GetWindowRect(GetDesktopWindow(), &rcdesktop);
|
|
|
|
|
2010-06-19 06:23:40 +00:00
|
|
|
if (conf.fullscreen())
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-11-14 01:38:10 +00:00
|
|
|
backbuffer.w = rcdesktop.right - rcdesktop.left;
|
|
|
|
backbuffer.h = rcdesktop.bottom - rcdesktop.top;
|
2010-03-19 05:24:36 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
dwExStyle = WS_EX_APPWINDOW;
|
|
|
|
dwStyle = WS_POPUP;
|
2010-05-01 23:34:44 +00:00
|
|
|
ShowCursor(false);
|
2010-03-19 05:24:36 +00:00
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
|
|
|
|
dwStyle = WS_OVERLAPPEDWINDOW;
|
2010-11-14 01:38:10 +00:00
|
|
|
backbuffer.w = _width;
|
|
|
|
backbuffer.h = _height;
|
2010-03-19 05:24:36 +00:00
|
|
|
}
|
2010-09-19 08:01:48 +00:00
|
|
|
dwStyle |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
|
2010-03-19 05:24:36 +00:00
|
|
|
|
|
|
|
RECT rc;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
rc.left = 0;
|
|
|
|
rc.top = 0;
|
2011-06-12 22:07:59 +00:00
|
|
|
rc.right = backbuffer.w;
|
2010-11-14 01:38:10 +00:00
|
|
|
rc.bottom = backbuffer.h;
|
2010-05-01 23:34:44 +00:00
|
|
|
AdjustWindowRectEx(&rc, dwStyle, false, dwExStyle);
|
2010-05-01 20:33:53 +00:00
|
|
|
int X = (rcdesktop.right - rcdesktop.left) / 2 - (rc.right - rc.left) / 2;
|
|
|
|
int Y = (rcdesktop.bottom - rcdesktop.top) / 2 - (rc.bottom - rc.top) / 2;
|
2010-03-19 05:24:36 +00:00
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
SetWindowLong(NativeWindow, GWL_STYLE, dwStyle);
|
|
|
|
SetWindowLong(NativeWindow, GWL_EXSTYLE, dwExStyle);
|
2010-03-19 05:24:36 +00:00
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
SetWindowPos(NativeWindow, HWND_TOP, X, Y, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-06-19 06:23:40 +00:00
|
|
|
if (conf.fullscreen())
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-03-19 05:24:36 +00:00
|
|
|
DEVMODE dmScreenSettings;
|
2010-05-01 20:33:53 +00:00
|
|
|
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
|
|
|
|
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
|
2010-11-14 01:38:10 +00:00
|
|
|
dmScreenSettings.dmPelsWidth = backbuffer.w;
|
|
|
|
dmScreenSettings.dmPelsHeight = backbuffer.h;
|
2010-03-19 05:24:36 +00:00
|
|
|
dmScreenSettings.dmBitsPerPel = 32;
|
2010-05-01 20:33:53 +00:00
|
|
|
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
2010-03-19 05:24:36 +00:00
|
|
|
|
|
|
|
// Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
|
2010-03-19 05:24:36 +00:00
|
|
|
{
|
2010-12-25 04:38:44 +00:00
|
|
|
if (MessageBox(NULL,
|
|
|
|
L"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?",
|
|
|
|
L"NeHe GL",
|
|
|
|
MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
|
2010-06-19 06:23:40 +00:00
|
|
|
conf.setFullscreen(false);
|
2010-03-19 05:24:36 +00:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-19 05:24:36 +00:00
|
|
|
// change to default resolution
|
|
|
|
ChangeDisplaySettings(NULL, 0);
|
|
|
|
}
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
if (!OpenWGLDisplay()) return false;
|
|
|
|
|
|
|
|
if (!CreateContextGL()) return false;
|
|
|
|
|
|
|
|
UpdateWindow(NativeWindow);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GLWindow::OpenWGLDisplay()
|
|
|
|
{
|
|
|
|
GLuint PixelFormat; // Holds The Results After Searching For A Match
|
2010-05-01 20:33:53 +00:00
|
|
|
PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
|
|
|
|
|
2010-03-19 05:24:36 +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, // Must Support Double Buffering
|
|
|
|
PFD_TYPE_RGBA, // Request An RGBA Format
|
|
|
|
32, // Select Our Color Depth
|
|
|
|
0, 0, 0, 0, 0, 0, // Color Bits Ignored
|
|
|
|
0, // 8bit Alpha Buffer
|
|
|
|
0, // Shift Bit Ignored
|
|
|
|
0, // No Accumulation Buffer
|
|
|
|
0, 0, 0, 0, // Accumulation Bits Ignored
|
2010-04-25 00:31:27 +00:00
|
|
|
24, // 24Bit Z-Buffer (Depth Buffer)
|
2010-03-19 05:24:36 +00:00
|
|
|
8, // 8bit Stencil Buffer
|
|
|
|
0, // No Auxiliary Buffer
|
|
|
|
PFD_MAIN_PLANE, // Main Drawing Layer
|
|
|
|
0, // Reserved
|
|
|
|
0, 0, 0 // Layer Masks Ignored
|
|
|
|
};
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
if (!(NativeDisplay = GetDC(NativeWindow)))
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-12-25 04:38:44 +00:00
|
|
|
MessageBox(NULL, L"(1) Can't Create A GL Device Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
|
2010-03-19 05:24:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
if (!(PixelFormat = ChoosePixelFormat(NativeDisplay, &pfd)))
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-12-25 04:38:44 +00:00
|
|
|
MessageBox(NULL, L"(2) Can't Find A Suitable PixelFormat.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
|
2010-03-19 05:24:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
if (!SetPixelFormat(NativeDisplay, PixelFormat, &pfd))
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2010-12-25 04:38:44 +00:00
|
|
|
MessageBox(NULL, L"(3) Can't Set The PixelFormat.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
|
2010-03-19 05:24:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLWindow::CloseWGLDisplay()
|
|
|
|
{
|
|
|
|
if (NativeDisplay && !ReleaseDC(NativeWindow, NativeDisplay)) // Are We Able To Release The DC
|
2010-05-01 20:33:53 +00:00
|
|
|
{
|
2012-10-21 18:10:13 +00:00
|
|
|
MessageBox(NULL, L"Release Device Context Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
|
|
|
|
NativeDisplay = NULL; // Set DC To NULL
|
2010-03-19 05:24:36 +00:00
|
|
|
}
|
2012-10-21 18:10:13 +00:00
|
|
|
}
|
2010-03-19 05:24:36 +00:00
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
bool GLWindow::CreateContextGL()
|
|
|
|
{
|
|
|
|
return CreateContextGL(2, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GLWindow::CreateContextGL(int major, int minor)
|
|
|
|
{
|
|
|
|
if (major <= 2) {
|
|
|
|
if (!(wglContext = wglCreateContext(NativeDisplay)))
|
|
|
|
{
|
|
|
|
MessageBox(NULL, L"(4) Can't Create A GL Rendering Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wglMakeCurrent(NativeDisplay, wglContext))
|
|
|
|
{
|
|
|
|
MessageBox(NULL, L"(5) Can't Activate The GL Rendering Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// todo
|
2010-03-19 05:24:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 05:24:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLWindow::SwapGLBuffers()
|
|
|
|
{
|
|
|
|
static u32 lastswaptime = 0;
|
2010-11-09 12:04:07 +00:00
|
|
|
|
|
|
|
if (glGetError() != GL_NO_ERROR) ZZLog::Debug_Log("glError before swap!");
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
SwapBuffers(NativeDisplay);
|
2010-03-19 05:24:36 +00:00
|
|
|
lastswaptime = timeGetTime();
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 05:24:36 +00:00
|
|
|
void GLWindow::SetTitle(char *strtitle)
|
|
|
|
{
|
2012-10-21 18:10:13 +00:00
|
|
|
if (!conf.fullscreen()) SetWindowText(NativeWindow, wxString::FromUTF8(strtitle));
|
2010-03-19 05:24:36 +00:00
|
|
|
}
|
|
|
|
|
2010-11-09 12:04:07 +00:00
|
|
|
extern void ChangeDeviceSize(int nNewWidth, int nNewHeight);
|
|
|
|
|
|
|
|
void GLWindow::ProcessEvents()
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
ZeroMemory(&msg, sizeof(msg));
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
|
|
|
|
{
|
|
|
|
switch (msg.message)
|
|
|
|
{
|
|
|
|
case WM_KEYDOWN :
|
|
|
|
int my_KeyEvent = msg.wParam;
|
|
|
|
bool my_bShift = !!(GetKeyState(VK_SHIFT) & 0x8000);
|
|
|
|
|
|
|
|
switch (msg.wParam)
|
|
|
|
{
|
|
|
|
case VK_F5:
|
|
|
|
case VK_F6:
|
|
|
|
case VK_F7:
|
|
|
|
case VK_F9:
|
|
|
|
OnFKey(msg.wParam - VK_F1 + 1, my_bShift);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VK_ESCAPE:
|
|
|
|
|
|
|
|
if (conf.fullscreen())
|
|
|
|
{
|
|
|
|
// destroy that msg
|
|
|
|
conf.setFullscreen(false);
|
|
|
|
ChangeDeviceSize(conf.width, conf.height);
|
2012-10-21 18:10:13 +00:00
|
|
|
UpdateWindow(NativeWindow);
|
2010-11-09 12:04:07 +00:00
|
|
|
continue; // so that msg doesn't get sent
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-21 18:10:13 +00:00
|
|
|
SendMessage(NativeWindow, WM_DESTROY, 0, 0);
|
2010-11-09 12:04:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((GetKeyState(VK_MENU) & 0x8000) && (GetKeyState(VK_RETURN) & 0x8000))
|
|
|
|
{
|
|
|
|
conf.zz_options.fullscreen = !conf.zz_options.fullscreen;
|
|
|
|
|
2010-11-14 01:38:10 +00:00
|
|
|
SetDeviceSize(
|
2010-11-09 12:04:07 +00:00
|
|
|
(conf.fullscreen()) ? 1280 : conf.width,
|
|
|
|
(conf.fullscreen()) ? 960 : conf.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-21 18:10:13 +00:00
|
|
|
void* GLWindow::GetProcAddress(const char* function)
|
|
|
|
{
|
|
|
|
return (void*)wglGetProcAddress(function);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLWindow::InitVsync(bool extension)
|
|
|
|
{
|
|
|
|
vsync_supported = extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLWindow::SetVsync(bool enable)
|
|
|
|
{
|
|
|
|
if (vsync_supported) {
|
|
|
|
wglSwapIntervalEXT(0);
|
|
|
|
}
|
|
|
|
}
|
2010-11-09 12:04:07 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
#endif
|