avoid flickering

Hi, I do alike below to draw rain drops in the display function (2D only):

if (temperatureC >= 0){
if (speedP >= 0.05){
if (initT1 == 0){
XPLMBindTexture2d(gTexture[4], 0);
// void SDL_GL_SwapBuffers(void);
glTexCoord2f(1, 1.0f); glVertex2f(X4achse[a]+15, Y4achse[a]-30); // Bottom Right Of The Texture and Quad
glTexCoord2f(0, 1.0f); glVertex2f(X4achse[a], Y4achse[a]-30); // Bottom Left Of The Texture and Quad
glTexCoord2f(0, 0.0f); glVertex2f(X4achse[a], Y4achse[a]); // Top Left Of The Texture and Quad
glTexCoord2f(1, 0.0f); glVertex2f(X4achse[a]+15, Y4achse[a]); // Top Right Of The Texture and Quad
initT1 = 1;
X4achse[a] -= 0.5;

so drops get replaced slightly at each loop. ok but the drops seem to get invisible slightly before the new are drawn. ->flickering but i want them to fade out (best) after
drawn the new positions. (shared lib; plugin for another app)
Many thanks

Please use [ code]/[ /code] (without space after ‘[’) around code snippets to make them easier to read.

ok but the drops seem to get invisible slightly before the new are drawn.

Do you use double buffering?

If you want to fade out the drops, you could keep a history of say the last 10 positions for each drop and draw “older” positions with more transparency.

I believe so from the parent app as uncommenting
// void SDL_GL_SwapBuffers(void);
has no effect? But maybe I’m missing something?

How would you keep history, any ideas?


Hmm, well don’t know what your parent application is doing, but if you have the source it couldn’t hurt to search for the place where it creates the OpenGL context and take a look at what it does there.

Regarding the history: I assume you have a variable that holds the current position for each drop. So to keep current and past positions you can use an array for each drop where drop_pos[0] is the current position and drop_pos[N] is the oldest. Whenever you update the position you first copy each one from array element i to i+1 and then write the new position into drop_pos[0].
You can also google for ring buffer or circular buffer on how to use your array in a way that does not require copying all elements around each time you update the position.

yes I might have a look at c++ list but the flickering would ruin the effect completely!
It’s a X-Plane plugin…