Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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  
  3DzzD: Offscreen rendering  (Read 853 times)
0 Members and 1 Guest are viewing this topic.
Offline Orangy Tang

JGO Kernel


Medals: 48
Projects: 11


Monkey for a head


« Posted 2011-02-14 21:53:47 »

I'm trying to get 3DzzD to render without having a visible display - i've got the following which almost works, but the actual library doesn't want to give me any output:

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  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
public class DzzdAppTest
{

   public static void main(String[] args)
   {
      Toolkit.getDefaultToolkit();
     
      DzzdAppTest app = new DzzdAppTest();
      app.run();
   }
   
   private JFrame frame;
   private OwnCanvas canvas;
   
   
   IRender3D render3d;
   IScene3D scene3d;
   
   
   
   public DzzdAppTest()
   {
      createDzzd();
     
      frame = new JFrame();
      frame.setLayout(new BorderLayout());
     
      canvas = new OwnCanvas();
      canvas.setMinimumSize( new Dimension(200, 200));
      canvas.setPreferredSize( new Dimension(200, 200));
      canvas.setMaximumSize( new Dimension(200, 200));
     
      frame.getContentPane().add(render3d.getCanvas(), BorderLayout.NORTH);
      frame.getContentPane().add(canvas, BorderLayout.CENTER);
     
      frame.setSize(200, 400);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
      render3d.setScreenUpdateEnabled(true);
      render3d.setPixelUpdateEnabled(true);
      render3d.getCanvas().setVisible(true);
      render3d.getCanvas().invalidate();
     
      // This will not render anything
     renderSingleFrame();
     
      frame.pack();
      frame.setVisible(true);
     
      // Now the frame is visible (and the canvas is valid) this will render correctly
     renderSingleFrame();
   }
   
   private void createDzzd()
   {
      // Ask 3DzzD factory for a fresh Scene3D
     this.scene3d = DzzD.newScene3D();  
     
      //Create a Scene3D loader and link it to a 3DS file
     IScene3DLoader loader = DzzD.newScene3DLoader();
      loader.loadScene3D("file:/Users/Orangy/Documents/CodeRepository/Tectonicus/Data/Test/","CUBE.3DS");
     
      // Add the loader to the scene
     this.scene3d.setScene3DLoader(loader);
     
      // Wait until all object & texture are loaded
     while(this.scene3d.getNbMonitoredSceneObject()!=0)
      {
         this.scene3d.updateMonitoredSceneObjects();  
         DzzD.sleep(10);
      }
     
      // Set the active camera in the 3d scene
     this.scene3d.setCurrentCamera3DByName("Camera01");
     
      // Ask 3DzzD factory for a software 3D Render
     this.render3d = DzzD.newRender3D(this.getClass(), "SOFT", null);
     
      // Set the Render3D size and enable maximum antialias
     this.render3d.setSize(200, 200 ,7);
     
      // Set Camera Aspect ratio to 1:1
     this.scene3d.getCurrentCamera3D().setZoomY(((double)this.render3d.getWidth())/((double)this.render3d.getHeight()));  
     
      // Tell the Render3D wich camera it should use to render
     this.render3d.setCamera3D(this.scene3d.getCurrentCamera3D());
   }
   
   public void run()
   {
      Canvas c = new Canvas();
      Graphics g = c.getGraphics();
      System.out.println(g);
   }
   
   public void renderSingleFrame()
   {
      //Set the scene to world space
     this.scene3d.setScene3DObjectToWorld();
     
      //Set the scene to active camera space
     this.scene3d.setScene3DObjectToCamera();
     
      //Tell the 3D render to compute & draw the frame
     this.render3d.renderScene3D(this.scene3d);
   }
   
   private class OwnCanvas extends Canvas
   {
      private static final long serialVersionUID = 1L;

      @Override
      public void paint(Graphics g)
      {
         super.paint(g);
         
         g.setColor(Color.green);
         g.fillRect(0, 0, 200, 200);
         
         render3d.getCanvas().paint(g);
      }
   }
}


I've been poking around the source but unfortunately can't seem to spot anything obvious. Does anyone have any hints as to how to fix this? (Dzzd? You around?)

Thanks.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Orangy Tang

JGO Kernel


Medals: 48
Projects: 11


Monkey for a head


« Reply #1 - Posted 2011-02-14 21:58:51 »

Actually, this modification seems to fix things:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
   public final void drawPixelsOnCanvas(Canvas canvas)
   {
      Graphics g=canvas.getGraphics();
     
      if(this.useMIS)      
         this.imageMemoire.newPixels();

      // pulled this out of the g!=null test
     ((Render2D.PCanvas)canvas).image=this.image;                  
     
      if(g!=null)
      {
         canvas.update(g);
      }
   }

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline DzzD
« Reply #2 - Posted 2011-02-14 22:31:55 »

I never experienced with offlscrren rendering but maybe  try this one to disable screen update :
Quote
yourRender.setScreenUpdateEnabled(false);

then you will probably have to add a method in Render3D that return the rendered pixel as an int array and/or the Image object result

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

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (85 views)
2013-05-17 21:29:12

alaslipknot (93 views)
2013-05-16 21:24:48

gouessej (125 views)
2013-05-16 00:53:38

gouessej (118 views)
2013-05-16 00:17:58

theagentd (128 views)
2013-05-15 15:01:13

theagentd (115 views)
2013-05-15 15:00:54

StreetDoggy (159 views)
2013-05-14 15:56:26

kutucuk (181 views)
2013-05-12 17:10:36

kutucuk (181 views)
2013-05-12 15:36:09

UnluckyDevil (188 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.271 seconds with 20 queries.