Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
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] 2
1  Java Game APIs & Engines / JOGL Development / Re: Clearing memory on: 2008-11-03 03:58:30
Darn! - not JOGL related.

My bad and thank you.

Pahidla
2  Java Game APIs & Engines / JOGL Development / Re: Clearing memory on: 2008-11-02 16:15:57
No, I have about 100 objects that show in an infinite loop. By showing, I mean generate a new list and delete it when the new object shows.

The fifth time around in the attempted infinite loop, I get that error.

(I realize that I could easily solve the problem by just maintaing 100 lists and invoking them when necessary. But that's not the point, because the problem will come back when I go from 100 objects to 1000.)
3  Java Game APIs & Engines / JOGL Development / Clearing memory on: 2008-11-02 03:58:41
Hi,

I have an application that shows the result of a long simulation so it is constantly showing completely new content. After a number of iterations I get a "java.lang.InternalError: Not enough storage is available to process this command".

All I do to clear up the resources is call GL.glDeleteLists when a particular object is no longer shown. Apparently that's not enough. What else should one do to keep the memory clear?

Many thanks in advance.

Aaron
4  Java Game APIs & Engines / JOGL Development / Re: How to render to an off-screen image? on: 2008-10-29 16:30:26
Could you maybe point out a tutorial on offscreen rendering or demo that includes it. I haven't been able to find one.

Thanks a lot for all the help.
5  Java Game APIs & Engines / JOGL Development / Re: How to render to an off-screen image? on: 2008-10-29 15:24:19
No, the ORANGE is beautiful.  It's the lack of lines and the general not-sameness (what's that dark triangle on the shiny part of the sphere?)

Here's my entire display(...) method. Maybe you'll notice something.

    public void display(GLAutoDrawable drawable) {
      GL gl = drawable.getGL();
      if (takeAPictureFlag) {
        myFBO.activate(gl);
      }

      gl.glClearColor(1f, 1f, 1f, 1f);


      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

      pSetView(drawable, false);

      myLight0.pGenerate3D(drawable);

      for (int i = 0; i < my3DObjects.size(); i++) {
        gl.glCallList(my3DObjects.get(i)); // Reveals implementation
      }
      gl.glFlush();



      if (takeAPictureFlag) {
        myFBO.readFrame(gl);
        myFBO.copyFrame(gl);
//        BufferedImage bi = myFBO.getBufferedImage();
//        myFBO.saveBufferedImage("C:/pg/name.png");
//        System.out.println("Buffered Image: " + bi);

        myFBO.deactivate(gl);
        takeAPictureFlag = false;  // clear screencapture flag
      }


    }

Thank you!
6  Java Game APIs & Engines / JOGL Development / Re: How to render to an off-screen image? on: 2008-10-29 13:14:25
And I have one more problem. In the following picture, you see the rendering on the left and the "picture" on the right.

http://freeboundaries.com/screenshot.png

So something went wrong there...

Thank you again,

Pahidla
7  Java Game APIs & Engines / JOGL Development / Re: How to render to an off-screen image? on: 2008-10-29 13:02:48
Hi,

I think I was missing myFBO.copyFrame(gl); the null exception no longer happens.

So now I have to resolve several problems.

1. What's the right thing to do to have my function takeAPicture return the BufferedImage? I don't have a animator or such and everything happens only in response to keyboard and mouse events. So display() won't get tirggered until something happens.

2. If I still want to custom size, what do I do to make "init" happen again?

3. Taking a picture turns the background in my Canvas to black? Why does that happen?

Many many thanks,

Pahidla
8  Java Game APIs & Engines / JOGL Development / Re: How to render to an off-screen image? on: 2008-10-29 04:23:59
Thanks for the help.

Before, I ask more questions, I'd like to overcome the fact that I'm getting "null" for the buffered image.

I have

public void init(...) {

     GL gl = drawable.getGL();

      gl.glClearColor(1f, 1f, 1f, 1f);
      gl.glEnable(GL.GL_DEPTH_TEST);
     
      //etc

     myFBO = new FrameBufferObject(drawable.getWidth(), drawable.getHeight());
      myFBO.init(gl);
}

