Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  JOGL Active Rendering Examples from Pro Java 6 book is not working any help  (Read 1237 times)
0 Members and 1 Guest are viewing this topic.
Offline falcon

Junior Newbie





« Posted 2009-08-15 22:22:31 »

The main problem is inside the AWT Canvas in order to get a drawable and a context
he uses these two lines but it seems they are deprecated.
http://download.java.net/media/jogl/jogl-2.x-docs-next/

// get a rendering surface and a context for this canvas
    drawable = GLDrawableFactory.getFactory().getGLDrawable(this, caps, null);
    context = drawable.createContext(null);

ANY HELP?

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  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
// CubeGL.java
// Andrew Davison, November 2006, ad@fivedots.coe.psu.ac.th

/* A JFrame contains a JPanel which holds a Canvas subclass called
   CubeCanvasGL. The canvas displays a rotating coloured cube
   using active rendering.

   The application is paused when it is minimized or deactivated.
   The window can be resized.

   The code uses the JSR-231 1.0.0 release build of JOGL,
   14th September 2006.

   The canvas could be added directly to the JFrame, but this
   approach allows other components can be included in the JFrame.
   In this example, there's a textfield which reports the cube
   rotations in the x,y,z- axes.
*/


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;

import javax.media.opengl.*;


public class CubeGL extends JFrame implements WindowListener
{
  private static int DEFAULT_FPS = 80;

  private static final int PWIDTH = 512;   // size of panel
 private static final int PHEIGHT = 512;

  private CubeCanvasGL canvas;

  private JTextField rotsTF;   // displays cube rotations
 private DecimalFormat df = new DecimalFormat("0.#");  // 1 dp


  public CubeGL(long period)
  {
    super("CubeGL (Active)");

    Container c = getContentPane();
    c.setLayout( new BorderLayout() );
    c.add( makeRenderPanel(period), BorderLayout.CENTER);

    rotsTF = new JTextField("Rotations: ");
    rotsTF.setEditable(false);
    c.add(rotsTF, BorderLayout.SOUTH);

    addWindowListener(this);

    pack();
    setVisible(true);
  } // end of CubeGL()


  private JPanel makeRenderPanel(long period)
  // construct the canvas, inside a JPanel
 {
    JPanel renderPane = new JPanel();
    renderPane.setLayout( new BorderLayout() );
    renderPane.setOpaque(false);
    renderPane.setPreferredSize( new Dimension(PWIDTH, PHEIGHT));

    canvas = makeCanvas(period);
    renderPane.add(canvas, BorderLayout.CENTER);

    canvas.setFocusable(true);
    canvas.requestFocus();    // the canvas now has focus, so receives key events

    // detect window resizes, and reshape the canvas accordingly
   renderPane.addComponentListener( new ComponentAdapter() {
      public void componentResized(ComponentEvent evt)
      { Dimension d = evt.getComponent().getSize();
        // System.out.println("New size: " + d);
       canvas.reshape(d.width, d.height);
      } // end of componentResized()
   });

    return renderPane;
  }  // end of makeRenderPanel()


  private CubeCanvasGL makeCanvas(long period)
  {
    // get a configuration suitable for an AWT Canvas (for CubeCanvasGL)
   GLCapabilities caps = new GLCapabilities();

    AWTGraphicsDevice dev = new AWTGraphicsDevice(null);
    AWTGraphicsConfiguration awtConfig = (AWTGraphicsConfiguration)
       GLDrawableFactory.getFactory().chooseGraphicsConfiguration(caps, null, dev);

    GraphicsConfiguration config = null;
    if (awtConfig != null)
      config = awtConfig.getGraphicsConfiguration();

    return new CubeCanvasGL(this, period, PWIDTH, PHEIGHT, config, caps);
  } // end of makeCanvas()


  public void setRots(float rotX, float rotY, float rotZ)
  // called from CubeCanvasGL to show cube rotations
 {  rotsTF.setText("Rotations: (" + df.format(rotX) + ", " +
                                     df.format(rotY) + ", " +
                                     df.format(rotZ) + ")");  }



  // ----------------- window listener methods -------------

  public void windowActivated(WindowEvent e)
  { canvas.resumeGame();  }

  public void windowDeactivated(WindowEvent e)
  {  canvas.pauseGame();  }

  public void windowDeiconified(WindowEvent e)
  {  canvas.resumeGame();  }

  public void windowIconified(WindowEvent e)
  {  canvas.pauseGame(); }

  public void windowClosing(WindowEvent e)
  {  canvas.stopGame();  }

  public void windowClosed(WindowEvent e) {}
  public void windowOpened(WindowEvent e) {}

// -----------------------------------------

  public static void main(String[] args)
  {
    int fps = DEFAULT_FPS;
    if (args.length != 0)
      fps = Integer.parseInt(args[0]);

    long period = (long) 1000.0/fps;
    System.out.println("fps: " + fps + "; period: " + period + " ms");

    new CubeGL(period*1000000L);    // ms --> nanosecs
 } // end of main()


} // end of CubeGL class



Offline falcon

Junior Newbie





« Reply #1 - Posted 2009-08-15 22:30:57 »

I could not post the second file due to 10000 character limit.
these two files are in this zip http://fivedots.coe.psu.ac.th/~ad/jg2/ch15/jogl1.zip
inside directory CubeGL_AR
Offline Cork

Junior Member




vote 6uN for OSX


« Reply #2 - Posted 2009-08-15 22:41:09 »

welcome to the world of JOGL!  You might be interested to know that JOGL2 has been recently released.  My advice if you are just starting out would be to have a look at the demos for JOGL2 and start from there.  I'm guessing your book is a bit outdated in this respect.  Some of the API has been changed and so you might find it easier that way.  In fact if you fancy a trip over to the dark side of NetBeans world, one of the forum members here has put together a pretty cool Net Beans JOGL2 bundle that includes many example projects that should get you up and running in no time!

good luck!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline falcon

Junior Newbie





« Reply #3 - Posted 2009-08-15 22:47:36 »

Hi Cork,

Thanks for the reply. I just started to learn JOGL and I also realized that JOGL2 is new because
they started to update Netbeans OpenGL pack in 5 days ago.

Then I will check the jogl-demos.

Offline DzzD
« Reply #4 - Posted 2009-08-21 13:11:50 »

maybe you can try this one ( I dont know if it is differents than the one in your book ) http://www.java-gaming.org/topics/active-rendering-with-jogl/17661/view.html

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.

pw (25 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (19 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!