PDA

View Full Version : Windowed/fullscreen mode



Rottbott
06-21-2001, 10:52 PM
Hi,

Firstly, how do I get into Windowed mode? When I create my window it goes fullscreen even if I specify FALSE for the fullscreen flag. Why?

Secondly, is it possible to switch between fullscreen and windowed as the program runs? If so, how?

Thanks,

Rottbott

Deiussum
06-22-2001, 05:25 AM
More info is needed. Like, how do you create your window (Glut, Win32, MFC, Linux, etc.) And what platform are you running on (Windows, Linux, etc.)

I don't know what you are using that you would explicitly specify a "fullscreen flag." Most of the things I use to create a window are windowed by default.

You can switch between fullscreen and windowed modes, but depending on what platform you are running on, there is probably extra work involved. (i.e. In Windows, everything needs to be destroyed and recreated.)

Rottbott
06-22-2001, 06:31 AM
I'm using Windoze. I'm not using Glut, just plain Win32 code. Here's the line that creates the window:

CreateGLWindow("Rottbott's OpenGL program", ScreenX, ScreenY, ScreenZ, TRUE);


As for destroying and recreating it, is this as simple as:

killit();
CreateGLWindow("Rottbott's OpenGL program", ScreenX, ScreenY, ScreenZ, TRUE);

?

Deiussum
06-22-2001, 07:18 AM
Post your code for CreateGLWindow. This is not an API function. Did you just grab it from the Nehe tutorials? I usually do all my own window creation so I haven't really looked too closely at that part of the Nehe tutorials. Maybe you just missed something when you were copying it over to your own code?

Rottbott
06-22-2001, 07:21 AM
It wasn't from the Nehe tutorials but I think it uses that code anyway. Where can I dig out the code it uses?

Rottbott
06-22-2001, 07:24 AM
I found the code, it uses a header file "setupogl.h". Here's the function:

BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
GLuint PixelFormat;
WNDCLASS wc;
DWORD dwExStyle;
DWORD dwStyle;
RECT WindowRect;
WindowRect.left=(long)0;
WindowRect.right=(long)width;
WindowRect.top=(long)0;
WindowRect.bottom=(long)height;

fullscreen=fullscreenflag;

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

RegisterClass(&wc);

DEVMODE dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
dmScreenSettings.dmSize=sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = width;
dmScreenSettings.dmPelsHeight = height;
dmScreenSettings.dmBitsPerPel = bits;
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWID TH|DM_PELSHEIGHT;

ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN);

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

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


hWnd=CreateWindowEx( dwExStyle,"OpenGL",title,
dwStyle |WS_CLIPSIBLINGS |WS_CLIPCHILDREN,
0, 0,WindowRect.right-WindowRect.left,
WindowRect.bottom-WindowRect.top,
NULL,NULL,hInstance,NULL);

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

hDC=GetDC(hWnd);
PixelFormat=ChoosePixelFormat(hDC,&pfd);
SetPixelFormat(hDC,PixelFormat,&pfd);
hRC=wglCreateContext(hDC);
wglMakeCurrent(hDC,hRC);

ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
Init();
return TRUE;
}

FoxDie
06-22-2001, 08:11 AM
Set width and height as your screen resolution and dwStyle=WS_CAPTION|WS_SYSMENU.
Don't use WS_POPUP

Rottbott
06-22-2001, 09:20 AM
That makes a mess. It ends up setting my desktop resolution to the 800*600 so the window takes up the whole screen. Plus when I exit it doesn't clear itself but that's probably a problem in the killit() function.

Deiussum
06-22-2001, 09:33 AM
It actually doesn't even appear to do anything with the fullscreen flag other than to set global fullscreen variable.

Technicall this part



DEVMODE dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings ));
dmScreenSettings.dmSize=sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = width;
dmScreenSettings.dmPelsHeight = height;
dmScreenSettings.dmBitsPerPel = bits;
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWID TH|DM_PELSHEIGHT;

ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSC REEN);



Should only be run if fullscreen is true. Likewise, dwStyle should only use WS_POPUP if fullscreen is true. Otherwise it should use something else, such as WS_CAPTION | WS_SYSMENU like FoxDie suggested. I typically use something like WS_OVERLAPPEDWINDOW.

Rottbott
06-22-2001, 10:15 AM
Works like a dream http://www.opengl.org/discussion_boards/ubb/smile.gif. Many thanks.

Only a couple of minor details left - how can I resize the window (sorry I know NO Windoze API code yet), and how can I make it so the mouse doesn't disappear when moved over the window?

Thanks a lot for your help both of you http://www.opengl.org/discussion_boards/ubb/biggrin.gif. I'm beginning to like this board.

FoxDie
06-22-2001, 12:07 PM
About mouse cursor.
Use ShowCursor(true) to show cursor and
ShowCursor(false) to hide cursor.

[This message has been edited by FoxDie (edited 06-22-2001).]

Rottbott
06-22-2001, 12:16 PM
Aha! I have a mouse cursor! However, when above the window it flickers like a magic lantern...

Deiussum
06-25-2001, 05:13 AM
Resize the window using code, handle when the user resizes the window, or just make it so that the user CAN resize the window?

1) To resize the window with code take a look at the SetWindowPos function. You can find information about it in MSDN (http://msdn.microsoft.com) .

2) If you want to handle when the user resizes the window, you need to handle the WM_SIZE event. It seems you are using some framework that wraps around the Win32 API that I am not familiar with so I can't help much more than to tell you that.

3) If you mean that your window is not resizable, it probably just has to do with your window styles WS_POPUP is not resizeable, WS_OVERLAPPEDWINDOW (along with others) is. I believe adding WS_BORDER will make your window resizable.

About the flickering mouse pointer, it might have to do with how you handle screen updates. Not knowing what your framework looks like, it's hard to say what you could to fix it. http://www.opengl.org/discussion_boards/ubb/smile.gif