XNA game starts drawing off screen on laptop - c#

I currently have my XNA PC game running in a borderless windowed mode which has worked well until recently on my new laptop. It seems to start drawing a few hundred pixels off the screen to the top left. This leaves a gap at the bottom of the screen and on the right where you can see the desktop below the game. All the mouse coords are accurate to where you should have to mouse over and click on things even though it's just not drawing in the right place.
My older laptop it drew correctly but this new one I just got it seems to be off somehow. I am using David Amador's Resolution class to set up a virtual resolution via:
graphics = new GraphicsDeviceManager(this);
Resolution.Init(ref graphics);
control = Control.FromHandle(this.Window.Handle);
Resolution.SetVirtualResolution(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height);
Resolution.SetResolution(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height, false);
I set fullscreen to false and then once I create the game screen I do the following to set it to borderless:
Form gameForm = (Form)Form.FromHandle(curGame.Window.Handle);
gameForm.FormBorderStyle = FormBorderStyle.None;
I tried doing "gameForm.Location = new System.Drawing.Point(0, 0);" to try and force set it to start drawing at (0,0) but with my current set up that doesn't seem to do anything because I can set it to (150, 150) and it won't start drawing there. Here is a screenshot from my laptop that shows how it's moved the window and cut off the left and top side exposing the desktop:
Does anyone have any idea why it could be happening now on my new laptop when it hasn't happened on my desktop or old laptop ever before?

Related

Problem with Fullscreen Resolution in Mono Game

a couple days ago I started game developing in MonoGame with Visual Studio 2017 and porting my code which i wrote in WinForms to MonoGame. Now I have a problem with the fullscreen mode. I searched the internet and the only thing I found out is that it depends on the resolution the monitor has.
In the default window mode of the application the screen looks like follows:
Now when I switch to fullscreen mode - this happens:
Now my problems are:
One can not see it on the picture because I used the print button and pasted in to paint but the image is largely strechted.
The right part of the screen is cut off
the sprites are moved to the top.
I'm using
graphics.ToggleFullScreen();
Is there a way to keep the original status like it is in window mode? Maybe to put flexible bars for a 4:3 mode and keep the sprite positions? My positions are fixed. So use something like
spriteBatch.Draw(Params.CUR_SPRITE_P1, new Rectangle(Convert.ToInt32(POSITION_P1.X), Convert.ToInt32(POSITION_P1.Y), 750, 476), Color.White); for the player position and the screen (to implement scrolling).
Or maybe adjust everything in full screen mode bu keep the positions of the sprites on different screen resolutions...
Thank you a lot!
Ok after searching and searching I finally found an answer:
var scaleX = (float)ActualWidth / VirtualWidth;
var scaleY = (float)ActualHeight / VirtualHeight;
var matrix = Matrix.CreateScale(scaleX, scaleY, 1.0f);
spriteBatch.Begin(transformMatrix: matrix);
This has to be put in the Draw()-Method.
My virtual screensize was 800x480. I tested it with my Monitor size 1920x1080 and this did the job.

Position to center screen in triple monitor setup with extended view

