Trails in OpenGL

Started by
6 comments, last by Thaumaturge 16 years, 1 month ago
Hello all, What is the best way to allow the path of a moving point to be recorded on the screen? i.e. I have created a point using GL_POINTS, and I have allowed it to move around the screen, how do I now allow its path to be visible (kind of like the old Snake game, but with indefinitely long tail)?
Advertisement
You can keep a queue of past positions. Make the queue of a certain length so during an update, pop the head of the queue and push the current position on the tail. Then draw all the points in the queue. Look up FIFO theory for the queue and you will understand.

Hope this helps.
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein (1879-1955) That is so very true...
if I need to specify the length of the queue, this means that my trail cannot exceed a certain length. What I really want is for it to be drawn to however long the point is left to move around the screen. Is there a workaround?

Many thanx for the response
Do you really need it to be infinite or just really large?

Why not use a standard container that can grow line a std::vector<T> ?

You can add as many points to it and iterate through them in order.
Thanx metorical,
I'll take this into account and hope its not past my programming skills to implement
To gain a (theoretically) indefinite trail, you could perhaps simply draw the trail to a buffer that is never cleared, and only keep track of the current trail segment.

Store the current position, and that of the last trail point, and draw a line between the two to your trail surface. Without clearing the surface, the already-extant sections of trail should remain.

If your point is the only thing on the screen, then this should be achievable by doing the above, rendering to the screen normal, and simply not clearing the screen (with the possible exception of an initial clear to establish a canvas on which to "draw").

If there are other objects, then render the trail to a texture, and display that texture on a quad of appropriate size.

Of course, this becomes more complicated if the screen is required to change view -point or -direction.

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

I was using this method of not clearing the buffer out but then I found it had some limitations. The point actually moves in 3D space, and so I can't perform a rotate without the effect of the rotation being left on the screen, which I don't want.

I think I should have mentioned that the point moves in 3D space. So a more specific analogy of my problem would be a 3D snake game that can grow a tail from start to the point's current position, however long that might be (not predeterminable).

Well, does the screen itself move and rotate, or just the object within it? If the former, then, depending on what limits exist on that movement, you might get away with an off-screen texture to which you render, and which is then applied to a quad that you render to screen.

If the object itself is the only thing that moves, then drawing to the screen should work, I would think, as long as you're careful...

Could you perhaps give a screenshot, please? That might give a better idea of what, precisely, you want.

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

This topic is closed to new replies.

Advertisement