Can't make sprites work as points

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Can't make sprites work as points

heddle
Experienced java developer but relatively new to jogl and openGL. I have researched this and could not find a solution. Some of the code for related issues (but not exactly what I wanted) was old and the jogl API has apparently changed so the signatures were not correct so I could not readily adapt it.

What I am trying to do: I have a high energy physics application that displays particle detectors. I draw hits in the detectors as points. But the points in basic jogl/opengl seem to be just squares. So what I would like to do is draw small images (pngs) at the points. So the basic problem is: draw images from png files (resources) at points.

I start by loading the image from a jar file via

 _sprite = TextureIO.newTexture(_url, false, ".png");

this seems to work fine. For instance, the sprite reports the correct image size.Then I try to draw the (same sprite) at a set of points using

public static void drawSprites(GLAutoDrawable drawable, float coords[],
    Texture sprite, float size) {

  GL2 gl = drawable.getGL().getGL2();
  gl.glPointSize(size);
  sprite.bind(gl);

//how many points?
  int np = coords.length / 3;

  gl.glBegin(GL.GL_POINTS);

  for (int i = 0; i < np; i++) {
      int j = i * 3;
      gl.glVertex3f(coords[j], coords[j + 1], coords[j + 2]);
  }
  gl.glEnd();
}



But all I get are the points-- i.e. squares. The squares are at the right xyz location--but they are just squares. No images.

Yes I know this is a noob mistake that will annoy the experts--I'll accept public humiliation as long as I get a solution! Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Can't make sprites work as points

jmaasing
Point sprites are sometimes an efficient way to do what you are looking for. However, for glPointSize the OpenGL specs only mandate that drivers/cards must support size 1. So you'll get varying results with nVidia, AMD, Apple et c if you specify anything else than 1.
I think what most game engines do is to draw a quad (two triangles) to do billboarding and maybe optionally try to use point sprites if they happen to be supported (many drivers/cards actually do support it, maybe there is some way to query the driver for support?).