Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (116)
games submitted by our members
Games in WIP (563)
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 / Help with Surface-Of-Revolution on: 2005-04-02 00:47:10
I am trying to do a surface-of-revolution and display the object as a wireframe representation, rotating around and saving the points


It has no compile errors, but it has a runtime error in the black screen saying:

java.lang.NullPointerException
       at Rotation6$Renderer.display(Rotation6.java:205)
       at net.java.games.jogl.impl.GLDrawableHelper.display(GLDrawableHelper.ja
va:74)
       at net.java.games.jogl.GLCanvas$DisplayAction.run(GLCanvas.java:194)
       at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:192)
       at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:182)
       at net.java.games.jogl.GLCanvas.display(GLCanvas.java:82)
       at net.java.games.jogl.Animator$1.run(Animator.java:104)
       at java.lang.Thread.run(Thread.java:536)

how do I fix this problem?

-----------------------------------------------------------------------

here is the code




import java.awt.*;
import java.awt.event.*;
import java.nio.IntBuffer;
import net.java.games.jogl.*;
import net.java.games.jogl.util.*;



public class Rotation6

{


static Animator animator = null;



public static void main(String[] args)

{

Frame frame = new Frame("Rotation ");

GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());

canvas.addGLEventListener(new Renderer());

frame.add(canvas);

frame.setSize(500, 500);

animator = new Animator(canvas);

frame.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

animator.stop();

System.exit(0);

}

});

frame.show();

animator.start();

canvas.requestFocus();



} // end main



static class Renderer implements GLEventListener, KeyListener {
 
 private float rtri = 0.0f;
 



public class wcPt3D {

     public float x, y, z;

     

     wcPt3D(float xcoord, float ycoord, float zcoord){

           x= xcoord;

           y= ycoord;
             
           z= zcoord;

    }

   

