Render off screen

I’m not sure exactly how to phrase a search for this, but I don’t understand how, java2D at least, handles this aspect of rendering or if it does at all. If you tell it to render an object wholly outside, or even partially outside, does it save itself the cpu and not render it at all? I mean the way I understand it, every one of those draw methods affects some matrix of pixels (I think of it as a 2D array), and then the show method is called and it is shown on the screen, is that correct?

I don’t know exactly the answer but this seems useless to consider as you might can’t do anything for it and/or they already pack it, done it for you.

[quote=“PRW56,post:1,topic:41497”]
Yup, I should not worry too much about stuff you draw off-screen. Usually for a game you draw the graphics on a ‘back buffer’ (which is indeed a bit like a matrix of pixels or a 2D array), and then draw the back buffer to the screen you see on the monitor. The rendering API, be it software or hardware makes sure that it doesn’t waste time rendering things you cannot see, so I would not worry about that if I were you.

Here’s how I do rendering in the Java4K games, which shows the use of a back-buffer in an applet:

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

public class Java2DTest extends Applet implements Runnable {

	public void start() {
		new Thread(this).start();
	}

	public void run() {
		// Set up the graphics stuff, double-buffering.
		BufferedImage screen = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB);
		Graphics2D g = (Graphics2D) screen.getGraphics();
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		Graphics2D appletGraphics = (Graphics2D) getGraphics();

		// Game loop
		do {

			// Clear background
			g.setPaint(Color.black);
			g.fillRect(0, 0, 800, 600);

			// Render something inside the bounds
			g.setPaint(Color.red);
			g.fillRect(100, 100, 200, 200);

			// Render something outside of the bounds (does not get rendered)
			g.setPaint(Color.blue);
			g.fillRect(3000, 3000, 200, 200);

			// Draw the backbuffer to the screen.
			appletGraphics.drawImage(screen, 0, 0, null);

			// Wait a bit to make sure the CPU doesn't explode
			try {
				Thread.sleep(10);
			} catch (Exception e) {

			}

		} while (isActive());
	}