and in  display():

    public void display(GLAutoDrawable drawable) {
      GL gl = drawable.getGL();

      if (takeAPictureFlag) {
        myFBO.activate(gl);
      }


      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

      setView(drawable, false); //my function

      // do the drawing, call some lists
      gl.glFlush();

      if (takeAPictureFlag) {
        myFBO.readFrame(gl);
        BufferedImage bi = myFBO.getBufferedImage(); // This is null!
         myFBO.deactivate(gl);
        takeAPictureFlag = false;  // clear screencapture flag
      }
}


Anything obvious catching your eye?

Thanks again,

Pahidla
9  Java Game APIs & Engines / JOGL Development / Re: How to render to an off-screen image? on: 2008-10-29 03:40:30
Thanks - it makes sense, but not 100%.

When you say "public void init( ... )" you mean the init of the GLEventListener?

It's not 100 percent clear to me, then, how to set the size at the time of takingAPicture...

Thanks, this is really helpful.

Pahidla
10  Java Game APIs & Engines / JOGL Development / Re: How to render to an off-screen image? on: 2008-10-29 00:23:07
Hi,

Thanks a lot for your help. I really appreciate it.

I think I tried to use your code in too naive a way (shown below). I have a program that's not a game but simply displays a mesh in a GLCanvas and responds to mouse clicks and drags. I'm looking to add code that will take a snapshot of the scene to specified resolution. So here's my code:

  public BufferedImage takeAPicture(int width, int height) {
    if (myFBO == null) {
      myFBO = new FrameBufferObject(width, height);
    }
   
    GL gl = myCanvas3D.getGL();
   
    myFBO.init(myCanvas3D.getGL());
    myFBO.activate(gl);
    myFBO.readFrame(gl);

    BufferedImage bi = myFBO.getBufferedImage();
    myFBO.deactivate(gl);
     
    return bi;
  }

I think I have to tie this code into a GLEventListener, but I'm not doing that. Can you suggest a fix.

Once again, I very much appreciate your help.

Pahidla
11  Java Game APIs & Engines / JOGL Development / How to render to an off-screen image? on: 2008-10-28 22:34:16
Hi,

I upgraded the version of jogl from three years ago and discovered that my code no longer works. For example, where did GLCanvas.createOffscreenDrawable go?

More importantly, can someone point out a howto on rendering to an off-screen buffer for the purposes of creating an image?

Many thank in advance!

Pahidla
12  Java Game APIs & Engines / JOGL Development / Re: Sudden lighting - what am I doing wrong? on: 2008-10-26 17:04:50
Never mind - messed up normals.
13  Java Game APIs & Engines / JOGL Development / Sudden lighting - what am I doing wrong? on: 2008-10-26 14:07:24
Hi,

Here's a link to a little app that I have created. I have a single light source. I keep the location of the object and the light and simply change the angle from which I look at the object. I expect smooth results as I am flying around the object but instead the object lights up suddenly. Any idea what I might be doing wrong?

http://freeboundaries.com/Rotate.html

Many thanks in advance,

Pahidla
14  Java Game APIs & Engines / JOGL Development / Re: "On-demand" mode modification to tut on: 2005-01-15 05:00:56
OK, thanks for all the help!
After simplifying my code things just worked. Here's my on-demand mode demo if anyone finds it useful. Drag to rotate, shift-drag to zoom, double-click to change the presence of perspective, ctrl-drag to change the degree of perspective.

Please comment if I'm doing something wrong.

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import net.java.games.jogl.*;

public class OnDemandDemo {
 public static void main(String[] inArgs) { new OnDemandDemo(); }

