Something that's been bugging me for a while, and I finally decided to do something about it: fullscreen toggle never worked on Windows. I've now made the F key do a three-way toggle between lo-res (ie standard psp resolution), hi-res (psp resolution doubled, so 960 * 544), and fullscreen (well, not exactly fullscreen, it's a window sized to your desktop's work area; if you have a weird sized desktop, you might get clipping).

This commit is contained in:
wrenczes@gmail.com
2011-04-11 00:30:50 +00:00
parent 81f22b31f5
commit 98220afb46
3 changed files with 454 additions and 404 deletions
+1 -1
View File
@@ -250,7 +250,7 @@ typedef enum Buttons
JGE_BTN_NEXT, // Right trigger
JGE_BTN_FULLSCREEN, // Switch to fullscreen (obviously, PC only)
JGE_BTN_MAX = JGE_BTN_NEXT + 1
JGE_BTN_MAX = JGE_BTN_FULLSCREEN + 1
} JButton;
+5 -1
View File
@@ -118,7 +118,11 @@ void JGE::HoldKey_NoRepeat(const LocalKeySym sym)
else for (keycodes_it it = rng.first; it != rng.second; ++it)
{
#if defined (WIN32) || defined (LINUX)
if (JGE_BTN_FULLSCREEN == it->second) JGEToggleFullscreen();
if (JGE_BTN_FULLSCREEN == it->second)
{
JGEToggleFullscreen();
return;
}
#endif
keyBuffer.push(triplet(*it, true));
if (!held(it->second))
+102 -56
View File
@@ -135,8 +135,15 @@ HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=FALSE; // Windowed Mode By Default
enum eDisplayMode
{
DisplayMode_lowRes = 0,
DisplayMode_hiRes,
DisplayMode_fullscreen
};
unsigned int gDisplayMode = DisplayMode_lowRes;
DWORD lastTickCount;
@@ -156,8 +163,10 @@ JGameLauncher* g_launcher = NULL;
static u32 gButtons = 0;
static u32 gOldButtons = 0;
static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] =
{
static const struct { LocalKeySym keysym; JButton keycode; }
gDefaultBindings[] =
{
{ VK_CONTROL, JGE_BTN_CTRL },
{ VK_RETURN, JGE_BTN_MENU },
{ VK_ESCAPE, JGE_BTN_MENU },
@@ -176,7 +185,8 @@ static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[]
{ VK_SPACE, JGE_BTN_OK },
{ 'K', JGE_BTN_SEC },
{ 'J', JGE_BTN_PRI },
};
{ 'F', JGE_BTN_FULLSCREEN },
};
void JGECreateDefaultBindings()
{
@@ -304,9 +314,7 @@ void Update(float dt)
void KillGLWindow(void) // Properly Kill The Window
{
DestroyGame();
if (fullscreen) // Are We In Fullscreen Mode?
if (gDisplayMode == DisplayMode_fullscreen)
{
ChangeDisplaySettings(NULL,0); // If So Switch Back To The Desktop
ShowCursor(TRUE); // Show Mouse Pointer
@@ -342,16 +350,14 @@ void KillGLWindow(void) // Properly Kill The Window
/* This Code Creates Our OpenGL Window. Parameters Are: *
* title - Title To Appear At The Top Of The Window *
* width - Width Of The GL Window Or Fullscreen Mode *
* height - Height Of The GL Window Or Fullscreen Mode *
* bits - Number Of Bits To Use For Color (8/16/24/32) *
* fullscreenflag - Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE) */
BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
* bits - Number Of Bits To Use For Color (8/16/24/32) */
BOOL CreateGLWindow(char* title, int width, int height, int bits)
{
int actualScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
int actualScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
JRenderer::GetInstance()->SetActualWidth(static_cast<float>(width));
JRenderer::GetInstance()->SetActualWidth(static_cast<float>(height));
JRenderer::GetInstance()->SetActualHeight(static_cast<float>(height));
GLuint pixelFormat; // Holds The Results After Searching For A Match
@@ -363,18 +369,15 @@ BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscree
windowRect.left = (long) 0;
windowRect.top = (long) 0;
if (fullscreenflag == false)
if (gDisplayMode != DisplayMode_fullscreen)
{
windowRect.left = (::GetSystemMetrics(SM_CXSCREEN) - width) / 2;
windowRect.top = (::GetSystemMetrics(SM_CYSCREEN) - height) / 2;
windowRect.left = (actualScreenWidth - width) / 2;
windowRect.top = (actualScreenHeight - height) / 2;
}
windowRect.right = windowRect.left + (long)width; // Set Right Value To Requested Width
windowRect.bottom = windowRect.top + (long)height; // Set Bottom Value To Requested Height
fullscreen=fullscreenflag; // Set The Global Fullscreen Flag
hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages
@@ -393,23 +396,24 @@ BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscree
return FALSE; // Return FALSE
}
if (fullscreen) // Attempt Fullscreen Mode?
if (gDisplayMode == DisplayMode_fullscreen) // Attempt Fullscreen Mode?
{
DEVMODE dmScreenSettings; // Device Mode
memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
dmScreenSettings.dmPelsWidth = width; // Selected Screen Width
dmScreenSettings.dmPelsHeight = height; // Selected Screen Height
dmScreenSettings.dmPelsWidth = actualScreenWidth; // Selected Screen Width
dmScreenSettings.dmPelsHeight = actualScreenHeight; // Selected Screen Height
dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
// Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
LONG result = ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN);
if (result != DISP_CHANGE_SUCCESSFUL)
{
// If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode.
if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
{
fullscreen=FALSE; // Windowed Mode Selected. Fullscreen = FALSE
gDisplayMode = DisplayMode_lowRes; // Windowed Mode Selected.
}
else
{
@@ -420,7 +424,7 @@ BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscree
}
}
if (fullscreen) // Are We Still In Fullscreen Mode?
if (gDisplayMode == DisplayMode_fullscreen) // Are We Still In Fullscreen Mode?
{
dwExStyle=WS_EX_APPWINDOW; // Window Extended Style
dwStyle=WS_POPUP; // Windows Style
@@ -443,6 +447,9 @@ BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscree
AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size
// Create The Window
if (hWnd == NULL)
{
if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window
"OpenGL", // Class Name
title, // Window Title
@@ -461,6 +468,7 @@ BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscree
MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
}
static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
{
@@ -531,17 +539,11 @@ BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscree
return FALSE; // Return FALSE
}
if (!InitGame()) // Initialize Our Game
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Game Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
return TRUE; // Success
}
LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
LRESULT CALLBACK WndProc(
HWND hWnd, // Handle For This Window
UINT uMsg, // Message For This Window
WPARAM wParam, // Additional Message Information
LPARAM lParam) // Additional Message Information
@@ -627,7 +629,6 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
case WM_SIZE: // Resize The OpenGL Window
{
ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); // LoWord=Width, HiWord=Height
return 0; // Jump Back
}
@@ -639,10 +640,65 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
bool JGEToggleFullscreen()
{
return false; // Not implemented under windows
//cycle between the display modes
++gDisplayMode;
if (gDisplayMode > DisplayMode_fullscreen)
gDisplayMode = DisplayMode_lowRes;
int width = 0, height = 0;
RECT workArea;
// get the useable screen area (ie not including the windows taskbar, etc
SystemParametersInfo( SPI_GETWORKAREA, 0, (PVOID)&workArea, 0);
int actualScreenWidth = workArea.right - workArea.left;
int actualScreenHeight = workArea.bottom - workArea.top;
switch (gDisplayMode)
{
case DisplayMode_fullscreen:
width = actualScreenWidth;
height = actualScreenHeight;
break;
case DisplayMode_hiRes:
width = SCREEN_WIDTH * 2;
height = SCREEN_HEIGHT * 2;
break;
case DisplayMode_lowRes:
default:
width = SCREEN_WIDTH;
height = SCREEN_HEIGHT;
break;
}
int x = workArea.left + ((actualScreenWidth - width) / 2);
int y = workArea.top + ((actualScreenHeight - height) / 2);
DWORD dwStyle;
DWORD dwExStyle = WS_EX_APPWINDOW;
if (gDisplayMode != DisplayMode_fullscreen)
{
dwStyle |= WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU;
dwExStyle |= WS_EX_WINDOWEDGE;
}
RECT windowRect;
windowRect.left = x;
windowRect.top = y;
windowRect.right = windowRect.left + width;
windowRect.bottom = windowRect.top + height;
AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
SetWindowPos(hWnd, NULL, windowRect.left, windowRect.top, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, 0);
ReSizeGLScene(width, height);
return true;
}
int WINAPI WinMain( HINSTANCE hInstance, // Instance
int WINAPI WinMain(
HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
@@ -653,12 +709,6 @@ int WINAPI WinMain( HINSTANCE hInstance, // Instance
DWORD tickCount;
int dt;
// Ask The User Which Screen Mode They Prefer
// if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
// {
// fullscreen=FALSE; // Windowed Mode
// }
g_launcher = new JGameLauncher();
u32 flags = g_launcher->GetInitFlags();
@@ -669,11 +719,18 @@ int WINAPI WinMain( HINSTANCE hInstance, // Instance
JRenderer::Set3DFlag(true);
// Create Our OpenGL Window
if (!CreateGLWindow(g_launcher->GetName(),SCREEN_WIDTH,SCREEN_HEIGHT,32,fullscreen))
if (!CreateGLWindow(g_launcher->GetName(),SCREEN_WIDTH,SCREEN_HEIGHT,32))
{
return 0; // Quit If Window Was Not Created
}
if (!InitGame()) // Initialize Our Game
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Game Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
while(!done) // Loop That Runs While done=FALSE
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
@@ -708,18 +765,6 @@ int WINAPI WinMain( HINSTANCE hInstance, // Instance
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
}
}
// if (keys[VK_F1]) // Is F1 Being Pressed?
// {
// keys[VK_F1]=FALSE; // If So Make Key FALSE
// KillGLWindow(); // Kill Our Current Window
// fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode
// // Recreate Our OpenGL Window
// if (!CreateGLWindow("NeHe's OpenGL Framework",640,480,16,fullscreen))
// {
// return 0; // Quit If Window Was Not Created
// }
// }
}
}
@@ -727,6 +772,7 @@ int WINAPI WinMain( HINSTANCE hInstance, // Instance
delete g_launcher;
// Shutdown
DestroyGame();
KillGLWindow(); // Kill The Window
return (msg.wParam); // Exit The Program
}