Page 1 of 1

Triangle Flickering

Posted: Tue Jan 15, 2019 3:14 am
by E8_Heterotic
I'm still fairly new to pixilang, but I have a decent amount of experience with programming in general. I'm having a bit of trouble with drawing triangles. It seems like the only option is triangles3d. I managed to get it to work and it will display a triangle on the screen. I also managed to get it to rotate, change color, etc.. However, there's still one strange problem.

The triangle keeps flickering on and off. I have a central "while" loop that clears the screen and then redraws the triangle every "frame." When I get read of the clear() command, the triangle displays without flickering on and off. That's fine if I want a stationary triangle, but if I'm making it rotate and change color, the screen will get cluttered with previously drawn triangles. Why isn't the triangle being drawn on every single pass through the loop even though the screen is cleared every single time the program loops?

The important part of the code is roughly:

while 1
{
update the clock
clear()
code to draw triangle
frame()
code to handle exit event
}

If the triangle is stationary and I remove the clear() command, the triangle never flickers. Somehow, it seems like the screen is cleared every time the loop cycles but the triangle isn't drawn every loop cycle.

I should also mention that I wrote similar code using fbox() and that doesn't flicker. I got boxes to do everything I wanted.

obs.pixi
(1.29 KiB) Downloaded 59 times

Re: Triangle Flickering

Posted: Thu Jan 17, 2019 5:33 am
by tabman
It seems that triangle order has to be initialized explicitly to use in triangles3d(). In your posted example add either of lines in respective places:

Code: Select all

clean(tt)
tt[7] = 0

Re: Triangle Flickering

Posted: Fri Jan 18, 2019 2:57 pm
by NightRadio
1) You forgot about the triangle order (last field in the tt array), as tabman said above.

2) You create the new tt and vv containers in every frame, without removing. It's very wasteful.
Here is more correct code:

Code: Select all

vv = new(24, 1, FLOAT)
tt = new(8, 1, INT)
clean(vv)
clean(tt)
while f < 300
{
 ...
 frame()
 f + 1
}

Re: Triangle Flickering

Posted: Sun Jan 20, 2019 9:36 am
by E8_Heterotic
tabman wrote:
Thu Jan 17, 2019 5:33 am
It seems that triangle order has to be initialized explicitly to use in triangles3d(). In your posted example add either of lines in respective places:

Code: Select all

clean(tt)
tt[7] = 0
Thanks, this ended up fixing it.

Re: Triangle Flickering

Posted: Sun Jan 20, 2019 9:37 am
by E8_Heterotic
NightRadio wrote:
Fri Jan 18, 2019 2:57 pm
1) You forgot about the triangle order (last field in the tt array), as tabman said above.

2) You create the new tt and vv containers in every frame, without removing. It's very wasteful.
Here is more correct code:

Code: Select all

vv = new(24, 1, FLOAT)
tt = new(8, 1, INT)
clean(vv)
clean(tt)
while f < 300
{
 ...
 frame()
 f + 1
}
Yeah, after a few minutes, the program just gives up drawing the triangle entirely. I finally figured out that it was a memory leak issue. I forgot that pixilang doesn't do garbage collection.