 private GLCanvas myGLCanvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());

 private double myTheta = Math.PI/2;
 private double myPhi   = -Math.PI/2;
 private double myZoom  = 2.0;
 private double myPerspAngle = Math.PI/3;
 private boolean myPerspectivePresent = true;

 public OnDemandDemo() {
   super();

   MouseListeners il = new MouseListeners();
   myGLCanvas.addMouseListener(il);
   myGLCanvas.addMouseMotionListener(il);
   myGLCanvas.addGLEventListener(new OnScreenGLEventListener());
   myGLCanvas.setSize(400, 400);
   myGLCanvas.repaint();

   javax.swing.JFrame frame = new javax.swing.JFrame("On Demand Mode Demonstration");
   frame.getContentPane().add(myGLCanvas);
   frame.pack();
   frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
   frame.setVisible(true);
 }

 public class OnScreenGLEventListener implements GLEventListener {
   public void init(GLDrawable inDrawable) {
     GL gl = inDrawable.getGL();

     gl.glClearColor(1f, 1f, 1f, 1f);

     gl.glEnable(GL.GL_DEPTH_TEST);
     gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
     gl.glEnable(GL.GL_POLYGON_OFFSET_LINE);

     gl.glEnable(GL.GL_LIGHTING);
     gl.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, new float[] { 1f, 1f, 1f, 1f });

     gl.glDisable(GL.GL_CULL_FACE) ;
     gl.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE, GL.GL_TRUE) ;
   }

   public void display(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
   public void displayChanged(GLDrawable inDrawable, boolean inWhat, boolean inWhen) {}
   public void reshape(GLDrawable drawable, int x, int y, int width, int height) {}

   public void display(GLDrawable inDrawable) {
     GL gl = inDrawable.getGL();
     gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

     pSetView(inDrawable, false);

     gl.glColor3d(0, 0, 0);
     gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
     gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, new float[] { 0f, 0f, 0f } );
     gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE, new float[] { 0f, 0f, 0f });
     gl.glBegin(GL.GL_LINE_LOOP);
     gl.glVertex3d( 1, -1, -1);
     gl.glVertex3d( 1, -1,  1);
     gl.glVertex3d(-1, -1,  1);
     gl.glVertex3d(-1, -1, -1);
     gl.glEnd();

     gl.glBegin(GL.GL_LINE_LOOP);
     gl.glVertex3d( 1, 1, -1);
     gl.glVertex3d( 1, 1,  1);
     gl.glVertex3d(-1, 1,  1);
     gl.glVertex3d(-1, 1, -1);
     gl.glEnd();

     gl.glFlush();
   }
 }

 public void pSetView(GLDrawable inDrawable, boolean inFlip) {
   pSetView( (double) myGLCanvas.getSize().width / myGLCanvas.getSize().height, inDrawable, inFlip);
 }

 public void pSetView(double inAspect, GLDrawable inDrawable, boolean inFlip) {
   GL gl = inDrawable.getGL();
   GLU glu = inDrawable.getGLU();

   gl.glMatrixMode(GL.GL_PROJECTION);
   gl.glLoadIdentity();

   double dim = myZoom;
   if (myPerspectivePresent) {
     glu.gluPerspective(myPerspAngle*180/Math.PI, inAspect, .1, 100000.0);
     dim = myZoom/Math.tan(myPerspAngle/ 2);
   }
   else
     gl.glOrtho(-myZoom*inAspect, myZoom*inAspect, -myZoom, myZoom, -10.0, 100.0);

   gl.glMatrixMode(GL.GL_MODELVIEW);
   gl.glLoadIdentity();
   double upOrDown = 1 - 2 * (int) (gMod(myTheta, 2*Math.PI)/Math.PI);
   glu.gluLookAt(dim*Math.sin(myTheta)*Math.cos(myPhi),
                 dim*Math.sin(myTheta)*Math.sin(myPhi),
                 dim*Math.cos(myTheta),
                 0.0, 0.0, 0.0,
                 0.0, 0.0, (!inFlip)?upOrDown:-upOrDown);
 }

 public static double gMod(double inA, double inM) {
   while (inA > inM) inA -= inM;
   while (inA < 0) inA += inM;
   return inA;
 }

 private class MouseListeners implements MouseListener, MouseMotionListener {
   private int myLastX, myLastY;
   public void mousePressed(MouseEvent inME) {
     if (inME.getButton() == MouseEvent.BUTTON1) {
       myLastX = inME.getX();
       myLastY = inME.getY();
     }
   }

   public void mouseDragged(MouseEvent inME) {
     if ((inME.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0) return;

     if ((inME.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) != 0 )
       myZoom += (inME.getY() - myLastY)/30.0;
     else if ((inME.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) != 0 )
       myPerspAngle += -(inME.getY() - myLastY)/600.0;
     else {
       myPhi   += -(inME.getX() - myLastX)/300.0;
       myTheta += -(inME.getY() - myLastY)/300.0;
     }
     myLastX = inME.getX();
     myLastY = inME.getY();

     myGLCanvas.display();
   }

   public void mouseMoved(MouseEvent inME) { }
   public void mouseReleased(MouseEvent inME) { }

   public void mouseClicked(MouseEvent inME) {
     if (inME.getButton() == MouseEvent.BUTTON1 && inME.getClickCount() == 2)
       myPerspectivePresent = !myPerspectivePresent;
     myGLCanvas.display();
   }
   public void mouseEntered(MouseEvent e) { }
   public void mouseExited(MouseEvent e) { }
 }
}
15  Java Game APIs & Engines / JOGL Development / Re: "On-demand" mode modification to tut on: 2005-01-12 05:19:07
But how do I make it show anything before the first mouse or key event?
16  Java Game APIs & Engines / JOGL Development / Re: "On-demand" mode modification to tut on: 2005-01-10 18:18:09
Funny, rigid bodies is the subject of my research, too. Maybe we can collaborate on that!

