2

I am working on a Java OpenGL application described below.

The application shows a large 2D texture of a world map. Some information must be represented as captions on the map (for example, a caption near Spain that shows its population). The captions are GL objects consisting of polygons and text. The user must be able to navigate around the map (left, right, up and down) as well as zoom in (+) and zoom out (-). When the user performs these operations, the map should move or resize and the captions should move along with the map but keep itselves at the same size.

I am doing the view 2D with glOrtho, the movement with glTranslate and the zoom with glScale. At first, when zooming, the captions resized along with the map, so the captions became too big or too small. To fix this, I billboarded the captions. With billboarding, the captions are not resizing but doesn't keep its relative position to the map when zooming in&out (I need the Spain's caption staying always near Spain).

All in a nutshell, I need the captions moving along with the map, keeping at a fixed size and with a relative position to the map.

Is there any way to do what I need to do?

genpfault
  • 51,148
  • 11
  • 85
  • 139
txedo
  • 956
  • 11
  • 11

3 Answers3

0

I had a similar problem

Ended up answering my own question ;)
My approach utilizes a geometry shader (thus opengl 3 is a minimum). It creates a quad from a point; The quad is rendered in a perspective projection - not ortho. This allows for easy depth testing (actually I don't even do ANY depth calculations - they are all automatic). I have later modified the shader a bit, so that the quad would actually stay constant whatever the zoom is. I want you to first check if this solution is feasible for you and then i'll update my answer and post the shader code and explain it.

Community
  • 1
  • 1
Timur Nuriyasov
  • 359
  • 2
  • 16
0

I think point sprites would serve you well here. A point sprite is a textured point that you can render in 3D space directly with your map. The texture of the point is simply rendered "flat", not warped like you drew it on a quad. You can even define the scaling function so that the "billboard" varies with distance.

Ben Jackson
  • 90,079
  • 9
  • 98
  • 150
  • At this moment I don't need to map textures. I need to place the captions, which are constructed by lines and polygons, on the map. This captions have a fixed size, but their position is relative to the map. So if the map is zoomed, the caption must be translated to its new relative position keeping its size. Here (http://stackoverflow.com/questions/850988/drawing-point-like-shapes-in-opengl-indifferent-to-zoom/851007#851007), there is a similar problem, but remember that my "point-like" shapes are lines and polygons. – txedo Nov 25 '10 at 11:25
0

I was looking for something similar to your question, I needed to render a dashed circle that could stay fixed on the screen regardless rotation/view/scaling

After some attempts I managed to get it working, maybe it could not be the best in term of performances, but if you are not rendering anything heavy for the modern GPUs this shouldnt be a problem:

dispay()..

//  set modelview Matrix
    gl.glMatrixMode(GL2.GL_MODELVIEW);
        gl.glLoadIdentity();
        glu.gluLookAt(0, 0, 2, 0, 0, 0, 0, -1, 0);

    gl.glMatrixMode(GL2.GL_PROJECTION);
        gl.glLoadIdentity();
        gl.glOrtho(-1.2, 1.2, -1.1, 1.1, 0, 100);
        renderDashedCircle(gl);
        if(activatePerspectiveView) {
            gl.glLoadIdentity();
            aspect = gLAutoDrawable.getWidth()/gLAutoDrawable.getHeight();
            glu.gluPerspective(60, aspect, 1, 100);

The critical render is in " renderDashedCircle(gl);"

Dont care about Ortho/perspective, that is something that belongs to my program (basically it is able to switch on the fly between them)

elect
  • 6,765
  • 10
  • 53
  • 119