Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Render off screen  (Read 369 times)
0 Members and 1 Guest are viewing this topic.
Offline PRW56

Senior Newbie





« Posted 2013-04-12 03:05:29 »

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?
Offline ReBirth
« Reply #1 - Posted 2013-04-12 11:04:08 »

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.

Offline Grunnt

JGO Wizard


Medals: 68
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #2 - Posted 2013-04-12 12:04:54 »

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?

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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
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());
   }

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (19 views)
2014-09-12 09:08:26

Norakomi (54 views)
2014-09-10 13:57:51

TehJavaDev (63 views)
2014-09-10 06:39:09

Tekkerue (31 views)
2014-09-09 02:24:56

mitcheeb (53 views)
2014-09-08 06:06:29

BurntPizza (37 views)
2014-09-07 01:13:42

Longarmx (23 views)
2014-09-07 01:12:14

Longarmx (27 views)
2014-09-07 01:11:22

Longarmx (27 views)
2014-09-07 01:10:19

mitcheeb (35 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!