could somebody take a look at my code?

took the “Getting started with jogl” code and expanded


import net.java.games.jogl.*;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class test
{
   public static void main( String[] args )
   {
       try
       {
           Frame testFrame = new Frame("TestFrame");
           testFrame.setSize( 512, 384 );

           GLCapabilities glCaps = new GLCapabilities();
           glCaps.setRedBits(32);
           glCaps.setBlueBits(32);
           glCaps.setGreenBits(32);
           glCaps.setAlphaBits(32);

           GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas( glCaps );

           testFrame.add( canvas );

           canvas.addGLEventListener(new TestRenderer());

           final Animator animator = new Animator( canvas);
           testFrame.addWindowListener(new WindowAdapter() {
               public void windowClosing(WindowEvent e) {
                 animator.stop();
                 System.exit(0);
               }
             });
           testFrame.show();
           animator.start();
       }
       catch( Exception e )
       {
           e.printStackTrace();
       }
   }
}



import net.java.games.jogl.GLEventListener;
import net.java.games.jogl.GL;
import net.java.games.jogl.GLDrawable;
import net.java.games.jogl.DebugGL;
import demos.util.*;
import java.io.IOException;


public class TestRenderer implements GLEventListener
{
   private GL              gl;
   private GLDrawable      glDrawable;
   private ObjReader       model;

   public void init(GLDrawable drawable)
   {
       this.gl = drawable.getGL();
       this.glDrawable = drawable;

       drawable.setGL( new DebugGL(drawable.getGL() ));
	   try{
	   		model=new ObjReader("C:\\body");
       }
       catch(IOException e)
       {
       		System.out.println("error line 25");
       }
       System.out.println("Init GL is " + gl.getClass().getName());
   }

   public void display(GLDrawable drawable)
   {
       	  gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
       	  gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
          gl.glEnableClientState(GL.GL_NORMAL_ARRAY);
          gl.glVertexPointer(3, GL.GL_FLOAT, 0, model.getVertices());
          gl.glNormalPointer(GL.GL_FLOAT, 0, model.getVertexNormals());
          int[] indices = model.getFaceIndices();
          gl.glDrawElements(GL.GL_TRIANGLES, indices.length, GL.GL_UNSIGNED_INT, indices);
          gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
          gl.glDisableClientState(GL.GL_NORMAL_ARRAY);
	}
   public void reshape(GLDrawable drawable, int x, int y, int width, int height)
   {
   }

   public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged)
   {
   }

}

It might be me, but shouldn’t that be 8 instead of 32…

Futher, what’s the problem? Or isn’t there any?

alrite made that little change and here seems to be the problem
error line 25
Init GL is net.java.games.jogl.impl.windows.WindowsGLImpl
java.lang.NullPointerException
at TestRenderer.display(TestRenderer.java:36)
at net.java.games.jogl.impl.GLDrawableHelper.display(GLDrawableHelper.ja
va:74)
at net.java.games.jogl.GLCanvas$DisplayAction.run(GLCanvas.java:198)
at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:239)
at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:186)
at net.java.games.jogl.GLCanvas.display(GLCanvas.java:74)
at net.java.games.jogl.Animator$1.run(Animator.java:104)
at java.lang.Thread.run(Thread.java:534)

something is going wrong with the obj reader

sorry about not posting that earlier it was pretty late when i got home

You should not cache the GL object but instead re-fetch it at the top of your init() and display() methods each frame.

that wouldn’t fix it but thanks for the tip.
Is GL really all that much to cache?

The point is that the GL object may change for example if the window is removed and re-added to the component hierarchy. Caching the object can only lead to errors.

Looking again, you’re hitting an error loading the model which is causing the error in your display callback.

well i’ve tried every diffent constructor and 3 diffent models for each. Are there any known issues about the objReader or something

The ObjReader is not a general-purpose .obj parser, but one tailored for that particular demo. You should look at a higher-level toolkit like Xith3D which contains parsers for several file formats.

almost all obj is the same and it’s not taliored for the demo because it checks for more than 3 vertex a line why would they do that if it was taliored for the demo.

I wrote the ObjReader and assure you it is not general-purpose. For example it doesn’t support textures which is probably why it’s failing to parse the models you’re feeding it. You should look at Xith3D or another scene graph library for general-purpose model loaders.

sorry I didn’t know your wrote it. I started writing my own but i gave up it was madding. Has anybody written a loader of any sort.