Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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  
  [solved]Having problems with JOGL  (Read 1095 times)
0 Members and 1 Guest are viewing this topic.
Offline cupcakey

Senior Newbie


Medals: 1



« Posted 2012-10-21 16:48:08 »

I used to use JOGL 1.0 for game dev, spent a few years away and now JOGL 2.0 is out. My OS is Linux Mint. I am using the JOGL natives i586 although my OS is i686. using Java 7 Open JDK i386. Getting some weird errors.

I tried running a JOGL2.0 picking example(http://jogamp.org/jogl-demos/src/demos/misc/Picking.java) and the display flashed the renderings correctly for maybe a half second then it went black(set clear color). Also when I resize the frame anything inside of it disappears.

This was all of course after countlessly trying to debug my own scripts. In my own script it seems that the glcanvas never updates the GluLookAt . I'm thinking this might be a java and or jogl error rather then a script error. . Either way any advice is appreciated. Thank you for your time.


If anyone could run my script and tell me if when you click the mouse the black pyramid gets further and further away it would be very appreciated! Otherwise I won't know if it's my install or my code.
Here's my code:
orbitalExplorerApp.java
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  
import java.applet.*;
import java.awt.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.Animator;

import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;


@SuppressWarnings("serial")
public class orbitalExplorerApp extends Applet{
   private static final long serialVersionUID = 7403003329697278728L;
    protected Animator animator;
    protected GLCanvas glcanvas;
    private orbitalExplorer orbExplorer = new orbitalExplorer();
   
    public void init() {
       setLayout( new BorderLayout() );
       GLProfile profile = GLProfile.get(GLProfile.GL2);
       GLProfile.initSingleton();
          GLCapabilities capabilities = new GLCapabilities(profile);
       
        glcanvas = new GLCanvas(capabilities);
        glcanvas.addGLEventListener(orbExplorer);
        glcanvas.addMouseListener(orbExplorer);
        glcanvas.setBounds(0, 0, 512, 512);
        animator = new Animator(glcanvas);
     
        add(glcanvas, BorderLayout.CENTER);
    }

    public void start() {
       animator.setRunAsFastAsPossible(false);
       animator.start();
    }
   
    public void stop() {
       animator.stop();
    }
   
    public void destroy() {}
}

orbitalExplorer.java
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  
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;

import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.GLCanvas;
import javax.media.opengl.glu.GLU;

public class orbitalExplorer extends GLCanvas implements GLEventListener, MouseListener{
   private GLU glu = new GLU();
   private GL2 gl;
   
   private Camera3D camera = new Camera3D(-1.0f,0f,-16.0f,//Location X,Y,Z
                                0f,0f,0f,//Angle X,Y,Z,
                                2f,//Orbiting Radius
                                0f,0f,0f);//Focus Position
  private float degreeToRadian = 0.0174532925f;
   

   public void mouseClicked(MouseEvent mouse) {
      camera.z = camera.z - 10.0f;
      System.out.println("camera-z:"+camera.z);//Displays correct camera values on clicking
  }
   public void mousePressed(MouseEvent mouse) {
     
   }

   public void mouseReleased(MouseEvent mouse) {
     
   }
   public void mouseEntered(MouseEvent mouse) {}
   public void mouseExited(MouseEvent mouse) {}
   public void mouseDragged(MouseEvent mouse) {}
   public void mouseMoved(MouseEvent mouse) {}
   public void mouseWheelMoved(MouseEvent mouse) {}

    public void reshape( GLAutoDrawable drawable, int x, int y, int width, int height ) {
       gl = drawable.getGL().getGL2();
        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.0f, 100.0f);//20 = LOOK AT DIST
       gl.glMatrixMode(GL2.GL_MODELVIEW);
        gl.glLoadIdentity();
    }

    public void init( GLAutoDrawable drawable ) {
       gl = drawable.getGL().getGL2(); //Set Up GL
      gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
       gl.glEnable(GL2.GL_DEPTH_TEST);
       gl.glClearDepth(1.0f);
       gl.glDepthFunc(GL2.GL_LEQUAL);
       gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
    }
       
    public void dispose( GLAutoDrawable drawable ) {}
   
    public void display( GLAutoDrawable drawable ) {
       //Canvas Clearing
      gl = drawable.getGL().getGL2();
       gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
        gl.glLoadIdentity();
       
        //Camera Permutations
       glu.gluLookAt(camera.x, camera.y, camera.z,
                    camera.focusx, camera.focusy, camera.focusz,
                    0, 1, 0);
       
       //Rendering Operations
      gl.glPushMatrix();
          gl.glBegin(GL2.GL_TRIANGLES);        // Drawing Using Triangles
             gl.glColor3f(0.0f, 0.0f, 0.0f);     //
             gl.glVertex3f(0.0f, 1.0f, 0.0f);    // Top Of Triangle (Front)
             gl.glVertex3f(-1.0f, -1.0f, 1.0f);  // Left Of Triangle (Front)
             gl.glVertex3f(1.0f, -1.0f, 1.0f);   // Right Of Triangle (Front)
             gl.glVertex3f(0.0f, 1.0f, 0.0f);    // Top Of Triangle (Right)
             gl.glVertex3f(1.0f, -1.0f, 1.0f);   // Left Of Triangle (Right)
             gl.glVertex3f(1.0f, -1.0f, -1.0f);  // Right Of Triangle (Right)
             gl.glVertex3f(0.0f, 1.0f, 0.0f);    // Top Of Triangle (Back)
             gl.glVertex3f(1.0f, -1.0f, -1.0f);  // Left Of Triangle (Back)
             gl.glVertex3f(-1.0f, -1.0f, -1.0f); // Right Of Triangle (Back)
             gl.glVertex3f(0.0f, 1.0f, 0.0f);    // Top Of Triangle (Left)
             gl.glVertex3f(-1.0f, -1.0f, -1.0f); // Left Of Triangle (Left)
             gl.glVertex3f(-1.0f, -1.0f, 1.0f);  // Right Of Triangle (Left)
          gl.glEnd();
        gl.glPopMatrix();
       
        gl.glFlush();
    }

}


