Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
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 / Re: Loading the libraries dynamically on: 2007-07-08 17:54:58
Simply using System.setProperty() to change java.library.path won't work. There are some horrible hacks to get around it.  See this  thread for one approach.
2  Java Game APIs & Engines / JOGL Development / Re: Errors on Linux / ATI on: 2007-06-07 22:17:59
Quote
I'm curious what chip they stopped supporting? Because I just peaked at their driver page and I see all the parts listed.

Support for the R200 chips was dropped in the proprietary drivers from ATI after version 8.28. The chip is pretty old, actually, but it was still used in new machines (a company-provided Dell laptop, in my case) for a long time after its release. ATI did release specs on the chips, however, and there are open source drivers available, but I haven't had much as much success with them as with the drivers from ATI. I just can't upgrade past any bugs in 8.28.
3  Java Game APIs & Engines / JOGL Development / Re: OpenGL pipeline on a linux platform bombs out when enabled. on: 2007-05-30 22:27:31
It runs (slowly) when I set sun.java2d.opengl to false.
It crashes for me when the sun.java2d.opengl property is set to true in the jnlp.

It prints:

Could not enable OpenGL pipeline for default config on screen 0

and then segfaults in the ATI driver.

#  SIGSEGV (0xb) at pc=0xb4fc5529, pid=27812, tid=2987170704
#
# Java VM: Java HotSpot(TM) Client VM (1.6.0-b105 mixed mode, sharing)
# Problematic frame:
# C  [atiogl_a_dri.so+0x1d3529]  glEnable+0x19

I don't know if this is the same problem you have or my own different problem.

I am running FC6 on with an old ATI R200 series chip and (somewhat old) fglrx drivers from AMD.

4  Java Game APIs & Engines / JOGL Development / Re: Errors on Linux / ATI on: 2007-05-17 23:07:15
Thanks. I'd love to be able to get fresh new Linux drivers from ATI, but my laptop (which was brand new a mere 18 months ago) has an ATI chip that they stopped supporting. I am stuck using the 8.28 version of ATI's Linux drivers with no hope of ever getting any bug fixes. That's why my next laptop will be Nvidia. Sorry about the rant, but it really is disappointing. 
5  Java Game APIs & Engines / JOGL Development / Re: Errors on Linux / ATI on: 2007-05-16 22:58:38
ATI on Linux is a problem for me too, I haven't gotten the open source drivers to work, but I have gotten ATI's proprietary drivers running. I have had allocation issues as well, but in my case they actually cause a segment violation and crash my JVM. The following JOGL program attempts to allocate 512 VBO's of size 1MB each (very abusive). I get to about 16MB worth before my JVM exits. It runs on my Windows/NVidia box, although it does eat up some memory by the end.

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  
import java.nio.FloatBuffer;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import com.sun.opengl.util.BufferUtil;

public class VboCrash
{
  public static void main(String[] args) throws Exception
  {
    JFrame frame = new JFrame("CrashTest");
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    GLCanvas canvas = new GLCanvas();
    frame.add(canvas);
    canvas.addGLEventListener(new GLEventListener()
    {
      public void init(GLAutoDrawable drawable)
      {
        GL gl = drawable.getGL();
        final int len = 1024 * 1024;
        long total = 0;
        for (int i = 0 ; i < 512 ; i++)
        {
          int[] id = new int[1];
          gl.glGenBuffersARB(1, id, 0);
          gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, id[0]);
          System.out.println("Bound id  " + id[0]);
          FloatBuffer fb = BufferUtil.newFloatBuffer(len);
          gl.glBufferDataARB(GL.GL_ARRAY_BUFFER_ARB, len, fb, GL.GL_STATIC_DRAW_ARB);
          System.out.println("Generated VBO length " + len);
          total += len;
          System.out.println("Used id " + id[0] + " (total:" + total + ")");
          //gl.glDeleteBuffersARB(1, id, 0);
       }
      }
      public void display(GLAutoDrawable drawable) {}
      public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
      public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}
      });
      frame.setSize(320, 240);
      frame.setVisible(true);
  }
}


The stack trace in the JVM dump shows that the crash occurs a few levels deep into the ATI code, so I doubt it's anything that JOGL could work around. My next Linux laptop will have an Nvidia card...

6  Game Development / Shared Code / Re: Rotation matrix for billboarding textured quads on: 2007-05-16 13:26:03
I mentioned in the last reply that I thought I could eliminate a sqrt(), and it was simple. I had used a trig identity to get a sine from a cosine, but the sine was sitting there in the normalized view vector the whole time. I just had to negate it.