I have three monitors/screens of different sizes/resolutions setup as an extended view, all wired to the same NVIDIA graphic card. And from left to right:
Screen#0: 2400*1080
Screen#1: 1920x1080
Screen#2: 1920*1080
My application has three separate Windows, where I respectively position each Window to the corresponding monitor/screen with the following code
window00.Left = System.Windows.Forms.Screen.AllScreens[0].WorkingArea.Left;
window01.Left = System.Windows.Forms.Screen.AllScreens[1].WorkingArea.Left;
window02.Left = System.Windows.Forms.Screen.AllScreens[2].WorkingArea.Left;
window00.WindowState = System.Windows.WindowState.Maximized;
window01.WindowState = System.Windows.WindowState.Maximized;
window02.WindowState = System.Windows.WindowState.Maximized;
I only get the 3rd windows (window02) position to the right most screen properly (Screen#02), but both the 1st and 2nd windows (window00 & window01) stack and maximized to the first screen (Screen#00), leaving the middle Screen#01 empty displaying the background desktop environment, regardless if I set WindowsState.Maximized or Normal.
Even if I workaround the problem through offsetting window01 position by the width of Screen#00 to get all three windows position properly to their corresponding screens, if I maximize Windows.State, window01 still jumps back to Screen#00.
Why is this happening and why does the window not position or maximized to its WorkingArea it assigned to? Could it be due to WPF application using Forms properties?

Blurry textures after resize on certain computer?

So here's the thing. I made a game in 192x108. Yes, that small. I also made it borderless windowed, and it also resizes and stretches itself to it fits the main screen.
HERE'S THE PROBLEM:
When I start the game on my home PC, it stretches out to 1920x1080 with nearest neighbor and it's not blurry at all, just a pixely beauty. BUT when I start the game on my school PC, it stretches out to 1366x768 and becomes BICUBIC? I even added PointClamp to the spriteBatch.Begin(...SamplerState.PointClamp), but there was NO difference.
So how come it's different depending on the PC I use?
Looks like you can do this for every frame outside of the sprite batch:
GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
https://gamedev.stackexchange.com/questions/6820/how-do-i-disable-texture-filtering-for-sprite-scaling-in-xna-4-0
However, I'm wondering if it isn't the sprites that are being scaled, but the device after the sprites are rendered. Hard to tell without more information. Make sure your DisplayMode, ClientBounds, ViewPort, and BackBuffer are all the same width and height as well.
http://msdn.microsoft.com/en-us/library/bb203889(v=xnagamestudio.31).aspx

Prevent Window Centering in XNA

When I set the position of my game window using form.DesktopLocation(new Point(X, Y);, it works, but then XNA automatically resets it to the center of the screen. I tried googling and looking on stack overflow, but I can't seem to figure out how to prevent it centering. Any ideas?
Here's my code manipulating the GraphicsDevice, GraphicsDeviceManager, and the Form controlling the game:
// in the initialiser
window = (Form)Form.FromHandle(Window.Handle);
GraphicsDeviceManager = new GraphicsDeviceManager(this);
// in the draw method
g.PreferredBackBufferWidth = Width;
g.PreferredBackBufferHeight = Height;
g.ApplyChanges();
f.DesktopLocation = new System.Drawing.Point(X, Y);
And that's literally everything. I tried setting the desktop location more than once each frame, before and after the g.ApplyChanges(), and that doesn't change anything.
However, just now, I tried removing the g.ApplyChanges() and it doesn't do it anymore. Odd. Why would running a g.ApplyChanges() before changing the form only sometimes recenter the form AFTER I positioned the form?
There is no solution to this question.
XNA automatically resets the position of the window to the center of the screen on g.ApplyChanges, and whenever it hits another window-related operation, such as resizing, or moving the window from one monitor to another.
This is a problem in XNA, not with XNA code. XNA was written with no way to prevent this because their focus is on content, not windows. Therefore, if you want greater control over your forms, it's a better idea to not use XNA at all, or use XNA's output in a form you set up.

Full screen c# windows form covering all monitor

Is there a way to make make a windows form application full screen and black out your secondary monitors? So the main display is on your primary display and all your other monitors are just completely black?
You can use the Screen class which give you informations about the current active screens.
// Form myFrm
Rectangle r = new Rectangle();
foreach (Screen s in Screen.AllScreens)
{
if ( s != Screen.CurrentScreen ) // Blackout only the secondary screens
r = Rectangle.Union(r, s.Bounds);
}
myFrm.Top = r.Top;
myFrm.Left = r.Left;
myFrm.Width = r.Width;
myFrm.Height = r.Height;
myFrm.TopMost = true; // This will bring your window in front of all other windows including the taskbar
I can think of one way, and that would be to find out how many monitors there are on the computer, and their layout relative to each other, then create your primary window at 0,0, maximize it and set it to be TopMost, then do the same for the other displays, placing them at the screen locations corresponding to the top left of each monitor of the computer.
The only thing I can think of that would benefit from this in a WinForms environment is an app designed to give a test; the app would cover the entire desktop (except the taskbar; you'd have to disable the Start menu) and pretty much ensure that the user couldn't look at anything except the testing program. It will give you a minimal performance advantage.
Most of the apps that black out all the monitors except the main display are basically using DirectX to control the screen directly (through the lower-level interface to the graphics card). If you're using WinForms to make your program, you're about 50 levels of abstraction above using DirectX.
One way would be to create a second form in your application. One that, when given a set of dimensions, will open without border or menu and with the background set to black.
When your application runs, enumerate your monitors (count them to see how many) and find their dimensions. Your primary one will start at 0,0.
Then spawn a copy of that second form for each of your monitors (except your primary one) and give that form the dimensions of the monitor. They will then turn each screen black.
You will need to remember to keep a handle to each of the forms and terminate them when you terminate your main form.

Categories

Resources