    wcPt3D( ){

    x = 0.0f;

    y = 0.0f;
   
    z = 0.0f;

     }
     
     

} // end wcpt3d



public void init(GLDrawable gLDrawable)

{

final GL gl = gLDrawable.getGL();

final GLU glu = gLDrawable.getGLU();



gl.glMatrixMode (GL.GL_PROJECTION);

gl.glClearColor (1.0f, 0.0f, 0.0f, 0.0f); //set background to white

gl.glClearDepth(1.0f); // Depth Buffer Setup

gl.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing

gl.glDepthFunc(GL.GL_LEQUAL); // The Type Of Depth Testing To Do

gl.glOrtho (-2.0, 2.0, -2.0, 2.0, -15.0, 15.0); // define drawing area
gl.glClearColor (0.0f, 0.0f, 0.0f, 0.0f);

gLDrawable.addKeyListener(this);

}







public void keyReleased(KeyEvent e) {}



public void keyTyped(KeyEvent e) {}




public void display(GLDrawable gLDrawable)

{

final GL gl = gLDrawable.getGL();

final GLU glu = gLDrawable.getGLU();



gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Set display window to color.

gl.glMatrixMode (GL.GL_MODELVIEW);



gl.glLoadIdentity();

gl.glRotatef(rtri, 0.0f, 2.0f, 0.0f);


gl.glBegin(GL.GL_LINES); //drawing using lines

wcPt3D[][] p1 = new wcPt3D[10][36];

float angle=0.0f;

     int i =0;
     

p1[0][0] =new wcPt3D (0.150f, 0.750f, 0.000f);
p1[1][0] =new wcPt3D (0.450f, 0.750f, 0.000f);
p1[2][0] =new wcPt3D (0.450f, 0.750f, 0.000f);
p1[3][0] =new wcPt3D (0.650f, 0.500f, 0.000f);
p1[4][0] =new wcPt3D (0.650f, 0.500f, 0.000f);
p1[5][0] =new wcPt3D (0.350f, 0.350f, 0.000f);
p1[6][0] =new wcPt3D (0.350f, 0.350f, 0.000f);
p1[7][0] =new wcPt3D (0.150f, 0.350f, 0.000f);
p1[8][0] =new wcPt3D (0.150f, 0.350f, 0.000f);
p1[9][0] =new wcPt3D (0.150f, 0.150f, 0.000f);

for (int row = 0; row < 36; row++) {
     gl.glBegin(GL.GL_LINES);
        
        for (int col = 0; col < 10; col++) {
           gl.glVertex3f(p1[row][col].x, p1[row][col].y, p1[row][col].z);



     }
gl.glEnd();
}



/*gl.glVertex3f(0.150f, 0.750f, 0.000f);
gl.glVertex3f(0.450f, 0.750f, 0.000f);
gl.glVertex3f(0.450f, 0.750f, 0.000f);
gl.glVertex3f(0.650f, 0.500f, 0.000f);
gl.glVertex3f(0.650f, 0.500f, 0.000f);
gl.glVertex3f(0.350f, 0.350f, 0.000f);
gl.glVertex3f(0.350f, 0.350f, 0.000f);
gl.glVertex3f(0.150f, 0.350f, 0.000f);
gl.glVertex3f(0.150f, 0.350f, 0.000f);
gl.glVertex3f(0.150f, 0.150f, 0.000f);
*/









gl.glEnd(); // Finished

rtri += 0.2f;

//}
gl.glFlush();
}

public void displayChanged(GLDrawable gLDrawable, boolean modeChanged, boolean deviceChanged)

{

}



public void reshape(GLDrawable gLDrawable, int x, int y, int width, int height)

{



}
public void keyPressed(KeyEvent e)

{

if (e.getKeyCode() == KeyEvent.VK_ESCAPE)

animator.stop();

System.exit(0);

}

   




public void rotate3D (wcPt3D[][] p1)

{



float deg = 0;
float RadianAngle = (float)(180/Math.PI);
 
     for (int row = 0; row < 36; row++) {
     

     for (int col = 0; col < 10; col++) {
     
   float zp = p1[row][col].z * (float)Math.cos(deg * RadianAngle) - p1[row][col].x * (float)Math.sin(deg * RadianAngle);
   float xp = p1[row][col].z * (float)Math.sin(deg * RadianAngle) + p1[row][col].x * (float)Math.cos(deg * RadianAngle);
   float yp = p1[row][col].y;
     
 p1[row][col] = new wcPt3D(xp, yp, zp);

 
  deg += 10.0f;
 
   }
   
     }
          
    }
     
public void draw3D (wcPt3D[][] p1, GL gl)

{


for (int row = 0; row < 36; row++) {
     gl.glBegin(GL.GL_LINES);
        
        for (int col = 0; col < 10; col++) {
           gl.glVertex3f(p1[row][col].x, p1[row][col].y, p1[row][col].z);
   


     }
gl.glEnd();
}


}







}

}
2  Java Game APIs & Engines / JOGL Development / Re: Help with barchart program on: 2005-01-08 00:29:10
I have made some changes to the program and called the BarChart2 and winReshapeFcn inside the display. It compiles ok and has no errors, but I still get that blank black screen at execution(BarChart screen) and no display of the barchart.

import java.awt.*;
import java.awt.event.*;
import net.java.games.jogl.*;
import net.java.games.jogl.util.*;

public class BarChart2 {



public static void main(String[] args)

 {
 
   
   Frame frame = new Frame("Bar Chart");

   GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());

   canvas.addGLEventListener(new Renderer());
 
   frame.add(canvas);

   frame.setSize(500, 600);

frame.addWindowListener(new WindowAdapter()

   {

     public void windowClosing(WindowEvent e)

     {

       

       System.exit(0);

     }

   });

   frame.show();
 
   canvas.requestFocus();
}

