Archived

This topic is now archived and is closed to further replies.

Guzba

window now full screening or something

Recommended Posts

Guzba    122

  
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>

#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glaux.lib")

#define SCREEN_W 800
#define SCREEN_H 600
#define SCREEN_D 16

typedef struct {
	
	bool space;
	bool enter;

	bool north;
	bool south;

	bool east;
	bool west;

	bool active;
	bool escape;

} key;

key input = {FALSE,
			 FALSE,
			 FALSE,
			 FALSE,
			 FALSE,
			 FALSE,
			 TRUE,
			 FALSE};

bool keys[256];

HGLRC           hRC		=	NULL;
HDC             hDC		=	NULL;
HWND            hWnd	=	NULL;
HINSTANCE       hInstance;

LRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

void killWindow(void)
{
	ChangeDisplaySettings(NULL, 0);
	ShowCursor(TRUE);

	if(hRC)
	{
		if(!wglMakeCurrent(NULL, NULL))
		{
			MessageBox(NULL, "Release Of DC And RC Failed", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
		}

		if(!wglDeleteContext(hRC))
		{
			MessageBox(NULL, "Release Rendering Context Failed", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
		}
		hRC = NULL;
	}

	if(hDC && !ReleaseDC(hWnd, hDC))
	{
		MessageBox(NULL, "Release Device Context Failed", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
		hDC = NULL;
	}

	if(hWnd && !DestroyWindow(hWnd))
	{
		MessageBox(NULL, "Could Not Release hWnd", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
		hWnd = NULL;
	}

	if(!UnregisterClass("Space", hInstance))
	{
		MessageBox(NULL, "Could Not Unregister Class", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
		hInstance = NULL;
	}

}

bool createWindow()
{
	WNDCLASS Window;

	int pixelFormat;

	DWORD dwExStyle;
	DWORD dwStyle;

	RECT WindowRect;
	WindowRect.left		=(long)0;
	WindowRect.right	=(long)SCREEN_H;
	WindowRect.top		=(long)0;
	WindowRect.bottom	=(long)SCREEN_W;	

	hInstance				= GetModuleHandle(NULL);
	Window.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	Window.lpfnWndProc		= (WNDPROC) WndProc;
	Window.cbClsExtra		= 0;
	Window.cbWndExtra		= 0;
	Window.hInstance		= hInstance;
	Window.hIcon			= LoadIcon(NULL, IDI_WINLOGO);
	Window.hCursor			= LoadCursor(NULL, IDC_ARROW);
	Window.hbrBackground	= NULL;
	Window.lpszMenuName		= NULL;
	Window.lpszClassName	= "Space";

	if(!RegisterClass(&Window))
	{
		MessageBox(NULL, "Failed To Register The Window Class", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	DEVMODE dmScreenSettings;
	memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
	dmScreenSettings.dmSize = sizeof(dmScreenSettings);
	dmScreenSettings.dmPelsHeight	= SCREEN_H;
	dmScreenSettings.dmPelsWidth	= SCREEN_W;
	dmScreenSettings.dmBitsPerPel	= SCREEN_D;
	dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

	if(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
	{
		return FALSE;
	}

	dwExStyle	=	WS_EX_APPWINDOW;
	dwStyle		=	WS_POPUP;
	ShowCursor(FALSE);

	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);

	if(!(hWnd=CreateWindowEx(dwExStyle,
							 "Space",
							 "Space Quest",
							 WS_CLIPSIBLINGS |
							 WS_CLIPCHILDREN |
							 dwStyle,
							 0, 0,
							 WindowRect.right-WindowRect.left,
							 WindowRect.bottom-WindowRect.top,
							 NULL,
							 NULL,
							 hInstance,
							 NULL)))
	{
		killWindow();
		MessageBox(NULL, "Window Creation Error", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	static PIXELFORMATDESCRIPTOR pfd =
	{
		sizeof(PIXELFORMATDESCRIPTOR),
		1,
		PFD_DRAW_TO_WINDOW |
		PFD_SUPPORT_OPENGL |
		PFD_DOUBLEBUFFER,
		PFD_TYPE_RGBA,
		SCREEN_D,
		0, 0, 0, 0, 0, 0,
		0,
		0,
		0,
		0, 0, 0, 0,
		16,
		0,
		0,
		PFD_MAIN_PLANE,
		0,
		0, 0, 0
	};

	if (!(hDC = GetDC(hWnd)))
	{
		killWindow();
		MessageBox(NULL, "Can''t Create A GL Device Context", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	if (!(pixelFormat = ChoosePixelFormat(hDC, &pfd)))
	{
		killWindow();
		MessageBox(NULL, "Can''t Find A Suitable PixelFormat", "ERROR",MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	if(!SetPixelFormat(hDC, pixelFormat, &pfd))
	{
		killWindow();
		MessageBox(NULL, "Can''t Set The PixelFormat", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	if (!(hRC = wglCreateContext(hDC)))
	{
		killWindow();
		MessageBox(NULL, "Can''t Create A GL Rendering Context", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	if(!wglMakeCurrent(hDC, hRC))
	{
		killWindow();
		MessageBox(NULL, "Can''t Activate The GL Rendering Context", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	ShowWindow(hWnd, SW_SHOW);
	SetForegroundWindow(hWnd);
	SetFocus(hWnd);

	return TRUE;
}

LRESULT CALLBACK WndProc(HWND	hWnd,
						 UINT	uMsg,
						 WPARAM	wParam,	
						 LPARAM	lParam)
{
	switch (uMsg)
	{
		case WM_ACTIVATE:
		{
			if (!HIWORD(wParam))
			{
				input.active = TRUE;
			}
			else
			{
				input.active = FALSE;
			}

			return 0;
		}

		case WM_SYSCOMMAND:
		{
			switch (wParam)
			{
				case SC_SCREENSAVE:
				case SC_MONITORPOWER:
				return 0;
			}
			break;
		}

		case WM_CLOSE:
		{
			PostQuitMessage(0);
			return 0;
		}

		case WM_KEYDOWN:
		{
			keys[wParam] = TRUE;
			return 0;
		}

		case WM_KEYUP:
		{
			keys[wParam] = FALSE;
			return 0;
		}
	}

	return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

int WINAPI WinMain(HINSTANCE hInstance,
				   HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine,
				   int nShowCmd)
{
	MSG		msg;
	bool	esc = FALSE;

	if (!createWindow())
	{
		return 0;
	}

	while(!input.escape)
	{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if (msg.message == WM_QUIT)
			{
				input.escape = TRUE;
			}
			else
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
		else
		{
			if (input.active)
			{
				if (keys[VK_ESCAPE])
				{
					input.escape = TRUE;
				}
				else
				{
					SwapBuffers(hDC);
				}
			}
		}
	}
	killWindow();
	return (msg.wParam);	
}
  
Ok, this is just the windows basecode i made but for some reason when i want it to full screen all it goes to it but it only makes about 3/4 of the screen go black, and one side still shows the windows and the bar is still on the bottom!! heres a picture: http://www.guzba.com/openglerror/error.jpg hehe, thanx

Share this post


Link to post
Share on other sites
morebeer    122
these lines:

WindowRect.left =(long)0;
WindowRect.right =(long)SCREEN_H;
WindowRect.top =(long)0;
WindowRect.bottom =(long)SCREEN_W;


shouldn''t SCREEN_W AND SCREEN_H be the other way around? ChangeDisplaySettings wont work if you give it 600x800...

Share this post


Link to post
Share on other sites
Burning_Ice    122
hmm usually you first create the window and then change the screen mode. you also have to create your window with WS_POPUP style.
and there could also be a problem with you not filling in the monitor frequenzy of the devmode. i usually put the line
EnumDisplaySettings ( NULL, 0, &dmScreenSettings );
instead of your
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
there, so that the devmode will be filled with the current screen res and monitor frequenzy, and then just change the res.

hope that helps


My Homepage

Share this post


Link to post
Share on other sites
Guzba    122
Ok, you gave quite a lot of information there and im just wondering, how do i do all that? i just took the NEHE basecode and rid it of the fullscreen option and edited a bit so i dont know all that much of what im doing :O. Could you show a few examples of where i should change if you dont mind?

Share this post


Link to post
Share on other sites
Burning_Ice    122
ok i changed your code so that it should work:


  

#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>

#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glaux.lib")

#define SCREEN_W 800
#define SCREEN_H 600
#define SCREEN_D 16





typedef struct {

bool space;
bool enter;

bool north;
bool south;

bool east;
bool west;

bool active;
bool escape;

} key;

key input = {FALSE,
FALSE,
FALSE,
FALSE,
FALSE,
FALSE,
TRUE,
FALSE};

bool keys[256];

HGLRC hRC = NULL;
HDC hDC = NULL;
HWND hWnd = NULL;
HINSTANCE hInstance;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

void killWindow(void)
{
ChangeDisplaySettings(NULL, 0);
ShowCursor(TRUE);

if(hRC)
{
if(!wglMakeCurrent(NULL, NULL))
{
MessageBox(NULL, "Release Of DC And RC Failed", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
}

if(!wglDeleteContext(hRC))
{
MessageBox(NULL, "Release Rendering Context Failed", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
}
hRC = NULL;
}

if(hDC && !ReleaseDC(hWnd, hDC))
{
MessageBox(NULL, "Release Device Context Failed", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
hDC = NULL;
}

if(hWnd && !DestroyWindow(hWnd))
{
MessageBox(NULL, "Could Not Release hWnd", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
hWnd = NULL;
}

if(!UnregisterClass("Space", hInstance))
{
MessageBox(NULL, "Could Not Unregister Class", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
hInstance = NULL;
}

}

bool createWindow()
{
WNDCLASS Window;

int pixelFormat;

DWORD dwExStyle;
DWORD dwStyle;

RECT WindowRect;
WindowRect.left =(long)0;
WindowRect.right =(long)SCREEN_H;
WindowRect.top =(long)0;
WindowRect.bottom =(long)SCREEN_W;

hInstance = GetModuleHandle(NULL);
Window.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
Window.lpfnWndProc = (WNDPROC) WndProc;
Window.cbClsExtra = 0;
Window.cbWndExtra = 0;
Window.hInstance = hInstance;
Window.hIcon = LoadIcon(NULL, IDI_WINLOGO);
Window.hCursor = LoadCursor(NULL, IDC_ARROW);
Window.hbrBackground = NULL;
Window.lpszMenuName = NULL;
Window.lpszClassName = "Space";

if(!RegisterClass(&Window))
{
MessageBox(NULL, "Failed To Register The Window Class", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}


dwExStyle = WS_EX_APPWINDOW;
ShowCursor(FALSE);


if(!(hWnd=CreateWindowEx(dwExStyle,
"Space",
"Space Quest",
WS_POPUP,
0, 0,
SCREEN_W, SCREEN_H,
NULL,
NULL,
hInstance,
NULL)))
{
killWindow();
MessageBox(NULL, "Window Creation Error", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}

DEVMODE newSettings;
// now fill the DEVMODE with standard settings, mainly monitor frequenzy

EnumDisplaySettings ( NULL, 0, &newSettings );
// set desired screen size/res

newSettings.dmPelsWidth = SCREEN_W;
newSettings.dmPelsHeight = SCREEN_H;
newSettings.dmBitsPerPel = SCREEN_D;
//set those flags to let the next function know what we want to change

newSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
// and apply the new settings

if ( ChangeDisplaySettings ( &newSettings, CDS_FULLSCREEN )
!= DISP_CHANGE_SUCCESSFUL )
return false; // in case of error


static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
SCREEN_D,
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};

if (!(hDC = GetDC(hWnd)))
{
killWindow();
MessageBox(NULL, "Can''t Create A GL Device Context", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}

if (!(pixelFormat = ChoosePixelFormat(hDC, &pfd)))
{
killWindow();
MessageBox(NULL, "Can''t Find A Suitable PixelFormat", "ERROR",MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}

if(!SetPixelFormat(hDC, pixelFormat, &pfd))
{
killWindow();
MessageBox(NULL, "Can''t Set The PixelFormat", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}

if (!(hRC = wglCreateContext(hDC)))
{
killWindow();
MessageBox(NULL, "Can''t Create A GL Rendering Context", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}

if(!wglMakeCurrent(hDC, hRC))
{
killWindow();
MessageBox(NULL, "Can''t Activate The GL Rendering Context", "ERROR", MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}

ShowWindow(hWnd, SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);

return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_ACTIVATE:
{
if (!HIWORD(wParam))
{
input.active = TRUE;
}
else
{
input.active = FALSE;
}

return 0;
}

case WM_SYSCOMMAND:
{
switch (wParam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}

case WM_CLOSE:
{
PostQuitMessage(0);
return 0;
}

case WM_KEYDOWN:
{
keys[wParam] = TRUE;
return 0;
}

case WM_KEYUP:
{
keys[wParam] = FALSE;
return 0;
}
}

return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
MSG msg;
bool esc = FALSE;

if (!createWindow())
{
return 0;
}

while(!input.escape)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
input.escape = TRUE;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
if (input.active)
{
if (keys[VK_ESCAPE])
{
input.escape = TRUE;
}
else
{
SwapBuffers(hDC);
}
}
}
}
killWindow();
return (msg.wParam);
}


all changes i made are between RegisterClass(...) and the pixelformat descriptor stuff


My Homepage

Share this post


Link to post
Share on other sites
Guzba    122
hey, well it works better i think but now i get a bunch of black lines about 1/2 cm with a 1/2 cm thick white line (both extending all the way across the window) that jump around the screen, jeez i really messed something up! i did follow your code exactly and i thank you for your help!

Share this post


Link to post
Share on other sites
Guzba    122
IT WORKS@!!! i just needed to get rid of the RECT WindowRect stuff and with your changes it worked
thanx so much everyone

Share this post


Link to post
Share on other sites
Guzba    122
its doing it again!!! god what did i do now lol

AHh why cant i win?! ive changed the settings and switched the H and W and nothing works! it worked one time! but then i tried to transfer the windows class into dif file but it didnt work so i put it back and it hasnt worked since! ive redone everythign from your code and nothing.. very maddening

[edited by - Guzba on March 18, 2003 6:02:34 PM]

Share this post


Link to post
Share on other sites