Fullscreen question

Started by
6 comments, last by bobby_nguyen 15 years, 6 months ago
Hi all again, I'm trying to get fullscreen to work on my little program. The fullscreen works, but it seems that my viewport / viewpoint changes. When I don't pass "ws_popup", the scene is moving correctly. When it is passed, it looks like I'm really close to the horizon.

if (fullScreen)												// Are We Still In Fullscreen Mode?
	{
		dwExStyle =WS_EX_APPWINDOW;								// Window Extended Style
		dwStyle=WS_POPUP;										// Windows Style
		ShowCursor(FALSE);										// Hide Mouse Pointer
	}
	else
	{
		dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended Style
		dwStyle=WS_OVERLAPPEDWINDOW;							// Windows Style
	}

	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);	// Adjust Window To True Requested Size
   
	hwnd = CreateWindowEx(	dwExStyle,							// Extended Style For The Window
							"OpenGL",							// Class Name
							szTitle,							// Window Title
							dwStyle |							// Defined Window Style
							WS_CLIPSIBLINGS |					// Required Window Style
							WS_CLIPCHILDREN,					// Required Window Style
							0,0,								// Window Position
							1280,	// Calculate Window Width
							1024,	// Calculate Window Height
							NULL,								// No Parent Window
							NULL,								// No Menu
							hInstance,							// Instance
							NULL);								// Dont Pass Anything To WM_CREATE


[Edited by - bobby_nguyen on November 13, 2008 3:40:35 PM]
Advertisement
So changing the line:
dwstyle=WS_OVERLAPPEDWINDOW;
to:
dwstyle=WS_POPUP;
And nothing else causes the problem you describe? Any chance of a screenshot?
Sure. thanks for the quick reply btw.
*When I set the first instance of "dwstyle" = NULL, I get the view I want, but there are borders and buttons.
code:
 if (fullScreen)												// Are We Still In Fullscreen Mode?	{		dwExStyle =WS_EX_APPWINDOW;								// Window Extended Style		dwStyle= NULL;										// Windows Style		ShowCursor(FALSE);										// Hide Mouse Pointer	}	else	{		dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended Style		dwStyle=WS_OVERLAPPEDWINDOW;							// Windows Style	}


Screenshot:


When I change it to WS_POPUP, I get the borderless, buttonless effect I want, but the viewpoint changes. You can see a few dots moving across the bottom.

Code:
 if (fullScreen)												// Are We Still In Fullscreen Mode?	{		dwExStyle =WS_EX_APPWINDOW;								// Window Extended Style		dwStyle=WS_POPUP;										// Windows Style		ShowCursor(FALSE);										// Hide Mouse Pointer	}	else	{		dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended Style		dwStyle=WS_OVERLAPPEDWINDOW;							// Windows Style	}


Screenshot:
That seems really odd. Is it possible that your projection or frustum is getting changed? Maybe you take the window dimensions and use them as arguments to some of your matrices?

I have OpenGL Windowing code at home that behaves as expected. If you haven't solved it before I get off work I'll take a look and let you know how I'm doing it.

throw table_exception("(? ???)? ? ???");

Thanks,
I'll be leaving my office here in a few minutes. I have not been able to figure it out. You may have a point with the projection changing.

Here is my Reshape function:
void ReshapeScene(int nWidth, int nHeight){	if (nHeight == 0)	{	  nHeight = 1;	}	nWidth = windW;	nHeight= windH;	glViewport(0, 0,windW, windH);	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	gluOrtho2D(-display_width/2, display_width/2, -display_width/2*windH/windW, display_width/2*windH/windW);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	return;}
Ok, so I'm looking at my code, and I use the same Windowstyle and WindowstyleEX settings that you are, so that's an unlikely culprit. I'm going to say that there's likely something wrong with how you're setting up your matrices and how that process is affected by the window size.

Particularly, I'm kind of concerned over the reshape code you posted... Its pretty seriously jacked up. I mean, you're taking in two parameters, comparing one to 0, and if it is, setting it to 1... Then you immediately set the two parameters equal to two other, presumably global, variables -- and then they're never touched again, prefering instead to use those same global variables that supplied the new values, and then you even bring in a third presumably global variable just for good measure... This is all very bad mojo, and its certainly not helping anything; it smells of "its not working, so I'll make random changes until it looks right"-syndrome.

Also, on another matter, from the code in the initial post, you should not be passing the window height and window width to CreateWindowEX as const literals... you need to be passing the adjusted window size. You can see how I do it in the Win32Window::Initialize code below. I would be inclined to fix that first, since its low-hanging fruit that might bear signifigant responsibility for the problem you're seeing.


Like I said, I suspect that there may (also?) be issues with the matrices in your transformation stages, which I can't do much to help you with. But here is my window setup and resizing code, just so you can look through it and see if you can pick out any more obvious errors. (Not that I'm claiming my code to be perfect either, but it works well for me and is correct to the best of my knowledge and efforts.)