1  
2  
3  
4  
5  
6  
7  
8  
9  
public static Matrix3f calculateBillboardRotation(Point3f eye, Point3f p)
{
  Vector3f view = new Vector3f(eye.x - p.x, eye.y - p.y, eye.z - p.z);
  Vector3f xzp = new Vector3f(view.x, 0, view.z);
  xzp.normalize();
  view.normalize();
  float cosp = view.dot(xzp);
  return new Matrix3f(xzp.z, xzp.x * -view.y, xzp.x * cosp, 0, cosp, view.y, -xzp.x, xzp.z * -view.y, xzp.z * cosp);
}


So, I got it down to two square roots in the vector normalize() calls . I guess that's still too many?

7  Game Development / Shared Code / Re: Rotation matrix for billboarding textured quads on: 2007-05-16 12:54:06
I agree, the cross product isn't nearly as expensive as sqrt() or acos().  Three sqrts per quad is definitely more than I would like, and upon further thought, I think I can eliminate one of them. Then it would be better than the two sqrt() plus two acos() calls that I found in some code in this tutorial: http://www.lighthouse3d.com/opengl/billboarding/index.php?billSphe but, hey, I am a newbie, so I have to start somewhere.

If I use a point near the center of the particles to get the vector to the camera eye, then I can calculate this matrix just once per frame instead of once per quad, with the drawback that some quads near the corners of the screen may look slightly askew. For particle effects that's probably good enough.

I am very interested in the quad orientation technique you mentioned. Have you, by any chance, got a link or some code you can paste here?



8  Game Development / Shared Code / Rotation matrix for billboarding textured quads on: 2007-05-16 02:50:35
Billboarding is the process of rotating a quad to face the camera so that no matter what the camera position, the quad is rotated to directly face the camera.

I've been fooling around with particle effects, and I was looking for some spherical billboard rotation code - but everything I found seemed to be tutorial style, and written for clarity instead of efficiency. All I wanted was to generate a 3x3 rotation matrix that I could apply to the quad vertices given a camera position and a particle pivot position.  The pivot position is the center of the quad, with each of the 4 vertices in a different quadrant on the xy plane.  I also wanted to avoid calling any trigonometric functions, and rely on simple pythagorean relationships.  So, I tried to simplify the calculations necessary to orient a quad to face the camera, and after a little algebraic refactoring, I came up with the following function. It does need to calculate 3 square roots, but there are no trig functions or cross products. It references the java vecmath package for the Point3f, Vector3f and Matrix3f implementations, but not for anything really important (just vector normalize and dot product). For simplicity, I present it here as a static function that creates new objects instead of reusing members.

Here's the stripped down version:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public static Matrix3f calculateBillboardRotation(Point3f eye, Point3f p)
{
  Vector3f view = new Vector3f(eye.x - p.x, eye.y - p.y, eye.z - p.z);
  Vector3f xzp = new Vector3f(view.x, 0, view.z);
  xzp.normalize();
  view.normalize();
  float cosp = view.dot(xzp);
  float sinp = (float) Math.sqrt(1 - cosp * cosp) * (view.y > 0 ? -1 : 1);
  return new Matrix3f(xzp.z, xzp.x * sinp, xzp.x * cosp, 0, cosp, -sinp, -xzp.x, xzp.z * sinp, xzp.z * cosp);
}