For example, I'm thinking right now of how to intelligently add energy dissipation to the rigid body or how to describe it in non-affine coordinates. Will your framework have support for planetary motion of rigid bodies?

As far as on-demand jogl, I just can't figure out how to get things started. How about an application this simple:
When the application starts it shows a triangle.

For me, the init() method does not trigger until I manually resize the parent frame.

Thanks a lot!

Pahidla
17  Java Game APIs & Engines / JOGL Development / Re: "On-demand" mode modification to tut on: 2005-01-10 02:14:58
I see that nnevatie is back, so there's hope for me. Otherwise, another sad Shakespeare sonnet.
18  Java Game APIs & Engines / JOGL Development / Re: "On-demand" mode modification to tut on: 2005-01-05 04:16:51
If I should give up the hope of seeing this, tell me now!

Then hate me when thou wilt; if ever, now;
Now, while the world is bent my deeds to cross,
Join with the spite of fortune, make me bow,
And do not drop in for an after-loss:
19  Java Game APIs & Engines / JOGL Development / "On-demand" mode modification to tutoria on: 2004-12-23 07:38:15
How about it?   Smiley
20  Java Game APIs & Engines / JOGL Development / Re: Causing the stuff to refresh on: 2004-12-23 07:36:56
Thank you. Very useful information.
21  Java Game APIs & Engines / JOGL Development / Re: Causing the stuff to refresh on: 2004-12-21 10:56:53
Hi Rex,

It did help, even though I didn't understand most of the terms you used buy I've gathered that I should stay away from it.

Actually, I only use it on mouse release after mouse drag which for my application basically means nothing else is hapenning.

Just out of curiousity, can't java (rather than opengl) tell me the color of a pixel on the screen?

Pahidla
22  Java Game APIs & Engines / JOGL Development / Re: Causing the stuff to refresh on: 2004-12-20 17:16:45
Ken, that's not what I meant. What I was trying to imply is that in every display() I will grab the entire image (in put it in myPixels) and the just lookup the value in myPixels[] upon every click. (Sounds like a good plan to me!) The application is such that clicks to query the pixels will follow almost every display().

BTW, I'm confused about the very glReadPixels command. I've looked up the c-spec and there's too much info. Did I basically give a correct command, giving it an array of longs of length HxW and passing the parameters GL.GL_RGB, GL.GL_UNSIGNED_BYTE?
23  Java Game APIs & Engines / JOGL Development / Re: Causing the stuff to refresh on: 2004-12-20 17:03:07
Now we are getting to the bottom of my confusion!

So how about something like:

     myPixels = new long[myGLCanvas.getWidth()*myGLCanvas.getHeight()];
     gl.glReadPixels(0, 0, myGLCanvas.getWidth(), myGLCanvas.getHeight(), GL.GL_RGB, GL.GL_UNSIGNED_BYTE, myPixels);