static class Renderer implements GLEventListener, KeyListener

 {
       

   


public void init(GLDrawable gLDrawable)

   {
final GL gl = gLDrawable.getGL();
final GLU glu = gLDrawable.getGLU();
gl.glColor3f (0.0f, 0.0f, 0.75f);  
gl.glMatrixMode (GL.GL_PROJECTION);  
gl.glLoadIdentity();

     

     //lineSegment(gLDrawable.getGL());
}
 


   
public void display(GLDrawable gLDrawable)//, int winWidth, int winHeight)


   {

    final GL gl = gLDrawable.getGL();
    final GLU glu = gLDrawable.getGLU();
    final GLUT glut = new GLUT();
   

   

   
     gl.glClear (GL.GL_COLOR_BUFFER_BIT);// Set display to color.

     gl.glColor3f (0.0f, 0.0f, 0.75f);  

             
     winReshapeFcn (gl, glu);//, gluOrtho2D, glClear); //, //GL_COLOR_BUFFER_BIT);    

     BarChart2(gl, glut);
     gl.glMatrixMode (GL.GL_MODELVIEW);

     gl.glLoadIdentity();



int winWidth = 600;
int winHeight = 500; //Initial display window size
int xRaster = 25;
int yRaster = 150;
/*gl.GLubyte*/ char[] label /*[36]*/  = { 'J','a','n', 'F','e','b', 'M','a','r',
                      'A','p','r', 'M','a','y', 'J','u','n',
                      'J','u','l', 'A','u','g', 'S','e','p',
                      'O','c','t', 'N','o','v', 'D','e','c' };


int[] dataValue /*[12]*/  = {420, 342, 324, 310, 262, 185,
                       190, 196, 217, 240, 312, 438 };
   
gl.glClearColor (1.0f, 1.0f, 0.0f, 0.0f); //White display window
gl.glMatrixMode (GL.GL_PROJECTION);                    
 }

 

public void displayChanged(GLDrawable gLDrawable, boolean modeChanged, boolean deviceChanged)

   {

   }

  public void reshape(GLDrawable gLDrawable, int x, int y, int width, int height)

   {

     

   }



   


public void BarChart2 (GL gl, GLUT glut)//, int xRaster, int yRaster, int[] dataValue)//,  //char[] label, char h)
{

     int xRaster;
     int yRaster;
     int month;
//      int[] dataValue;
     char[] label;
     int k;
     char h;

 int[] dataValue  = {420, 342, 324, 310, 262, 185,
                       190, 196, 217, 240, 312, 438 };
     
     //gl.glClear (GL.GL_COLOR_BUFFER_BIT); //Clear display window
     
     gl.glColor3f (1.0f, 1.0f,0.0f); // Set bar color to red
     for (k = 0; k < 12; k++)
     
     gl.glRecti (20 + k*50, 165, 40 + k*50, dataValue [k]);
     
//      gl.glColor4f (1.0f, 1.0f, 1.0f, 1.0f); // Set test color to black
     xRaster = 25; //20;              // Display chart labels
     yRaster = 150;
     for (month = 0; month < 12; month++) {
           gl.glRasterPos2i (xRaster, yRaster);
           for (k = 3*month; k <3 * month + 3; k++)
     //glut.glutBitmapCharacter(GLUT.BITMAP_HELVETICA_12, label [h]);       //glut.glutBitmapCharacter  //(GLUT.BITMAP_HELVETICA_12,//label[h]);
           xRaster +=50;


     }
gl.glFlush ();      
}
     

     

public void winReshapeFcn (GL gl, GLU glu)//, GLU gluOrtho2D, GL glClear)//, GL GL_COLOR_BUFFER_BIT)    
{
     
     double newWidth =0.0;
     double newHeight= 0.0;
     GL GL_COLOR_BUFFER_BIT;
     GLU gluOrtho2D;
     GL glClear;
     gl.glMatrixMode (GL.GL_PROJECTION);
     gl.glLoadIdentity ();
     glu.gluOrtho2D (0.0, (double) newWidth, 0.0, (double) newHeight);
     gl.glClear (GL.GL_COLOR_BUFFER_BIT);

     

     }




   

   public void keyPressed(KeyEvent e)

   {

     if (e.getKeyCode() == KeyEvent.VK_ESCAPE)

       System.exit(0);

   }
   

   public void keyReleased(KeyEvent e) {}

   

   public void keyTyped(KeyEvent e) {}

     

 

 }


}
3  Java Game APIs & Engines / JOGL Development / Re: Help with barchart program on: 2004-12-31 03:43:44
whenever I try anything.BarChart2() I get a cannot resolve symbol error
4  Java Game APIs & Engines / JOGL Development / Help with barchart program on: 2004-12-30 02:55:06
Whenever I run this, it compiles, but I get a black screen, what can I do to get the barchart to show up?


import java.awt.*;
import java.awt.event.*;
import net.java.games.jogl.*;
import net.java.games.jogl.util.*;

public class BarChart2 {


public static void main(String[] args)

 {

   Frame frame = new Frame("Bar Chart");

   GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());

   canvas.addGLEventListener(new Renderer());
   //frame.display();
   frame.add(canvas);