GLWindow::Initialize code:
/// ****************************************************************************/// <summary>Creates and registers an application window for use with OpenGL.</summary>/// <param name="ClassName">The name used to register the window class.</param>/// <param name="Caption">The title given to the window at its creation.</param>/// <param name="WindowSettings">A collection of window settings used at its creation.</param>/// <param name="hInstance">The HINSTANCE of the windows application.</param>/// <param name="lpfnWndProc">The Address of the WNDPROC function.</param>/// <param name="lpCreateParam">The extra parameter passed by the CreateWindowEx/// function through the WM_CREATE message's lParam./// <returns>A boolean containing true if initialization was successful, otherwise/// false.</returns>bool GLWindow::Initialize(const std::wstring ClassName, const std::wstring Caption, const WindowSettings WindowSettings, HINSTANCE hInstance, WNDPROC lpfnWndProc, long * lpCreateParam){	// Attempt to initialize basic Win32 window and bail early if we fail.	if (!Win32Window::Initialize(ClassName, Caption, WindowSettings, hInstance, lpfnWndProc, lpCreateParam))		return false;	// Attempt to acquire a device context	mDeviceContextHandle = GetDC(Win32Window::GetWindowHandle());	if (!mDeviceContextHandle)	{		MessageBox(NULL, TEXT("Cannot create a GL device context."), TEXT("Error"), MB_OK | MB_ICONEXCLAMATION);		Destroy(hInstance);		return false;	}	// Define our desired pixel format.	PIXELFORMATDESCRIPTOR pfd; 			std::fill_n(reinterpret_cast<byte *>(&pfd), sizeof(pfd), 0);      // Make sure memory is cleared	pfd.nSize       = sizeof(pfd);          // Size of PIXELFORMATDESCRIPTOR	pfd.nVersion    = 1;                    // Version	pfd.dwFlags     = PFD_DRAW_TO_WINDOW |  // Format must support window	                  PFD_SUPPORT_OPENGL |  // Format must support OpenGL	                  PFD_DOUBLEBUFFER;     // Must support double buffering	pfd.iPixelType  = PFD_TYPE_RGBA;        // Request an RGBA format	pfd.cColorBits  = WindowSettings.BPP;   // Select our color depth	pfd.cDepthBits  = 16;                   // 16Bit depth buffer 	pfd.dwLayerMask = PFD_MAIN_PLANE;       // Main drawing layer (ignored by modern OpenGL)	// Check for a compatible pixel format.	GLuint pixelFormat = ChoosePixelFormat(mDeviceContextHandle, &pfd);	if (!pixelFormat)	{		MessageBox(NULL, TEXT("Cannot find a suitable pixel format."), TEXT("Error"), MB_OK | MB_ICONEXCLAMATION);		Destroy(hInstance);		return false;	}	// Attempt to set the pixel format.	if (!SetPixelFormat(mDeviceContextHandle, pixelFormat, &pfd))	{		MessageBox(NULL, TEXT("Cannot set the pixel format."), TEXT("Error"), MB_OK | MB_ICONEXCLAMATION);		Destroy(hInstance);		return false;	}	// Attempt to acquire an OpenGL context.	mOpenGLContextHandle = wglCreateContext(mDeviceContextHandle);	if (!mOpenGLContextHandle)	{		MessageBox(NULL, TEXT("Cannot create an OpenGL rendering context."), TEXT("Error"), MB_OK | MB_ICONEXCLAMATION);		Destroy(hInstance);		return false;	}	// Attempt to activate the OpenGL context.	if (!wglMakeCurrent(mDeviceContextHandle, mOpenGLContextHandle))	{		MessageBox(NULL, TEXT("Cannot activate the OpenGL rendering context."), TEXT("Error"), MB_OK | MB_ICONEXCLAMATION);		Destroy(hInstance);		return false;	}	return true;}


