Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (756)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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  
  could somebody take a look at my code?  (Read 3831 times)
0 Members and 1 Guest are viewing this topic.
Offline wakeboardin

Senior Newbie




Java games rock!


« Posted 2005-08-08 04:49:53 »

took the "Getting started with jogl" code and expanded
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  
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();
       }
   }
}

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  
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)
   {
   }

}
Offline Riven
Administrator

« JGO Overlord »


Medals: 1340
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2005-08-08 07:54:24 »

1  
2  
3  
4  
5  
           GLCapabilities glCaps = new GLCapabilities();
           glCaps.setRedBits(32);
           glCaps.setBlueBits(32);
           glCaps.setGreenBits(32);
           glCaps.setAlphaBits(32);


It might be me, but shouldn't that be 8 instead of 32...

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

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline wakeboardin

Senior Newbie




Java games rock!


« Reply #2 - Posted 2005-08-08 16:19:52 »

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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline wakeboardin

Senior Newbie




Java games rock!


« Reply #3 - Posted 2005-08-08 16:20:25 »

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

JGO Coder




Java games rock!


« Reply #4 - Posted 2005-08-08 21:55:10 »

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

Senior Newbie




Java games rock!


« Reply #5 - Posted 2005-08-08 22:43:53 »

that wouldn't fix it but thanks for the tip.
Is GL really all that much to cache?
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #6 - Posted 2005-08-08 23:19:06 »

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.
Offline wakeboardin

Senior Newbie




Java games rock!


« Reply #7 - Posted 2005-08-09 00:57:17 »

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

JGO Coder




Java games rock!


« Reply #8 - Posted 2005-08-09 01:21:45 »

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.
Offline wakeboardin

Senior Newbie




Java games rock!


« Reply #9 - Posted 2005-08-09 02:38:16 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #10 - Posted 2005-08-09 03:44:13 »

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.
Offline wakeboardin

Senior Newbie




Java games rock!


« Reply #11 - Posted 2005-08-09 15:59:54 »

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.
Pages: [1]
  ignore  |  Print  
 
 

 
DesertCoockie (52 views)
2018-05-13 18:23:11

nelsongames (83 views)
2018-04-24 18:15:36

nelsongames (74 views)
2018-04-24 18:14:32

ivj94 (759 views)
2018-03-24 14:47:39

ivj94 (87 views)
2018-03-24 14:46:31

ivj94 (643 views)
2018-03-24 14:43:53

Solater (102 views)
2018-03-17 05:04:08

nelsongames (184 views)
2018-03-05 17:56:34

Gornova (426 views)
2018-03-02 22:15:33

buddyBro (1086 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!