in display() and the refer to myPixels in the click callback?
24  Java Game APIs & Engines / JOGL Development / Re: Causing the stuff to refresh on: 2004-12-20 16:14:12
By the way, I welcome ALL comments about my code - style, observations, criticisms, etc!
25  Java Game APIs & Engines / JOGL Development / Re: Causing the stuff to refresh on: 2004-12-20 16:06:56
Thank you!

Here it is, maximally compressed. With a little bit of work I will be able to post something that actually runs. Or, I could include a small flash presentation of what happens on the screen. This is a JPanel which is later included in a JFrame.


package laba;

import pmgjutils.Value;
import pmgjutils.ValuePanel;

import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;

import net.java.games.jogl.*;

public class ImaxToPost extends JPanel {
 private GLCanvas myGLCanvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());

 private ArrayList myContents = new ArrayList();
 private ArrayList my3DObjects = new ArrayList();  // Basically an ArrayList of ints representing gl lists.

 /*
  Value.Double is basically a Double which triggers a callback when changed. Value.DoubleWheelable is a similar thing except it creates a
  a little gui component that looks like a wheel. Value.Boolean is the same for boolean except it creates a checkbox Etc...
  */
 private Value.DoubleWheelable myTheta = new Value.DoubleWheelable("Longitudal Angle, \u03b8 (in units of \u03c0)", .5, 0.01, 1);
 private Value.DoubleWheelable myPhi = new Value.DoubleWheelable("Azimuthal Angle, \u03c6 (in units of \u03c0)", -.5, 0.01, 0);
 private Value.DoubleWheelable myZoom = new Value.DoubleWheelable("Zoom", 2.0, 0.1, 1);
 private Value.Boolean myPerspectivePresent = new Value.Boolean("Perspective?", false);
 private Value.DoubleRange myPersp = new Value.DoubleRange("View Angle", Math.PI/3, 0, Math.PI);

 public GLCanvas pGetCanvas3D() { return myGLCanvas; }

 private static void gRefreshCanvas(GLCanvas inCanvas) {
// Experiments with threads. Basically calles myGLCanvas.display();
   final GLCanvas canvas = inCanvas;
//    SwingUtilities.invokeLater(new Runnable() {
//      public void run() {
//        System.out.println("About the give the repaint command! " + Thread.currentThread().getName());
       canvas.display();
//      }
//    });
 }

 public ImaxToPost() {
   setLayout(new BorderLayout());

   Value[] values = new Value[] {
       myZoom, myTheta, myPhi, myPerspectivePresent, myPersp,
       Value.SEPARATOR, Value.SEPARATOR };

   for (int v = 0; v < values.length; v++) { // refresh when a view paramter changed.
     values[v].pAddValueListener(new Value.Listener() {
       public void pOnAction(Value.Event inE) { gRefreshCanvas(myGLCanvas); }
     });
   }

   InteractionListeners il = new InteractionListeners();
   myGLCanvas.addComponentListener(il);
   myGLCanvas.addMouseListener(il);
   myGLCanvas.addMouseMotionListener(il);

 }

 public void pKickStart() {
   myGLCanvas.addGLEventListener(new OnScreenGLEventListener());
   add(myGLCanvas, BorderLayout.CENTER);
 }

 public class OnScreenGLEventListener implements GLEventListener {
   public void init(GLDrawable inDrawable) {
     System.out.println("Init is being called by " + Thread.currentThread().getName());
     GL gl = inDrawable.getGL();

     gl.glClearColor(1f, 1f, 1f, 1f);

     gl.glEnable(GL.GL_DEPTH_TEST);
     gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
     gl.glEnable(GL.GL_POLYGON_OFFSET_LINE);

     // Lights
     gl.glEnable(GL.GL_LIGHTING);
     gl.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, new float[] { 1f, 1f, 1f, 1f }); // was .6 .6 .6 1

     gl.glDisable(GL.GL_CULL_FACE) ;
     gl.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE, GL.GL_TRUE) ;
   }

   public void display(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
   public void displayChanged(GLDrawable inDrawable, boolean inWhat, boolean inWhen) {}
   public void reshape(GLDrawable drawable, int x, int y, int width, int height) {}

   public void display(GLDrawable inDrawable) {
//      System.err.println(Thread.currentThread().getName());
//      try { throw new RuntimeException();  }  catch (Exception inE) { inE.printStackTrace(System.out);   }
     GL gl = inDrawable.getGL();
     gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

     pSetView(inDrawable, false);

     for (int i = 0; i < myContents.size(); i++) {
       Buildable buildable = (Buildable) myContents.get(i); // Definition of Buildable below
       if (buildable.pHasBeenTouched()) {
         Object obj = buildable.pGenerate3D(inDrawable, null);
         if (my3DObjects.size() > i && my3DObjects.get(i) != null)
           my3DObjects.set(i, obj);
         else
           my3DObjects.add(i, obj);
         buildable.pUntouch();
       }

       if (buildable.pIsVisible() && ((Integer) my3DObjects.get(i)).intValue() != 0)
         gl.glCallList(((Integer) my3DObjects.get(i)).intValue()); // Reveals implementation
     }

     gl.glFlush();

   }
 }

 /*

  public interface Buildable {
    public abstract Object pGenerate3D(net.java.games.jogl.GLDrawable drawable, Object inOther);
    public abstract String pGetName();
    public abstract boolean pIsVisible();
    public boolean pHasBeenTouched();
    public Buildable pTouch();
    public Buildable pUntouch();
  }

  */
 public void pSetView(GLDrawable inDrawable, boolean inFlip) {
   pSetView( (double) myGLCanvas.getSize().width / myGLCanvas.getSize().height, inDrawable, inFlip);
 }

 public void pSetView(double inAspect, GLDrawable inDrawable, boolean inFlip) {
   GL gl = inDrawable.getGL();
   GLU glu = inDrawable.getGLU();

   gl.glMatrixMode(GL.GL_PROJECTION);
   gl.glLoadIdentity();

   double dim = myZoom.pValue();
   if (myPerspectivePresent.pValue()) {
     glu.gluPerspective(myPersp.pValue()*180/Math.PI, inAspect, .1, 100000.0);
     dim = myZoom.pValue() / Math.tan(myPersp.pValue() / 2);
   }
   else
     gl.glOrtho(-myZoom.pValue() * inAspect, myZoom.pValue() * inAspect, -myZoom.pValue(), myZoom.pValue(), -10.0, 100.0);

   gl.glMatrixMode(GL.GL_MODELVIEW);
   gl.glLoadIdentity();
   double theta = myTheta.pValue() * Math.PI;
   double phi = myPhi.pValue() * Math.PI;
   double upOrDown = 1 - 2 * (int) (pmgjutils.math.PmgMath.gMod(theta, 2 * Math.PI) / Math.PI);
   glu.gluLookAt(dim * Math.sin(theta) * Math.cos(phi),
                 dim * Math.sin(theta) * Math.sin(phi), dim * Math.cos(theta),
                 0.0, 0.0, 0.0,
                 0.0, 0.0, (!inFlip)?upOrDown:-upOrDown);
 }



 private class InteractionListeners implements MouseListener, MouseMotionListener, ComponentListener {
   private int myLastX, myLastY;
   public void mousePressed(MouseEvent inME) {
     if (inME.getButton() == MouseEvent.BUTTON1) {
       myLastX = inME.getX();
       myLastY = inME.getY();
     }
     else if (inME.getButton() == MouseEvent.BUTTON3) {
       int x0 = (int) ((GLCanvas) inME.getSource()).getParent().getBounds().getX();
       int y0 = (int) ((GLCanvas) inME.getSource()).getParent().getBounds().getY();
       int x = inME.getX(), y = inME.getY();
     }
   }

   public void mouseDragged(MouseEvent inME) {
     if ((inME.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0) return;

     if ((inME.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) != 0 ) {
       myZoom.pIncrement((inME.getY() - myLastY)/30.0/Math.PI);
     }
     else if ((inME.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) != 0 ) {
       myPersp.pIncrement(-(inME.getY() - myLastY)/600.0/Math.PI);
     }
     else {
       myPhi.pIncrement(  -(inME.getX() - myLastX)/300.0/Math.PI);
       myTheta.pIncrement(-(inME.getY() - myLastY)/300.0/Math.PI);
     }
     myLastX = inME.getX();
     myLastY = inME.getY();
   }

   public void mouseMoved(MouseEvent inME) { }
   public void mouseReleased(MouseEvent e) { }
   public void mouseClicked(MouseEvent inME) {
     if (inME.getButton() == MouseEvent.BUTTON1 && inME.getClickCount() == 2) {
       myPerspectivePresent.pNegate();
       return;
     }

     final MouseEvent e = inME;
     SwingUtilities.invokeLater(new Runnable() {
       public void run() {
         int x = e.getX(), y = e.getY();

         GL gl = myGLCanvas.getGL();

         char[] l = new char[3];
         gl.glReadPixels(x, y, 3, 3, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, l);
         System.out.println(x + " " + y + " " + (int) l[0] + " " + (int) l[1] + " " + (int) l[2]);
       }
     });
   }
   public void mouseEntered(MouseEvent e) { }
   public void mouseExited(MouseEvent e) { }
   public void componentHidden(ComponentEvent inCE) { }
   public void componentShown(ComponentEvent inCE) { }
   public void componentMoved(ComponentEvent inCE) { }
   public void componentResized(ComponentEvent inCE) { }
 }
}
26  Java Game APIs & Engines / JOGL Development / Re: Causing the stuff to refresh on: 2004-12-20 15:06:53
Thank you for your vote on confidence and, more importantly, for taking the time the help the less advanced users. Your posting was extremely insightful and educational.