Win32Window::Initialize code:
/// ****************************************************************************/// <summary>Creates and registers a Win32 application window.</summary>/// <param name="ClassName">The name used to register the window class.</param>/// <param name="Caption">The title given to the window at its creation.</param>/// <param name="WindowSettings">A collection of window settings used at its creation.</param>/// <param name="hInstance">The HINSTANCE of the windows application.</param>/// <param name="lpfnWndProc">The Address of the WNDPROC function.</param>/// <param name="lpCreateParam">The extra parameter passed by the CreateWindowEx/// function through the WM_CREATE message's lParam./// <returns>A boolean containg true if initialization was successful, otherwise/// false.</returns>bool Win32Window::Initialize(const std::wstring ClassName, const std::wstring Caption, const WindowSettings WindowSettings, HINSTANCE hInstance, WNDPROC lpfnWndProc, long * lpCreateParam){	WNDCLASS wc;                                              // Windows Class Structure	DWORD    dwExStyle;	DWORD    dwStyle;	mWindowClassName = ClassName;	mWindowCaption   = Caption;	mWindowSettings  = WindowSettings;	wc.hInstance     = hInstance;                             // Set the Instance	wc.lpszClassName = mWindowClassName.c_str();              // Set the Class Name	wc.lpszMenuName  = NULL;                                  // Set the Defualt Menu	wc.lpfnWndProc   = lpfnWndProc;                           // Set the Window Proc	wc.style         = CS_VREDRAW | CS_HREDRAW;               // Redraw On Move	wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);    // No Background Required	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);           // Load The Arrow Pointer	wc.hIcon         = LoadIcon(NULL, IDI_WINLOGO);           // Load The Default Icon	wc.cbClsExtra    = NULL;                                  // No Extra Window Data	wc.cbWndExtra    = NULL;                                  // No Extra Window Data	// Attempt to register the window class	if (!RegisterClass(&wc))	{		MessageBox(NULL, TEXT("Failed to register the window class."), TEXT("Error"), MB_OK | MB_ICONEXCLAMATION);		return FALSE;	}	if (mWindowSettings.Fullscreen)	{		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    = mWindowSettings.Width;    // Selected Screen Width		dmScreenSettings.dmPelsHeight   = mWindowSettings.Height;   // Selected Screen Height		dmScreenSettings.dmBitsPerPel   = mWindowSettings.BPP;      // 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)		{			if(MessageBox(NULL, TEXT("The requested fullscreen mode es not supported by\nyour video card. Use windowed mode instead?"), TEXT("Fullscreen mode not supported"), MB_YESNO | MB_ICONEXCLAMATION) == IDYES)			{				mWindowSettings.Fullscreen = false;			}			else			{				MessageBox(NULL, TEXT("Video mode not supported."), TEXT("Notice"), MB_OK);				return false;			}		}	}	if(mWindowSettings.Fullscreen)	{		// Set fullscreen window appearance		dwExStyle = WS_EX_APPWINDOW;                    // Window Extended Style		dwStyle = WS_POPUP;                             // Windows Style		ShowCursor(false);                              // Hide Mouse Pointer	}	else	{		// Set windowed window appearance		dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style		dwStyle = WS_OVERLAPPEDWINDOW;                  // Windows Style	}	//	RECT WindowRect;	WindowRect.left     = (long)0;                      // Set Left Value To 0	WindowRect.right    = (long)mWindowSettings.Width;  // Set Right Value To Requested Width	WindowRect.top      = (long)0;                      // Set Top Value To 0	WindowRect.bottom   = (long)mWindowSettings.Height; // Set Bottom Value To Requested Height	// Adjust Window To True Requested Size	AdjustWindowRectEx(&WindowRect, dwStyle, false, dwExStyle);	// Attempt to create the window	mWindowHandle = CreateWindowEx(WS_EX_TOPMOST | dwExStyle,   // Extended style	                        mWindowClassName.c_str(),           // Class Name	                        mWindowCaption.c_str(),             // Window Title	                        WS_CLIPSIBLINGS | WS_CLIPCHILDREN | // Required Window Style	                        dwStyle,                            // Selected Window Style	                        0, 0,                               // Window Position	                        WindowRect.right - WindowRect.left, // Calculate Adjusted Window Width	                        WindowRect.bottom - WindowRect.top, // Calculate Adjusted Window Height	                        NULL,                               // No Parent Window	                        NULL,                               // No Default Window	                        hInstance,                          // Instance	                        lpCreateParam);                     // Pass App so we can access it from Win32App::StaticWndProc	if (!mWindowHandle)	{		MessageBox(NULL, TEXT("Window creation error."), TEXT("Error"), MB_OK | MB_ICONEXCLAMATION);		Destroy(hInstance);		return false;	}	ShowWindow(mWindowHandle, SW_SHOW); // Show The Window	SetForegroundWindow(mWindowHandle); // Slightly Higher Priority	SetFocus(mWindowHandle);            // Sets Keyboard Focus To The Window    return true;}


GLApp::Resize code:
void GLApp::Resize(const WindowSettings Settings){	// Assert on divide by zero	assert(Settings.Height != 0);	// Resize the viewport	glViewport(0, 0, Settings.Width, Settings.Height);	// Reset projection matrix	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	// Reset perspective	gluPerspective(45.0f, (GLfloat)Settings.Width / (GLfloat)Settings.Height, 0.1f, 100.0f);	// Reset the model-view matrix	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();}


[Edited by - Ravyne on November 14, 2008 3:51:27 AM]

throw table_exception("(? ???)? ? ???");

Thanks for your great help. I know my code is jacked. I'm trying to convert old GLUT code to WinAPI, and incorporate DirectInput, and it's been a bumpy road. I will try to clean up my code to your suggestions and will let you know how that goes.
Sweet dude. I followed a few of your suggestions and removed some unnecessary variables. I removed the gluPerspective function and added my ReshapeScene function into my Winmain function. Got it working now.

thanks a million.

This topic is closed to new replies.

Advertisement