Advertisement Jump to content
Sign in to follow this  

Basic Fullscreen mode problem

This topic is 4981 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hiya!! I am using openGL to do a small game, and I would like the game to always be fullscreen. However, when I start the app the window shows, but then the app closes with the error logged in my error logging that tells me I am crashing at ShowWindow(g_hWnd, nCmdShow); Here is my code: WinMain
WNDCLASSEX	winClass;				//Window class
    MSG			uMsg;
	DWORD		dwExStyle;				// Window Extended Style
	DWORD		dwStyle;				// Window Style
	RECT		WindowRect;				// Grabs Rectangle Upper Left / Lower Right Values
	int bits = 16;
	WindowRect.left = (long)0;				// Set Left Value To 0
	WindowRect.right = (long)SCREEN_WIDTH;	// Set Right Value To Requested Width = (long)0;				// Set Top Value To 0
	WindowRect.bottom = (long)SCREEN_HEIGHT;// Set Bottom Value To Requested Height

    memset(&uMsg, 0, sizeof(uMsg));

	winClass.lpszClassName = "MY_WINDOWS_CLASS";
    winClass.cbSize        = sizeof(WNDCLASSEX);         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    winClass.lpfnWndProc   = WindowProc;
    winClass.hInstance     = hInstance;
    winClass.hIcon         = LoadIcon(hInstance, (LPCTSTR)IDI_WINLOGO);
    winClass.hIconSm       = LoadIcon(hInstance, (LPCTSTR)IDI_WINLOGO);
    winClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
    winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    winClass.lpszMenuName  = NULL;
    winClass.cbClsExtra    = 0;
    winClass.cbWndExtra    = 0;
        return E_FAIL;

	//Fullscreen stuff
	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	= SCREEN_WIDTH;			// Selected Screen Width
	dmScreenSettings.dmPelsHeight	= SCREEN_HEIGHT;		// Selected Screen Height
	dmScreenSettings.dmBitsPerPel	= bits;					// Selected Bits Per Pixel

	// 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 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)
			return E_FAIL;		//Unable to start due to fullscreen issues.

	dwExStyle = WS_EX_APPWINDOW;	// Window Extended Style
	dwStyle = WS_POPUP;			// Windows Style
	ShowCursor(FALSE);			// Hide Mouse Pointer

    g_hWnd = CreateWindowEx(dwExStyle, 
                            dwStyle |							// Defined Window Style
							WS_CLIPSIBLINGS |					// Required Window Style
							WindowRect.right-WindowRect.left,	// Calculate Window Width,	// Calculate Window Height

    if(g_hWnd == NULL)
        return E_FAIL;
	//DEBUGGING LOG"Error Logs/log.txt", ios::out);

	//initialize OpenGL
    if(!vid.InitVideo(g_hDC, g_hRC, g_hWnd, &player1, &player2))
		return FALSE;

	//Generate Map and assign sprites to the their Entity's
		return FALSE;

	if(!ShowWindow(g_hWnd, nCmdShow))
		fout << "Show Error\n";
		return E_FAIL;
	SetForegroundWindow(g_hWnd);	// Slightly Higher Priority
GLuint PixelFormat;


    memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));

    pfd.nSize      = sizeof(PIXELFORMATDESCRIPTOR);
    pfd.nVersion   = 1;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 16;
    pfd.cDepthBits = 16;
    hDC = GetDC(hWnd);
	if(hDC == NULL)
		return FALSE;

    PixelFormat = ChoosePixelFormat(hDC, &pfd);
	if(!SetPixelFormat(hDC, PixelFormat, &pfd))
		return FALSE;
    hRC = wglCreateContext(hDC);
	if(!wglMakeCurrent(hDC, hRC))
		return FALSE;

		return FALSE;

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	glOrtho(0.0f, (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT, 0.0f, -1.0f, 1.0f);

	return TRUE;
I didn't know if I should post in openGL or not, so if a mod thinks I shouldn't be posting here I'm sorry!!

Share this post

Link to post
Share on other sites
I don't know about the rest of the code but ShowWindow does not return an error [grin]

from the docs:

Return Value

If the window was previously visible, the return value is nonzero.

If the window was previously hidden, the return value is zero.

Share this post

Link to post
Share on other sites
damn straight...
so why would my window just open and not be shown if I took out the failure portion of the code under ShowWindow()??

Share this post

Link to post
Share on other sites
I don't see why it wouldn't work (at least for the window not to show). Make sure you are passing both the device context and rendering context by reference to the InitVideo() function. Also what does your main loop look like? Try stepping through your code make sure you don't have any invalid pointers or anything like that [smile]

[Edited by - setaglib on May 31, 2005 2:36:06 AM]

Share this post

Link to post
Share on other sites
ok, well I have NO idea what the error was that initially started my problems, but one I took out the error clause after ShowWindow(), which I did not initially have in my code anyways, it worked out alright.

Can someone tell me what UpdateWindow() does???
I found that line in a tutorial and am not sure if I need it.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!