开发者

OpenGL VBO shader

I have a 2D VBO object that represent points in 2D space. What is the be开发者_高级运维st way to draw an arbitrary shape at that point? Lets say I wanted to draw a red 'X' at each.

Can I use a shader to do this?


You don't neccessarily need a special shader for that, you might just use point sprites. This would basically mean to draw the VBO as a point set (using glDrawArrays(GL_POINTS, ...)) and enabling point sprites to draw a textured square (with a texture of the 'X') at the position of each point, assuming a point size of more than 1 pixel.

For actually generating geometry at the location of each point you could use the geometry shader. This way you also render the VBO as point set and generate two lines (the 'X') or whatever geometry for each point inside the geometry shader.

An alternative to the geometry shader are instanced arrays (requiring the same GL3/DX10 hardware as neccessary for geometry shaders). This way you draw multiple instances of the 'X' shape and source the instances' individual positions from the point VBO by using an attribute whose index is advanced once per instance.

The last alternative would be to generate the shapes' geometries manually on the CPU, so that you end up with a line set or a quad set conatining all the 'X's as lines or sprites or whatever.

But the easiest (and maybe fastest, not sure about that) way should be the point sprite approach mentioned first, as their usual clipping problems shouldn't be that much of a problem in your case and you don't seem to need 3d shapes anyway. This way you neither need to generate the geometry yourself on the CPU, nor do you need special shaders or GL3/DX10 hardware (although this is quite common nowadays). All you need is a texture of the shape and enable point sprites (which should be core since GL 1.5).

If all these general ideas don't tell you anything, you might want to delve a little deeper into OpenGL and real-time computer graphics in general.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