0

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 location--but they are just squares. No images.

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • 1
    From the calls in the code, it looks like you're probably looking for a solution using legacy OpenGL. If you're also interested in modern (shader based) OpenGL, my answer here might help: http://stackoverflow.com/questions/27098315/render-large-circular-points-in-modern-opengl/27099691#27099691. – Reto Koradi Jul 28 '15 at 02:57
  • I definitely agree with @RetoKoradi, you should avoid legacy stuffs – elect Jul 28 '15 at 08:57
  • Thank you for the info. About modern OpenGL. My version on my mac air prints **OpenGL version: 2.1 INTEL-10.6.20 OpenGL renderer: Intel HD Graphics 4000 OpenGL Engine** I wonder because, for example, the constant GL_PROGRAM_POINT_SIZE in the linked post on circular points is not defined for me. – David Heddle Jul 28 '15 at 17:36
  • I confirm that this constant is in GL3: http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/GL3.html#GL_PROGRAM_POINT_SIZE – gouessej Jul 28 '15 at 18:33
  • According to [Apple](https://developer.apple.com/opengl/capabilities/), 10.9 brings GL 4.1 on the HD4000, which OSX have you? – elect Jul 29 '15 at 12:13
  • Hi elect, it is OSX 10.10.3 – David Heddle Jul 29 '15 at 17:43
  • Hi gouessej,You are correct (of course) about the constant's availability in GL3. – David Heddle Jul 29 '15 at 17:47
  • To all-- I know this is a lot to ask but does anyone have a complete mini jogl demo that either draws sprites at points or circles instead of squares? Either to post here or email to me and I'll post with attribution? david dot heddle at cnu dot edu. – David Heddle Jul 29 '15 at 17:49
  • We can help and write that together, come on jogl irc or forum. How many objects are we talking about? – elect Jul 30 '15 at 06:49
  • elect, I would like to see a demo that generates any number (say 100) of random xyz points and draws some as circles and some as sprites. That said, I now see I have to (or should) use shaders and see what you mean by modern opengl. Since there appears to be no jogl book (my old-school preferred way to learn) I have been trying to find the right demo in the jogl demos and "steal" the code. That has gotten me pretty far--drawing particle detectors and trajectories in 3D, but I've been vexed by the seeming trivial problem of drawing circles or sprites on points as opposed to squares. – David Heddle Jul 30 '15 at 13:29
  • The points look like square because you have to call first 'glEnable(GL_POINT_SMOOTH)'. If you want to learn opengl the old-way, it is perfect, because that is how you learn it at best. [Arcsynthesis](https://bitbucket.org/alfonse/gltut/wiki/Home) is the best place where you can start. Then another very valuable site is [ogldev](http://ogldev.atspace.co.uk/). Finally, a shorter one is also [open.gl](https://open.gl/). All of them are in C, but I did a [port](https://github.com/elect86?tab=repositories) of the first and (partially) the second tutorial guide. – elect Jul 31 '15 at 07:14
  • [This](https://github.com/elect86/modern-jogl-examples/blob/master/modern-jogl-examples/src/tut14/basicTexture/BasicTexture.java) is a basic tutorial about texturing – elect Jul 31 '15 at 07:16
  • Hi David, I just finished a small [Hello Triangle](https://github.com/elect86/jogl-samples/blob/master/jogl-samples/src/helloTriangle/HelloTriangle.java) if you are interested :). It shows basic stuff, you can build up stuff from there. – elect Aug 05 '15 at 07:52
  • Hi elect, thank you! There is one compilation problem, and I'm sure I'm just dumb, but what I fails on the import import.framework.Semantic and subsequently on all the references to Semantic. – David Heddle Aug 06 '15 at 12:54
  • Hi David, check you have [this file](https://github.com/elect86/jogl-samples/blob/master/jogl-samples/src/framework/Semantic.java) and the [last jogl build](http://jogamp.org/deployment/archive/master/gluegen_876-joal_603-jogl_1414-jocl_1066/archive/), jogamp-all-platforms.7z – elect Aug 07 '15 at 08:12

0 Answers0