If that seemed interesting to you, here's the version with comments that hopefully explain what the heck I was thinking:

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  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
   /**
    * Calculates a 3x3 rotation matrix used to orient a quad billboard to directly face the camera eye.
    * The camera eye and the point p about which the billboard should pivot should be in world co-ordinates.
    * When applying the rotation matrix, first translate the vertices about the pivot point to the origin,
    * transform the vertices with the matrix, and then translate the new vertices back to world space.
    * The rotation is a 360 degree rotation around the y axis,
    * combined with a +/- 90 degree rotation about the x axis (the tilt up or down).
    * The initial billboard position assumes it is parallel to the xy plane with the normal
    * vector pointing to (0,0,1).
    * This method uses no trig functions, but it does calculate 3 square roots.
    */

   public static Matrix3f calculateBillboardRotation(Point3f eye, Point3f p)
   {
      // The view vector is the direction from the point to the camera eye
     Vector3f view = new Vector3f(eye.x - p.x, eye.y - p.y, eye.z - p.z);

      // The xzp vector has the y component set to zero and is a projection
     // of the view vector onto the xz plane.
     Vector3f xzp = new Vector3f(view.x, 0, view.z);

      // Once normalized, the components of the xzp vector will be direction cosines.
     // So, xzp.z contains the direction cosine of the angle between xzp and the z-axis,
     // and xzp.x contains the direction cosine of the angle between xzp and the x-axis.
     // Consider that since xzp.y is zero, then xzp.x and xzp.y are two sides
     // of a right triangle, and the magnitude of the xzp vector is the hypotenuse.
     // Let theta be the angle between xzp and the z-axis (which is also the
     // counter-clockwise rotation about the y axis that we want for our billboard).
     // Using standard trigonometric ratios, we know that:
     // cos(theta) = xzp.z / ||xzp||
     // We can remove the ||xzp|| (magnitude) since it equals 1 (normalized vector)
     // therefore, cos(theta) = xzp.z.
     // Using the same approach, the trigonometric ratio for sine, would be:
     // sin(theta) = xzp.x / ||xzp||
     // So, xzp.z and xzp.x are the exact sines and cosines we need for the
     // rotation about the y-axis, and we are done.
     xzp.normalize();

      // We have the sines and cosines for the rotation about the y axis, now
     // we need to get the elevation (rotation about the x axis).
     // The dot product of the normalized view and xzp vectors will provide
     // the cosine of the angle between the two vectors.
     // This cosine is related to the angle of elevation above the xz plane.
     view.normalize();
      float cosp = view.dot(xzp);

      // We have the cosine, but for the rotation matrix we need the sine, as well.
     // The sine of the elevation angle can be derived from the cosine using the
     // trig identity: sine = sqrt( 1 - (cosine squared) )
     // The sign must be negated when the view vector is looking up.
     // (y > 0) (i.e. camera looking down)
     float sinp = (float) Math.sqrt(1 - cosp * cosp) * (view.y > 0 ? -1 : 1);

      // Prepopulate a 3x3 rotation matrix with the rotation around the y axis
     // and the rotation around the x axis. This is how the matrix would wind
     // up if we created a separate rotation matrix for the y axis rotation
     // and the x axis rotation and then multiplied them together.
     // This is quicker than actually doing a full matrix multiplication
     // because the lack of a z axis rotation makes a lot of terms become
     // zero and drop out.
     return new Matrix3f(xzp.z, xzp.x * sinp, xzp.x * cosp, 0, cosp, -sinp, -xzp.x, xzp.z * sinp, xzp.z * cosp);
   }


Comments?

Anyone care to check my math?

Should I add special code to handle angles close to zero?
9  Java Game APIs & Engines / JOGL Development / Re: Java FloatBuffers don't always translate nicely to C API on: 2007-05-07 22:42:01
Excellent! So the snippet of code can be written like this:

1  
2  
3  
4  
5  
6  
7  
      FloatBuffer interleavedBuffer = generateT2F_N3F_V3FInterleavedBuffer();
      interleavedBuffer.position(2);
      gl.glNormalPointer(GL.GL_FLOAT, 8 * BufferUtil.SIZEOF_FLOAT, interleavedBuffer);
      interleavedBuffer.position(5);
      gl.glVertexPointer(3, GL.GL_FLOAT, 8 * BufferUtil.SIZEOF_FLOAT, interleavedBuffer);
      interleavedBuffer.position(0);
      gl.glTexCoordPointer(2, GL.GL_FLOAT, 8 * BufferUtil.SIZEOF_FLOAT, interleavedBuffer);


I knew there was a reason I posted here.
Thank you.
10  Java Game APIs & Engines / JOGL Development / Re: Java FloatBuffers don't always translate nicely to C API on: 2007-05-07 01:01:21
Yeah,  you are right. The GLImpl is already so huge, that adding more methods would make it even more confusing. And java.nio.Buffer essentially encapsulates the position that I suggested as an additional method parameter. I saw a lot of other methods taking a float[] followed by a starting offset parameter, that it made me want the same thing for Buffers. I have found that some of my video cards really benefit from interleaved data, so I run into this a lot.
11  Java Game APIs & Engines / JOGL Development / Java FloatBuffers don't always translate nicely to C API on: 2007-05-06 18:59:42
Many OpenGL functions in the C API accept a pointer as a parameter, whereas the corresponding methods in JOGL use a reference to a FloatBuffer. For example, the C function (below) has two Java wrappers:

