Drawing “point-like” shapes in OpenGL, indifferent to zoom

前端 未结 3 1758
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-21 03:00

I\'m working with Qt and QWt3D Plotting tools, and extending them to provide some 3-D and 2-D plotting functionality that I need, so I\'m learning some OpenGL in the process.

相关标签:
3条回答
  • 2021-01-21 03:28

    What you want is called a "point sprite." OpenGL1.4 supports these through the ARB_point_sprite extension.

    Try this tutorial

    http://www.ploksoftware.org/ExNihilo/pages/Tutorialpointsprite.htm

    and see if it's what you're looking for.

    0 讨论(0)
  • 2021-01-21 03:29

    There's no easy way to do what you want to do. You'll have to dynamically resize the primitives you're drawing depending on the camera's current zoom. You can use a technique known as billboarding to make sure that your objects always face the camera.

    0 讨论(0)
  • 2021-01-21 03:38

    The scene is re-drawn every time the user zooms or pans, anyway, so you might as well re-calculate the size.

    You suggested using a textured poly, or using polygons directly, which sound like good ideas to me. It sounds like you want the plot points to remain in the correct position in the graph as the camera moves, but you want to prevent them from changing size when the user zooms. To do this, just resize the plot point polygons so the ratio between the polygon's size and the distance to the camera remains constant. If you've got a lot of plot points, computing the distance to the camera might get expensive because of the square-root involved, but a lookup table would probably solve that.

    In addition to resizing, you'll want to keep the plot points facing the camera, so billboarding is your solution, there.

    An alternative is to project each of the 3D plot point locations to find out their 2D screen coordinates. Then simply render the polygons at those screen coordinates. No re-scaling necessary. However, gluProject is quite slow, so I'd be very surprised if this wasn't orders of magnitude slower than simply rescaling the plot point polygons like I first suggested.

    Good luck!

    0 讨论(0)
提交回复
热议问题