GLWindow

void GLWindow::terminateApplication()

terminateApplication gets called when you want to shut the window down. It simply posts the quit message and says to stop looping.

void
GLWindow::terminateApplication()
{
PostMessage(hWnd, WM_QUIT, 0, 0);
isProgramLooping = false;
}

void GLWindow::toggleFullscreen()

toggleFullscreen is done differently than NeHe’s code that I’m using. The code on NeHe’s site posted a fullscreen message, destroyed the window, then created a fullscreen window calling the initializtion function again. I just resize the current window and change it’s attributes. It also keeps track of window position and size, so when we leave fullscreen mode, the window is restored correctly.

void
GLWindow::toggleFullscreen()
{
static long wndStyles;
static long wndExStyles;
static RECT windowRect = {0, 0, starting_width, starting_height};

if(isFullScreen)
{
SetWindowLong(hWnd, GWL_STYLE, wndStyles);
SetWindowLong(hWnd, GWL_EXSTYLE, wndExStyles);

SetWindowPos(hWnd, HWND_TOPMOST,windowRect.left,windowRect.top,
windowRect.right - windowRect.left, windowRect.bottom - windowRect.top,SWP_SHOWWINDOW);

current_width = starting_width;
current_height = starting_height;
}
else
{
wndStyles = GetWindowLong(hWnd, GWL_STYLE);
wndExStyles = GetWindowLong(hWnd, GWL_EXSTYLE);
GetWindowRect(hWnd, &windowRect);

SetWindowLong(hWnd, GWL_STYLE,WS_POPUP);

SetWindowPos(hWnd, HWND_TOPMOST,0,0,GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN),SWP_SHOWWINDOW);

current_width = GetSystemMetrics(SM_CXSCREEN);
current_height = GetSystemMetrics(SM_CYSCREEN);
}

isFullScreen = !isFullScreen;
}

bool GLWindow::changeScreenResolution(int width, int height, int bitsPerPixel)

changeScreenResolution is used to create the window. I have no idea why would ever need it outside of that method, but here you go.

bool
GLWindow::changeScreenResolution(int width, int height, int bitsPerPixel)
{
DEVMODE dmScreenSettings;
ZeroMemory(&dmScreenSettings, sizeof(DEVMODE));
dmScreenSettings.dmSize = sizeof(DEVMODE);
dmScreenSettings.dmPelsWidth = width;
dmScreenSettings.dmPelsHeight = height;
dmScreenSettings.dmBitsPerPel = bitsPerPixel;
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
return false;
}

this->starting_width = width; this->current_width = width;
this->starting_height = height; this->current_height = height;
return true;
}

Pages: 1 2 3 4 5 6 7 8

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>