1  
2  
3  
4  
5  
6  
7  
8  
C API:

  void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *  ptr);

Corresponding Java API (wrapped in GL.java):

  public void glVertexPointer(int size, int type, int stride, java.nio.Buffer ptr);
  public void glVertexPointer(int size, int type, int stride, long ptr_buffer_offset);


The first method I use when passing the contents of a direct FloatBuffer directly to GL. The trouble with the first method, is that the stride parameter isn't very powerful without being able to specify the starting offset in the buffer.  The second method (with the buffer offset) is useful when passing an offset into a VBO and the stride works great, but with dynamic data (like an animated model) a VBO isn't always the right choice. There are many other methods following a similar pattern (for example, I also use glTexCoordPointer and glNormalPointer a lot).

My problem is that if I interleave a FloatBuffer in T2F_N3F_V3F (texture, normal, vertex), and I don't use a VBO, I need to jump through hoops to get the offset into the FloatBuffer. I could write something like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
      FloatBuffer interleavedBuffer = generateT2F_N3F_V3FInterleavedBuffer();
      gl.glTexCoordPointer(2, GL.GL_FLOAT, 8 * BufferUtil.SIZEOF_FLOAT, interleavedBuffer);
      interleavedBuffer.position(2);
      FloatBuffer normalSlice = interleavedBuffer.slice();
      gl.glNormalPointer(GL.GL_FLOAT, 8 * BufferUtil.SIZEOF_FLOAT, normalSlice);
      group.interleavedAnimatedArray.position(5);
      FloatBuffer vertexSlice = interleavedBuffer.slice();
      gl.glVertexPointer(3, GL.GL_FLOAT, 8 * BufferUtil.SIZEOF_FLOAT, vertexSlice);
      interleavedBuffer.position(0);


Yes, I can use glInterleavedArrays(GL.GL_T2F_N3F_V3F, 0, interleavedBuffer), but I am trying to make a different point. The point is, I propose yet another overload of the methods accepting a Buffer as a parameter, that would also accept an offset into the buffer. So using the glVertexPointer example from above, we would have:

1  
2  
3  
  public void glVertexPointer(int size, int type, int stride, java.nio.Buffer ptr);
  public void glVertexPointer(int size, int type, int stride, java.nio.Buffer ptr, int buffer_offset);
  public void glVertexPointer(int size, int type, int stride, long ptr_buffer_offset);


The new method (the middle one, above) would more fully expose the potential of the original C API.

Thoughts?
12  Java Game APIs & Engines / JOGL Development / Re: GLCanvas is blocking mouse wheel events on: 2007-05-02 01:29:34
This is a very interesting example. Just to be sure, I modified your code to mask AWTEvent.MOUSE_EVENT_MASK instead of MOUSE_WHEEL_EVENT_MASK and the program works as expected (mouse enter and exit events at the GLCanvas).  So there's nothing wrong with your code. However, as you discovered, the AWTEvent.MOUSE_WHEEL_EVENT_MASK doesn't seem to enable the mouse wheel events.

Then, if I add a specific call to add a listener (with a no-op handler):
1  
2  
3  
4  
canvas.addMouseWheelListener(new MouseWheelListener()
{
   public void mouseWheelMoved(MouseWheelEvent e) {}
});


Then the mouse wheel events begin to work in the GLCanvas. It looks like some extra magic is performed in addMouseWheelListener() to enable the wheel events, that is not being performed by addAWTEventListener().

13  Java Game APIs & Engines / JOGL Development / GlCanvas resize flicker on Linux on: 2007-04-28 19:13:41
What's the current status regarding disabling backround erase in GLCanvas?

When I run my JOGL program in a Linux X11 environment with JDK 1.6.0, I get terrible flicker during window resize. The problem does not occur under windows. I know it's something at the Java level causing the flicker (and not X or the video driver), because I can change the flicker color with GLCanvas.setBackground(). I tried -Dsun.awt.noerasebackground=true to no avail.
 
I've looked at the source for GLCanvas, where it appears to use reflection to find a disableBackgroundErase() method in the Toolkit. When I run my JOGL program on Linux, GLCanvas.getToolkit() returns an instance of sun.awt.X11.XToolkit, which has no such method as far as I can tell.

The bug parade 6333613 http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6333613 indicates state: Closed, fixed.

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.

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

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

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

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

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

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

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

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

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

BurntPizza (48 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!