The game I’m working on have a resolution of 160x144 pixels (like a gameboy one). I’ve been searching how to “zoom” or “scale” the windows (like, x2, x3 or x4) , but I don’t find anything, only how to change the game resolution.
Any clues on how to work with that? Thanks in advance.
You can draw to a small render target first and then render that to the backbuffer in the size you want. You may want to set the sampler state of the graphicsdevice to pointclamp so it doesn’t interpolate when scaling up.
Sorry can I jump in and ask a very similar topic. I have a 480x280 game that I want to scale 1-4X depending on options.Any help GREATLY appreciated.
I am trying to do this by rt, but currently it seems to be in reverse and my window gets bigger but my game shrinks in half lol. EDIT: since almost got it working.
so screenwidth and height are constant 480x280 and screenScale is a multiplier 1-4x. Changing scale simply makes graphics.prefferedbackbuffer… 480 and 280 * multiplier. This works fine for windowed and my game just doubles in size as you expect, however in full screen it is still stretching to any display. I thought I really had the answer here
If you pass null as a render target the GraphicsDevice will render to the backbuffer again. So in your game instance you’ll want to do something like:
_nativeRenderTarget = new RenderTarget2d(GraphicsDevice, 160, 144);
// Draw call
// now render your game like you normally would, but if you change the render target somewhere,
// make sure you set it back to this one and not the backbuffer
// after drawing the game at native resolution we can render _nativeRenderTarget to the backbuffer!
// First set the GraphicsDevice target back to the backbuffer
// RenderTarget2D inherits from Texture2D so we can render it just like a texture
_actualScreenRectangle would be a Rectangle like (x: 0, y: 0, width: a * 160, height: a * 144), where a is 1, 2, 3 or whatever scale factor you want.
EDIT: you’ll actually have to set the backbuffer size to the size of this rectangle by using PreferredBackBufferWidth and PreferredBackBufferHeight of your GraphicsDeviceManager. If you don’t do this in your game constructor, but later through settings or what not, you need to call GraphicsDeviceManager.ApplyChanges() for the window to actually resize.
Might be because you’re drawing with the transformMatrix the second time too. Since you already applied it once, you just have to render the texture with spritebatch to the backbuffer without additional transformation.
I have tried with taking that out as well I noticed that.
In your example where you draw to the “_actualScreenRectangle” my understanding is that it should draw the RT to a rectangle of 160x144 or 320x288 and if you then resize the screen, you should still have that 320x288 rectangle and just get blackness beyond it, however the image stretches with it.
I have tried messing with sourc/dest rectangles such as
spriteBatch.Draw(rt, new Rectangle(0, 0, 480, 280), new Rectangle(0, 0, screenWidth * ScreenScale, screenHeight * ScreenScale), Color.White);
Later at home I will try remove the transformation from the first spritebatch too (but then if that works how do I use a camera in my main drawing spritebatch )
If you’re not on the latest develop, there’s a bug in DX which will cause the drawing to rescale when the window is resized. I’m not sure if it’s also messed up if you do this through code (with graphicsdevicemanager as I said before).
EDIT: NOPE; I didn’t say nothing. I’ve tried to port it to OpenGL and happens the same issue as I was having in DirectX. I’m going to try the RenderTarget thing. If I have any issue, I will ask again here. Thanks!