Jump to content
  • Advertisement
Sign in to follow this  
naxalyte

OpenGL Trails in OpenGL

This topic is 3792 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!