Vector3D.java
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  
public class Vector3D {
   public float x, y, z;
   public float mag;
   
   public Vector3D(float X, float Y, float Z){
      x = X; y = Y; z = Z;
   }
   
   public Vector3D(){
      x = 0f; y = 0f; z = 0f;
   }
   
   public Vector3D(Vector3D vector){
      x = vector.x; y = vector.y; z = vector.z;
   }
   
   public void setX(float X){x = X;}
   public void setY(float Y){x = Y;}
   public void setZ(float Z){x = Z;}
   
   public void setXYZ(float X,float Y,float Z)
      {x = X; y = Y; z = Z;}
   
   public float magnitude(){
      return (float)Math.sqrt(x*x + y*y + z*z);
   }
   
   public void add(Vector3D vector){
      x += vector.x;
      y += vector.y;
      z += vector.z;
   }
   
   public void subtract(Vector3D vector){
      x -= vector.x;
      y -= vector.y;
      z -= vector.z;
   }
   
   public void scalar(float scalar){
      x = x * scalar;
      y = y * scalar;
      z = z * scalar;
   }
   
   public void divide(float scalar){
      x = x / scalar;
      y = y / scalar;
      z = z / scalar;
   }
   
   public float dotProduct(Vector3D vector){
      return (float) (x * vector.x) + (y * vector.y) + (z * vector.z);      
   }
   
   public Vector3D crossProduct(Vector3D vector){
      float crossX = y * vector.z + vector.y * z;
        float crossY = z * vector.x - vector.z * x;
        float crossZ = x * vector.y - vector.x * y;
        return new Vector3D(crossX, crossY, crossZ);
   }
   
   public void normalize(){
      float mag = magnitude();
      if(mag > 0){ divide(mag); }
   }
   
   public float distance(Vector3D vector){
      float distanceX = x - vector.x,
            distanceY = y - vector.y,
            distanceZ = z - vector.z;
      return (float)Math.sqrt(distanceX * distanceX +
                           distanceY * distanceY +
                           distanceZ * distanceZ);
     
   }
   
   public float angleBetween(Vector3D vector){
      float dot = dotProduct(vector);
      float theta = (float)Math.acos(dot / (magnitude() * vector.magnitude()));
      return theta;
   }

   
}


Camera3D.Java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
public class Camera3D extends Vector3D{
   public float anglex, angley, anglez;
   public float radius = 1f;
   public float focusx = 0f, focusy = 0f, focusz = 0f;
   
   public Camera3D(float X, float Y, float Z,
         float angleX, float angleY, float angleZ,
         float Radius,
         float focusX, float focusY, float focusZ){
      x = X; y = Y; z = Z;
      anglex = angleX; angley = angleY; anglez = angleZ;
      radius = Radius;
      focusx = focusX; focusy = focusY; focusz = focusZ;
   }  
}
Offline gouessej
« Reply #1 - Posted 2012-10-21 21:05:33 »

Hi

You will get more replies on the official JogAmp forum:
http://forum.jogamp.org/

What does mean "the glcanvas never updates the GluLookAt"?

Please can you chech whether your stop method is called before the end of the applet execution?

Offline cupcakey

Senior Newbie


Medals: 1



« Reply #2 - Posted 2012-10-21 21:20:03 »

Stop is not called before the end of the application.

What I mean is the perspective of the scene does not change. If I change the variables of GluLookAt durring operation the scene does not change. Even if I hide the drawing of the object or change the color of the object it only displays the first thing rendered.

Thanks for the advice on the other forum that's where I'm heading next.

I did just find this error on closing the applet:
Info: Nativewindow X11 Error (Thread: XToolkt-Shutdown-Thread): 3 - BadWindow (invalid Window parameter), dpy 0x79b55288, id 3600011, # 787: 4:0 X_DestroyWindow
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cupcakey

Senior Newbie


Medals: 1



« Reply #3 - Posted 2012-10-21 22:06:19 »

Nevermind I'm a real dumb dumb head cake face, I forgot to install new drivers for my graphics card. Works like a charm!
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.

TehJavaDev (13 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (31 views)
2014-08-16 06:45:27

Tekkerue (31 views)
2014-08-16 06:22:17

Tekkerue (19 views)
2014-08-16 06:20:21

Tekkerue (29 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (42 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
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!