Frame moving to a higher resolution screen issues.

Hello…

So I have my Frame container to draw my image buffer to. The game loop (before it starts looping) does this:

Graphics frameGraphics = frame.getGraphics();

And then uses the frameGraphics object to draw the image onto the frame.

However when I use this and I move the frame to my much higher resolution screen, the buffered image stays 800x600 however the frame gets scaled up four times.

The issue is the fact that the Graphics object changes on the Frame when it moves to the other screen.
I don’t want to have frame.getGraphics() in my game loop because it causes too much overhead… what should I do?

I assume you’re talking about AWT/Swing?

Are you absolutely sure you need active rendering? Why don’t you just extend JPanel and override the paintComponent() method? Usually calling getGraphics() on a component is a bad idea, unless you really know what you’re doing.

Yes I need active rendering, it’s a 3D rasterized video game.

Can’t you just get the Graphics again when you resize the frame?

To fill out the suggestion made by @KevinWorkman, add a component listener to your frame and capture the resize event. From there you should be able to resize your buffer and be back on track. This also avoids having to grab the graphics object every iteration of your game loop.

Where’d you guys get resizing from? I’m saying that when I move (as in drag) the frame to a much higher resolution screen, the frame (and ONLY the frame, this means that the 800x600 bufferedimage stays 800x600) gets scaled appropriately, but the graphics object of the frame changes. The graphics object, im assuming, knows that the screen is of a higher resolution so it draws the image larger to fit onto the larger frame.

Probably from your description of the frame getting “scaled up four times” in your original post. Can you post a before and after shot of the window so that we’re all on the same page?

I fixed the issue by adding a ComponentMoved listener to the Frame and setting a boolean to true after the Frame had finished moving and then in the game loop, if that boolean was true, it would call for a fresh graphics object

[quote=“Archive,post:6,topic:55383”]
From here:

[quote=“Archive,post:1,topic:55383”]

That’s pretty much exactly what I meant by this:

[quote=“KevinWorkman,post:9,topic:55383”]

[quote=“Archive,post:6,topic:55383”]
From here:

Haha, I guess I didn’t correctly interpret your response! Thanks

No problem. Although, it seems like you don’t really need that boolean. Why not just get the Graphics again directly from the listener?

I guess it’s a trade off between thread safety and a single if statement in your render code. It probably doesn’t make much of a difference anyway.