Sign in to follow this  
reaperrar

Fullscreen window and resolution

Recommended Posts

I have two different questions:

1. Using the windows API I want to create a full-screen window. At the moment I'm creating a border-less/frame-less window the size of the desktop. This works fine, got my desktop turning black :D Now I'm assuming I have to/should:
[list][*]Hide the windows cursor[*]Show an ingame cursor[*]Move the image cursor according to windows cursor position - old windows cursor position[*]Reset the windows cursor to the center of the fullscreen[/list]I can do the above, just wondering if I should.
I'm also thinking I should disable the mouse clicking outside the window somehow, should I do this? If so, how?

2.
How do I go about multiple resolution support/aspect ratio etc. Is there a good guide I can follow?

Share this post


Link to post
Share on other sites
See [url="http://my.opera.com/adelamro/blog/2010/01/09/curver-fullscreen"]this[/url] for fullscreen toggling implementation in Win32. Remember that you can create a windows cursor and bundle it with your application and then use it with the system cursor instead of an an-game cursor image. This has the advantage of being fast, since the system cursor updates are fast, but game cursors' update speed depends on the frame rate. But if you decide you still want an in-game cursor (for example, if you're doing crazy cursor graphics), then yes, you should hide the system cursor and draw an in-game one.

To hide the cursor, responding to WM_SETCURSOR appropriately will result in simpler and better-behaving code than calling ShowCursor(false).

However, you should only need to adjust the cursor position when the window is not fullscreened. In full screen mode, the user can't move the cursor outside the window since it's taking up all of the screen space. In windowed mode, look into using the ClipCursor() API, or capture the mouse when the window is activated (and release it when it's deactivated) so that you receive WM_MOUSEMOVE messages when the user moves the cursor outside of the window, and respond to it by setting the cursor position back inside the window. Or, like you suggested, use an in-game cursor and keep the system cursor in the center of the window.

I'm not sure what you mean exactly by handling multiple resolutions and aspect ratios. Do you how to decide the aspect ration based on resolution? For 2D stuff, I'll just quote [url="http://www.gamedev.net/topic/461070-fullscreen-mode-res--aspect-ratio-opinions-needed/page__view__findpost__p__4040457"]this[/url]:

[quote name='Adam_42' timestamp='1187780143' post='4040457']


The usual method for aspect ratio independence for 2D elements is to have a border. You put everything in a 4:3 shaped box in the middle of the screen but stretch the background to full screen. As long as the background is generic that works well. If not then it's black borders or extra backgrounds designed for different shaped resolutions (16:9 and 5:4 are the common ones).

The other option is just to stretch everything to fit.

By the way it's also worth noting that the ratio of width to height in pixels is not always the same as width to height in inches. For example 1280x1024 on a CRT probably has non square pixels, but on and LCD the pixels are probably square. I wouldn't worry about it for 2D, but it isn't too hard getting it right for 3D.

You can use (float)GetDeviceCaps(hdc, HORZRES) / (float)GetDeviceCaps(hdc, VERTRES) to find out what Windows thinks the physical aspect ratio is.
[/quote]

I hope this helps.

Share this post


Link to post
Share on other sites
KK got most of it working, though when I exit fullscreen and restore the window's old position/dimensions everything else on screen is black. If I drag the window over the screen the black is removed, though I can not do the same for the taskbar. I have to press ctrl alt del for it to refresh. How can I fix this?

Share this post


Link to post
Share on other sites
Do you want to do this for learning purposes or do you want to create an actual game? If latter, I'd suggest you screw your plans and
move ahead to a graphics api right away. These APIs like directx already have these functions like fullscreen/windowed-switching and custom hardware cursors included. Would be a waste of time bothering the win32-api that case.

Share this post


Link to post
Share on other sites
Well, I am making a game... using opengl atm. How do I go about toggling fullscreen using opengl?

EDIT: I feel like I'm one step away from having fullscreen toggle working just with windows api, and I would like to know how just for the sake of knowing. Could you also tell me how to refresh the background after returning to windowed mode?

Share this post


Link to post
Share on other sites
I had a hunch I'd have to "ShowWindow" after "SetWindowLong" and "MoveWindow", not do both then show window. So I went from...

[code]SetWindowLong(m_oHandle, GWL_STYLE, FULLSCREENWINDOWSTYLE);
MoveWindow(m_oHandle, iOldPositionX, iOldPositionY, uiOldWidth, uiOldHeight, 1);
ShowWindow(m_oHandle, SW_SHOW);[/code]

..which didn't work, to this...

[code]SetWindowLong(m_oHandle, GWL_STYLE, FULLSCREENWINDOWSTYLE);
ShowWindow(m_oHandle, SW_SHOW);
MoveWindow(m_oHandle, iOldPositionX, iOldPositionY, uiOldWidth, uiOldHeight, 1);
ShowWindow(m_oHandle, SW_SHOW);[/code]

...which did work. So now my background is not black when the window returns to windowed mode. But I thought showing the window twice shouldn't be the fix, seems weird. So I changed my method to this...

[code]SetWindowPlacement(m_oHandle, &m_oOldWindowPlacement);
SetWindowLong(m_oHandle, GWL_STYLE, DEFAULTWINDOWSTYLE);
ShowWindow(m_oHandle, SW_SHOW);[/code]

...which also works. Can someone explain the reasoning behind this?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this