# Java - set resolution of game

Hi everybody I am making small game using pure Java 8 and rednering it by Java AWT Graphics2D method . My question is how to make that user can change the quality of game. For example: 720p, 1080p, 1440p. Something similar that is when playing YouTube video.

The steps I will make?

• Make 3 pictures of each, each with different quality.

Is this the right way?

But Java is default only 72dpi so each of them will be the same quality. So how to render it in different resolution?

Edit:

I will be using LibGDX for rendering. So I will be using OpenGL. But still don’t know how to make in LibGDX.

Edit:

So I now understand that using LibGDX mipmap I will make my scaling nicer. So I will have 1440p image and scale it up down? Or I will have to have each image for each resolution (720p, 1080p,1440p) and they will change to user selected resolution and only scaling to the window size?

The second method I have in mind how to do, but for second I need code example.

Thanks one more time for spending time with beginner!

• This reddit thread offers some third-party libraries you might be interested in. reddit.com/r/gamedev/comments/19ubgo/… I would personally recommend something like LibGDX. Apr 16, 2020 at 15:23
• Yes thanks! Any idea doing it from scratch?
– user136940
Apr 16, 2020 at 15:25
• Here's a pure Java AWT solution that I found: stackoverflow.com/questions/11225113/… Apr 16, 2020 at 15:27
• Thanks I read that before. But that is for whole monitor. I won’t only change quality of my textures
– user136940
Apr 16, 2020 at 15:38

This can be done via scaling, see here.

However...

Q: Why do render quality levels like you are proposing to implement, exist in games & video? That is, lowering texture quality while keeping the window / viewport size the same?

A: To improve performance on lower spec machines.

But... windowed Java AWT can't (?) be assumed to work that way. Instead, it uses the native resolution of the desktop and the size of the window within that desktop, to define the number of pixels / texels to be rendered, in x & y. AWT is not really designed for games or videos, but for simple desktop UI, graphing and diagrams. (Whether AWT's scaling and rendering mentioned above is GPU-accelerated, is up for debate.)

So if you keep things at the same size, but lower the quality, then you are possibly not changing the number of pixels that must be rendered - but rather just having to double or quadruple those texels into the final render's pixels. This makes the game look worse, potentially with no performance improvement.

So if you want a quality setting that will definitely decrease the rendering load (and thus isn't a complete waste of time!), you need to use a render technology like OpenGL for Java, in the form of e.g. LibGDX renderer, LWJGL, or JOGL. This is because GPU-based rendering actually will do less work when you render fewer texels, so that lowering quality actually does something useful.

So to have any assured benefits to what you're doing, I would suggest switching to a renderer that is intended for games. Else you may be wasting your time. EDIT: Google "libgdx mipmap" for more.

• This is exactly the right answer - you can't conceivably do this from scratch and get a solid efficient solution, you need external render technology. Apr 16, 2020 at 18:25
• Thanks a lot! It open my mind! I am using LWJGL for simple 3D objects, but don’t know how to make 2D. Probably go for LibGDX. I will wait some time and then mark this as the final answer!
– user136940
Apr 17, 2020 at 5:26
• Any idea how ti make it in LibGDX?
– user136940
Apr 18, 2020 at 5:53
• @Engineer What? There is some filters
– user136940
Apr 18, 2020 at 7:29
• google "libgdx mipmap" - and learn what you need to know. Apr 18, 2020 at 7:34