Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello everyone, I have a java openGL program that will not run. Everytime I try to do so, I recieve: java.lang.NoSuchMethodError: com.jogamp.common.os.Platform.initSingleton()V at com.jogamp.opengl.GLProfile. (GLProfile.java:147)

Hello everyone, I have a java openGL program that will not run. Everytime I try to do so, I recieve:

java.lang.NoSuchMethodError: com.jogamp.common.os.Platform.initSingleton()V

at com.jogamp.opengl.GLProfile.(GLProfile.java:147)

at GraphicsScene.main(GraphicsScene.java:343)

I have spent the past few hours trying to find a fix via google and jogl docs but have not succeeded. I have tried different/older builds of jogl and that has not worked as well. I am hoping another set of eyes with greater knowledge of jogl can assist me. Thanks

JAR File:

link: https://jogamp.org/deployment/jogamp-current/archive/

file name: "jogamp-all-platforms.7z 2015-10-10 05:03 53M"

//file is marked with a "?"

GraphicsScene.java

import java.awt.*; import javax.swing.*; import java.awt.event.*; import com.jogamp.opengl.*; import com.jogamp.opengl.GL2; import com.jogamp.opengl.awt.GLCanvas; import com.jogamp.opengl.glu.GLU; import com.jogamp.opengl.util.FPSAnimator; import com.jogamp.common.os.Platform.*; //GraphicsScene public class GraphicsScene implements GLEventListener{ private GLU glu = new GLU(); private static GraphicsEnvironment Scene; private static boolean Flag = false; public static DisplayMode dm, dm_old; private static Dimension DimXgraph; private static Point point = new Point(0, 0); private float DimRQ=0.0f, DimRT =0.0f; @Override public void display(GLAutoDrawable drawable) { float R =3, r =2; int N=5, n=4; int maxn= 1000; // max precision n=Math.min(n,maxn-1); N=Math.min(N,maxn-1); float rr=1.5f*r; double dv=2*Math.PI/n; double dw=2*Math.PI/N; double v=0.0f; double w=0.0f; int i, j,longs=20,lats=15; final GL2 gl = drawable.getGL().getGL2(); // Clear The Screen And The Depth Buffer gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(-2.0f,1.3f,-6.0f); gl.glRotatef(DimRT, 0.0f, 1.0f, 0.0f); // start drawing TRIANGLES gl.glBegin(GL2.GL_TRIANGLES); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glVertex3f(0.0f, 1.0f, 0.0f); gl.glColor3f(0.0f, 1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 1.0f); gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(1.0f, -1.0f, 1.0f); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glVertex3f(0.0f, 1.0f, 0.0f); gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(1.0f, -1.0f, 1.0f); gl.glColor3f(0.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, -1.0f); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glVertex3f(0.0f, 1.0f, 0.0f); gl.glColor3f(0.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, -1.0f); gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glVertex3f(0.0f, 1.0f, 0.0f); gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f); gl.glColor3f(0.0f, 1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 1.0f); gl.glEnd(); // Done Drawing The Pyramid // start drawing Cube gl.glLoadIdentity(); gl.glTranslatef(0.2f, 1.6f, -8.0f); gl.glRotatef(DimRQ, 1.0f, 1.0f, 1.0f); // Rotate The Cube On X, Y & Z gl.glBegin(GL2.GL_QUADS); // Start Drawing The Cube gl.glColor3f(0.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, 1.0f, -1.0f); gl.glVertex3f(-1.0f, 1.0f, -1.0f); gl.glVertex3f(-1.0f, 1.0f, 1.0f); gl.glVertex3f(1.0f, 1.0f, 1.0f); gl.glColor3f(1.0f, 0.5f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 1.0f); gl.glVertex3f(-1.0f, -1.0f, 1.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f); gl.glVertex3f(1.0f, -1.0f, -1.0f); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glVertex3f(1.0f, 1.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, 1.0f); gl.glVertex3f(-1.0f, -1.0f, 1.0f); gl.glVertex3f(1.0f, -1.0f, 1.0f); gl.glColor3f(1.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, -1.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f); gl.glVertex3f(-1.0f, 1.0f, -1.0f); gl.glVertex3f(1.0f, 1.0f, -1.0f); gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, -1.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f); gl.glVertex3f(-1.0f, -1.0f, 1.0f); gl.glColor3f(1.0f, 0.0f, 1.0f); gl.glVertex3f(1.0f, 1.0f, -1.0f); gl.glVertex3f(1.0f, 1.0f, 1.0f); gl.glVertex3f(1.0f, -1.0f, 1.0f); gl.glVertex3f(1.0f, -1.0f, -1.0f); gl.glEnd(); // Done Drawing The Quad // DRAWING circle gl.glLoadIdentity(); gl.glTranslatef(3.5f, 1.5f, -9.0f); // Move Right And Into The Screen gl.glRotatef(DimRQ, 1.0f, 1.0f, 1.0f); // Rotate The Cube On X, Y & Z gl.glBegin(GL2.GL_QUAD_STRIP); // Start Drawing The Cube for(i = 0; i <= lats; i++) { double lat0 = Math.PI * (-0.5 + (double) (i - 1) / lats); double z0 = Math.sin(lat0); double zr0 = Math.cos(lat0); double lat1 = Math.PI * (-0.5 + (double) i / lats); double z1 = Math.sin(lat1); double zr1 = Math.cos(lat1); for(j = 0; j <= longs; j++) { double lng = 2 * Math.PI * (double) (j - 1) / longs; double x = Math.cos(lng); double y = Math.sin(lng); gl.glColor3d(1.0*j, (1.0*i), 2.0*j); gl.glNormal3d(x * zr0, y * zr0, z0); gl.glVertex3d(x * zr0, y * zr0, z0); gl.glNormal3d(x * zr1, y * zr1, z1); gl.glVertex3d(x * zr1, y * zr1, z1); } } gl.glEnd(); // Start Drawing The Rectangle gl.glLoadIdentity(); gl.glTranslatef(-6.0f, -2.3f, -15.0f); // Move Right And Into The Screen gl.glRotatef(DimRQ, 1.0f, 1.0f, 1.0f); // Rotate The Cube On X, Y & Z gl.glBegin(GL2.GL_QUADS); gl.glColor3f(0.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, 2.0f, -3.0f); gl.glVertex3f(-1.0f, 2.0f, -3.0f); gl.glVertex3f(-1.0f, 2.0f, 3.0f); gl.glVertex3f(1.0f, 2.0f, 3.0f); gl.glColor3f(1.0f, 0.9f, 0.0f); gl.glVertex3f(1.0f, -2.0f, 3.0f); gl.glVertex3f(-1.0f, -2.0f, 3.0f); gl.glVertex3f(-1.0f, -2.0f, -3.0f); gl.glVertex3f(1.0f, -2.0f, -3.0f); gl.glColor3f(1.0f, 0.0f, 0.2f); gl.glVertex3f(1.0f, 2.0f, 3.0f); gl.glVertex3f(-1.0f, 2.0f, 3.0f); gl.glVertex3f(-1.0f, -2.0f, 3.0f); gl.glVertex3f(1.0f, -2.0f, 3.0f); gl.glColor3f(1.0f, 1.0f, 0.6f); gl.glVertex3f(1.0f, -2.0f, -3.0f); gl.glVertex3f(-1.0f, -2.0f, -3.0f); gl.glVertex3f(-1.0f, 2.0f, -3.0f); gl.glVertex3f(1.0f, 2.0f, -1.0f); gl.glColor3f(0.0f, 0.0f, 1.7f); gl.glVertex3f(-1.0f, 2.0f, 3.0f); gl.glVertex3f(-1.0f, 2.0f, -3.0f); gl.glVertex3f(-1.0f, -2.0f, -3.0f); gl.glVertex3f(-1.0f, -2.0f, 3.0f); gl.glColor3f(1.0f, 0.1f, 1.9f); gl.glVertex3f(1.0f, 2.0f, -3.0f); gl.glVertex3f(1.0f, 2.0f, 3.0f); gl.glVertex3f(1.0f, -2.0f, 3.0f); gl.glVertex3f(1.0f, -2.0f, -3.0f); gl.glEnd(); // Done Drawing //Start Drawing The Quinary gl.glLoadIdentity(); gl.glTranslatef(-0.0f, -1.9f, -15.0f); // Move Right And Into The Screen gl.glRotatef(DimRQ, 1.0f, 1.0f, 1.0f); // Rotate The Cube On X, Y & Z // outer loop while(w<2*Math.PI+dw) { v=0.0f; gl.glBegin(GL2.GL_TRIANGLE_STRIP); // inner loop while(v<2*Math.PI+dv) { gl.glNormal3d( (R+rr*Math.cos(v))*Math.cos(w)-(R+r*Math.cos(v))*Math.cos(w), (R+rr*Math.cos(v))*Math.sin(w)-(R+r*Math.cos(v))*Math.sin(w), (rr*Math.sin(v)-r*Math.sin(v))); gl.glVertex3d((R+r*Math.cos(v))*Math.cos(w), (R+r*Math.cos(v))*Math.sin(w), r*Math.sin(v)); gl.glNormal3d( (R+rr*Math.cos(v+dv))*Math.cos(w+dw)-(R+r*Math.cos(v+dv))*Math.cos(w+dw), (R+rr*Math.cos(v+dv))*Math.sin(w+dw)-(R+r*Math.cos(v+dv))*Math.sin(w+dw), rr*Math.sin(v+dv)-r*Math.sin(v+dv)); gl.glVertex3d((R+r*Math.cos(v+dv))*Math.cos(w+dw), (R+r*Math.cos(v+dv))*Math.sin(w+dw), r*Math.sin(v+dv)); v+=dv; } // inner loop gl.glEnd(); w+=dw; } //outer loop //Start Drawing The 3D lines gl.glLoadIdentity(); // Move Right And Into The Screen gl.glTranslatef(5.0f, -2.0f, -10.0f); gl.glRotatef(DimRQ, 1.0f, 1.0f, 1.0f); gl.glBegin(GL2.GL_LINES); gl.glVertex3f(-0.75f,0f,3f); gl.glVertex3f(0f,-0.75f,3f); gl.glVertex3f(-0.75f,0f,0); gl.glVertex3f(-0.75f,0f,3f); gl.glVertex3f(0f,-0.75f, 0); gl.glVertex3f(0f,-0.75f,3f); gl.glEnd(); gl.glFlush(); DimRT +=0.2f; DimRQ -=0.15f; } @Override public void init(GLAutoDrawable drawable) { final GL2 GLANCE = drawable.getGL().getGL2(); GLANCE.glShadeModel(GL2.GL_SMOOTH); GLANCE.glClearColor(0f, 0f, 0f, 0f); GLANCE.glClearDepth(1.0f); GLANCE.glEnable(GL2.GL_DEPTH_TEST); GLANCE.glDepthFunc(GL2.GL_LEQUAL); GLANCE.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST); } @Override public void reshape(GLAutoDrawable drawable, int x, int y, int W,int H) { final GL2 GLU = drawable.getGL().getGL2(); if(H <=0) H =1; final float h = (float) W / (float) H; GLU.glViewport(0, 0, W, H); GLU.glMatrixMode(GL2.GL_PROJECTION); GLU.glLoadIdentity(); glu.gluPerspective(45.0f, h, 1.0, 20.0); GLU.glMatrixMode(GL2.GL_MODELVIEW); GLU.glLoadIdentity(); } /**  * @param args  */  public static void main(String[] args) throws SecurityException{ try{ final GLProfile profile = GLProfile.get(GLProfile.GL2); GLCapabilities capabilities = new GLCapabilities(profile); // The canvas final GLCanvas glcanvas = new GLCanvas(capabilities); GraphicsScene r = new GraphicsScene(); glcanvas.addGLEventListener(r); glcanvas.setSize(640, 480); final FPSAnimator animator = new FPSAnimator(glcanvas, 100,true ); final JFrame frame = new JFrame ("3D Graphic scene"); frame.getContentPane().add(glcanvas); //Shutdown frame.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ if(animator.isStarted()) animator.stop(); System.exit(0); } }); frame.setSize(frame.getContentPane().getPreferredSize()); Scene = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] devices = Scene.getScreenDevices(); dm_old = devices[0].getDisplayMode(); dm = dm_old; Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int windowX = Math.max(0, (screenSize.width - frame.getWidth()) / 2); int windowY = Math.max(0, (screenSize.height - frame.getHeight()) / 2); frame.setLocation(windowX, windowY); JPanel p = new JPanel(); p.setPreferredSize(new Dimension(0,0)); frame.add(p, BorderLayout.SOUTH); KeyCorrelation(p, frame, r); animator.start(); frame.setVisible(true); }catch (NoSuchMethodError error){ error.printStackTrace(); } } private static void KeyCorrelation(JPanel p, final JFrame frame, final GraphicsScene r) { ActionMap actionMap = p.getActionMap(); InputMap inputMap = p.getInputMap(); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), "F1"); actionMap.put("F1", new AbstractAction(){ @Override public void actionPerformed(ActionEvent drawable) { DisplayFullScreen(frame); }}); } protected static void DisplayFullScreen(JFrame f) { if(!Flag){ f.dispose(); f.setUndecorated(true); f.setVisible(true); f.setResizable(false); DimXgraph = f.getSize(); point = f.getLocation(); f.setLocation(0, 0); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); f.setSize((int) screenSize.getWidth(), (int) screenSize.getHeight()); Flag=true; }else{ f.dispose(); f.setUndecorated(false); f.setResizable(true); f.setLocation(point); f.setSize(DimXgraph); f.setVisible(true); Flag =false; } } @Override public void dispose(GLAutoDrawable drawable) { } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Icdt 88 2nd International Conference On Database Theory Bruges Belgium August 31 September 2 1988 Proceedings Lncs 326

Authors: Marc Gyssens ,Jan Paredaens ,Dirk Van Gucht

1st Edition

3540501711, 978-3540501718

More Books

Students also viewed these Databases questions

Question

Does it use a maximum of two typefaces or fonts?

Answered: 1 week ago