That said, I _am_ doing something wrong.  I'm having many problems, so I'll take them one at a time.

I'm operating in the "on-demand" mode. But I have a problem kicking things off. When the JFrame containing my GLCanvas comes up, the init() or display() are _not_ called. In order to trigger them, I have to manually resize the window and then everything gets going.

So how do I fix this?
27  Java Game APIs & Engines / JOGL Development / Re: Causing the stuff to refresh on: 2004-12-19 19:04:03
Thank you. You're a mench.
28  Java Game APIs & Engines / JOGL Development / Re: Causing the stuff to refresh (request) on: 2004-12-19 15:19:03
Could someone be kind enough to modify Gregory Pierce's to show how to write a simple "painting on demand" application.

I've read the existing tutorial very carefully, but I can't quite figure out how kick things off in the "on demand" mode.

When I call GLCanvas.display() from a button callback I find that all GL commands take place in the "AWT-EventQueue-0" tread which I understand is incorrect. How can that be fixed? (I tried using SwingUtilities.invokeLater but that doesn't seem to help...)

(I already have what I think is a very cool application which mimics the Examiner, I think it was called, in Magician where viewing parameters can be continuously adjusted, etc. Everything seems to work - albeit incorrectly from the threads point of view.)
29  Java Game APIs & Engines / JOGL Development / Causing the stuff to refresh on: 2004-12-18 15:21:56
Hi,

I'm beginning to feel a little guilty about making so many posts, but anyway...

If something changes among my 3d objects and I basically need to tell the system to refresh the view, what's the right way to do it?

I basically call GLCanvas.display() but something tells me that is not the right way to do it.

What is?

Thanks a lot for the help I'm getting...

Pahidla
30  Java Game APIs & Engines / JOGL Development / Unable to lock surface on: 2004-12-18 13:00:04
Hi,

You may tell from another thread that I'm currently struggling with jogl and threads. Now I'm trying something but getting the "Unable to lock surface" exception.

There are no threads on this forum on this and the only explanation I found was this:

2. net.java.games.jogl.GLException: Unable to lock surface

JOGL appears to have some very weird internal setup timing that causes problems in odd ways. This exception comes when you have attempted to do something to the GLCanvas before adding it to another component that is not already visible. To avoid this, make sure you call setVisible(true) on the containing Frame/Window before adding the GLCanvas.

This seems to occur only when I try to initialize things from the Swing thread.

Can someone tell me more about what's going on here?

Thanks.

Pahidla
Pages: [1] 2
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (16 views)
2014-08-31 22:59:12

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

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

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

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

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

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

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

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

BurntPizza (49 views)
2014-08-09 21:09:32
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!