Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
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   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / JOGL Development / Re: JOGL Active Rendering Examples from Pro Java 6 book is not working any help on: 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.

2  Java Game APIs & Engines / JOGL Development / Re: JOGL Active Rendering Examples from Pro Java 6 book is not working any help on: 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
3  Java Game APIs & Engines / JOGL Development / JOGL Active Rendering Examples from Pro Java 6 book is not working any help on: 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



4  Java Game APIs & Engines / JOGL Development / Re: How to: Getting started with JOGL on: 2009-08-15 22:14:54
It seems there are some changes in the API. I updated the code.

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  
import com.sun.opengl.util.Animator;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.awt.GLCanvas;


/**
 * SimpleJOGL2.java <BR>
 * author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel) <P>
 *
 * This version is equal to Brian Paul's version 1.2 1999/10/21
 */

public class SimpleJOGL implements GLEventListener {

    public static void main(String[] args) {
        Frame frame = new Frame("Simple JOGL Application");
        GLCanvas canvas = new GLCanvas();

        canvas.addGLEventListener(new SimpleJOGL());
        frame.add(canvas);
        frame.setSize(640, 480);
        final Animator animator = new Animator(canvas);
        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                // Run this on another thread than the AWT event queue to
               // make sure the call to Animator.stop() completes before
               // exiting
               new Thread(new Runnable() {

                    public void run() {
                        animator.stop();
                        System.exit(0);
                    }
                }).start();
            }
        });
        // Center frame
       frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        animator.start();
    }

    public void init(GLAutoDrawable drawable) {
        // Use debug pipeline
       // drawable.setGL(new DebugGL(drawable.getGL()));

       GL2 gl = drawable.getGL().getGL2();
        System.err.println("INIT GL IS: " + gl.getClass().getName());

        // Enable VSync
       gl.setSwapInterval(1);

        // Setup the drawing area and shading mode
       gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl.glShadeModel(GL2.GL_SMOOTH); // try setting this to GL_FLAT and see what happens.
   }

    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
        GL2 gl = drawable.getGL().getGL2();
        GLU glu = new GLU();

        if (height <= 0) { // avoid a divide by zero error!
       
            height = 1;
        }
        final float h = (float) width / (float) height;
        gl.glViewport(0, 0, width, height);
        gl.glMatrixMode(GL2.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluPerspective(45.0f, h, 1.0, 20.0);
        gl.glMatrixMode(GL2.GL_MODELVIEW);
        gl.glLoadIdentity();
    }

    public void display(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();

        // Clear the drawing area
       gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
        // Reset the current matrix to the "identity"
       gl.glLoadIdentity();

        // Move the "drawing cursor" around
       gl.glTranslatef(-1.5f, 0.0f, -6.0f);

        // Drawing Using Triangles
       gl.glBegin(GL2.GL_TRIANGLES);
            gl.glColor3f(1.0f, 0.0f, 0.0f);    // Set the current drawing color to red
           gl.glVertex3f(0.0f, 1.0f, 0.0f);   // Top
           gl.glColor3f(0.0f, 1.0f, 0.0f);    // Set the current drawing color to green
           gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
           gl.glColor3f(0.0f, 0.0f, 1.0f);    // Set the current drawing color to blue
           gl.glVertex3f(1.0f, -1.0f, 0.0f);  // Bottom Right
       // Finished Drawing The Triangle
       gl.glEnd();

        // Move the "drawing cursor" to another position
       gl.glTranslatef(3.0f, 0.0f, 0.0f);
        // Draw A Quad
       gl.glBegin(GL2.GL_QUADS);
            gl.glColor3f(0.5f, 0.5f, 1.0f);    // Set the current drawing color to light blue
           gl.glVertex3f(-1.0f, 1.0f, 0.0f);  // Top Left
           gl.glVertex3f(1.0f, 1.0f, 0.0f);   // Top Right
           gl.glVertex3f(1.0f, -1.0f, 0.0f);  // Bottom Right
           gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
       // Done Drawing The Quad
       gl.glEnd();

        // Flush all drawing operations to the graphics card
       gl.glFlush();
    }

     public void dispose(GLAutoDrawable drawable){}
   
    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
    }
}
Pages: [1]
 

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 (22 views)
2014-07-24 01:59:36

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

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

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

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

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

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

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

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

Riven (53 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!