   frame.setSize(500, 600);



     

   frame.addWindowListener(new WindowAdapter()

   {

     public void windowClosing(WindowEvent e)

     {

       

       System.exit(0);

     }

   });

   frame.show();

   canvas.requestFocus();
}
static class Renderer implements GLEventListener, KeyListener

 {
       



     


public void init(GLDrawable gLDrawable)

   {
final GL gl = gLDrawable.getGL();
final GLU glu = gLDrawable.getGLU();
gl.glColor3f (0.0f, 0.0f, 0.75f);  
gl.glMatrixMode (GL.GL_PROJECTION);  
gl.glLoadIdentity();

     

     //lineSegment(gLDrawable.getGL());

   

   }


   
public void display(GLDrawable gLDrawable)//, int winWidth, int winHeight)


   {

    final GL gl = gLDrawable.getGL();
    final GLU glu = gLDrawable.getGLU();
 
   
     gl.glClear (GL.GL_COLOR_BUFFER_BIT);// Set display to color.

           //gl.glColor3f (0.0f, 0.0f, 0.75f);  

             

     gl.glMatrixMode (GL.GL_MODELVIEW);

     gl.glLoadIdentity();



int winWidth = 600;
int winHeight = 500; //Initial display window size
//setSize (600,500);
//gl.GLint xRaster = 25;
//gl.GLint yRaster = 150; //Initialize raster position
int xRaster = 25;
int yRaster = 150;
/*gl.GLubyte*/ char[] label /*[36]*/  = { 'J','a','n', 'F','e','b', 'M','a','r',
                      'A','p','r', 'M','a','y', 'J','u','n',
                      'J','u','l', 'A','u','g', 'S','e','p',
                      'O','c','t', 'N','o','v', 'D','e','c' };


int[] dataValue /*[12]*/  = {420, 342, 324, 310, 262, 185,
                       190, 196, 217, 240, 312, 438 };
   
gl.glClearColor (1.0f, 1.0f, 0.0f, 0.0f); //White display window
gl.glMatrixMode (GL.GL_PROJECTION);                    
 }

 

public void displayChanged(GLDrawable gLDrawable, boolean modeChanged, boolean deviceChanged)

   {

   }

  public void reshape(GLDrawable gLDrawable, int x, int y, int width, int height)

   {

     

   }



   







public void BarChart2 (GL gl, GLUT glut, int xRaster, int yRaster, int[] dataValue,  char[] label, char h)
{
//      char[] label;
     int month;
     int k;
//      char h;
     gl.glClear (GL.GL_COLOR_BUFFER_BIT); //Clear display window
     
     gl.glColor3f (1.0f, 1.0f,0.0f); // Set bar color to red
     for (k = 0; k < 12; k++)
     
     gl.glRecti (20 + k*50, 165, 40 + k*50, dataValue [k]);
     
//      gl.glColor4f (1.0f, 1.0f, 1.0f, 1.0f); // Set test color to black
     xRaster = 20;              // Display chart labels
     for (month = 0; month < 12; month++) {
           gl.glRasterPos2i (xRaster, yRaster);
           for (k = 3*month; k <3 * month + 3; k++)
     //glut.glutBitmapCharacter(GLUT.BITMAP_HELVETICA_12, label [h]);       //glut.glutBitmapCharacter  //(GLUT.BITMAP_HELVETICA_12,//label[h]);
           xRaster +=50;
     
     
     }
gl.glFlush ();      

}      

public void winReshapeFcn (GL gl, GLU glu, int newWidth, int newHeight, GLU gluOrtho2D, GL glClear, GL GL_COLOR_BUFFER_BIT)    
{
     gl.glMatrixMode (GL.GL_PROJECTION);
     gl.glLoadIdentity ();
     glu.gluOrtho2D (0.0, (double) newWidth, 0.0, (double) newHeight);
     gl.glClear (GL.GL_COLOR_BUFFER_BIT);

     

     }



   

   public void keyPressed(KeyEvent e)

   {

     if (e.getKeyCode() == KeyEvent.VK_ESCAPE)

       System.exit(0);

   }
   

   public void keyReleased(KeyEvent e) {}

   

   public void keyTyped(KeyEvent e) {}

 }


}

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.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (30 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (28 views)
2014-09-20 20:14:06

BurntPizza (32 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24: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!