Hi,
A strange bug occurs when I try to create a fullscreen window.
The function that creates the window returns an instace of the ZWindow struct which is defined as following:
/*!
* \brief Holds minimal window information.
*/
typedef struct ZWindow
{
HWND hwnd; /*!< Window handle. */
HINSTANCE hInstance; /*!< Application instance. */
HDC hDC; /*!< Device context. */
HGLRC hRC; /*!< OpenGL rendering context. */
BOOL active; /*!< Window active flag. */
BOOL fullscreen; /*!< Fullscreen flag. */
char *title; /*!< Title of the window. */
int error_code; /*!< Holds the error code. */
int width; /*!< Width of the window. */
int height; /*!< Height of the window. */
}ZWindow;
The function itself is:
/*! \param title The window title.
* \param width Width of the window, in pixels.
* \param height Height of the window in pixels.
* \param bits Colordepth of the new window.
* \param fullscreen Fullscreen flag.
* \return A ZWindow object with the information of the newly created window.
* \bug Fullscreen mode does NOT work...
*/
ZWindow CreateGLWindow(const char *title, int width, int height, int bits, BOOL fullscreen)
{
GLuint PixelFormat;
DWORD ExStyle;
DWORD Style;
RECT WindowRect;
ZWindow window;
WindowRect.left = (long)0;
WindowRect.right = (long)width;
WindowRect.top = (long)0;
WindowRect.bottom = (long)height;
window.title = (char *)GlobalAlloc(GMEM_FIXED, strlen(title) + 1);
strcpy(window.title, title);
window.width = width;
window.height = height;
window.hInstance = GetModuleHandle(NULL);
if(fullscreen) // Attempt Fullscreen Mode?
{
DEVMODE ScreenSettings; // Device Mode
memset(&ScreenSettings, 0, sizeof(ScreenSettings)); // Makes Sure Memory's Cleared
ScreenSettings.dmSize=sizeof(ScreenSettings); // Size Of The Devmode Structure
ScreenSettings.dmPelsWidth = width; // Selected Screen Width
ScreenSettings.dmPelsHeight = height; // Selected Screen Height
ScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel
ScreenSettings.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(&ScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
window.error_code = ZGL_ERROR_INVALID_GRAPHICS_MODE;
return window;
}
ExStyle = WS_EX_APPWINDOW; // Window Extended Style
Style = WS_POPUP; // Windows Style
ShowCursor(FALSE); // Hide Mouse Pointer
}
else
{
ExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
Style = WS_OVERLAPPEDWINDOW; // Windows Style
}
window.fullscreen = fullscreen;
AdjustWindowRectEx(&WindowRect, Style, FALSE, ExStyle); // Adjust Window To True Requested Size
// Create The Window
if (!(window.hwnd=CreateWindowEx(ExStyle, ZGL_CLASS_NAME, title, Style | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
0, 0,WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, NULL, NULL,
window.hInstance, NULL)))
{
if(fullscreen == TRUE)
ChangeDisplaySettings(NULL, 0);
window.error_code = ZGL_ERROR_CRETATION_FAILURE;
return window; // Return FALSE
}
static 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, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
bits, // 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
};
if((window.hDC = GetDC(window.hwnd)) == NULL) // Try to get a device context
{
window.error_code = ZGL_ERROR_DC_CREATION_FAILURE;
return window;
}
if (!(PixelFormat = ChoosePixelFormat(window.hDC, &pfd))) // Choose pixel format
{
window.error_code = ZGL_ERROR_INVALID_PIXEL_FORMAT;
return window;
}
if(!SetPixelFormat(window.hDC, PixelFormat, &pfd))
{
window.error_code = ZGL_ERROR_INVALID_PIXEL_FORMAT;
return window;
}
if (!(window.hRC = wglCreateContext(window.hDC))) // Create an OpenGL rendering context
{
window.error_code = ZGL_ERROR_RC_CREATION_FAILURE;
return window;
}
ShowWindow(window.hwnd, SW_SHOW); // Show The Window
SetForegroundWindow(window.hwnd); // Slightly Higher Priority
SetFocus(window.hwnd); // Sets Keyboard Focus To The Window
window.error_code = ZGL_ERROR_NONE; // Success
return window; // Return created window information
}
The bug occures if the fullscreen parameter is set to TRUE. Its not easy to describe it. Try it yourself.
Thanks in advance for any help.