Triangle Flickering

Pixilang programming language
Post Reply
E8_Heterotic
Posts: 30
Joined: Wed Dec 19, 2018 4:05 am

Triangle Flickering

Post by E8_Heterotic » Tue Jan 15, 2019 3:14 am

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 48 times

tabman
Posts: 4
Joined: Wed Nov 12, 2014 6:32 pm

Re: Triangle Flickering

Post by tabman » 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

User avatar
NightRadio
Site Admin
Posts: 3118
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: Triangle Flickering

Post by NightRadio » 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
}

E8_Heterotic
Posts: 30
Joined: Wed Dec 19, 2018 4:05 am

Re: Triangle Flickering

Post by E8_Heterotic » Sun Jan 20, 2019 9:36 am

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.

E8_Heterotic
Posts: 30
Joined: Wed Dec 19, 2018 4:05 am

Re: Triangle Flickering

Post by E8_Heterotic » Sun Jan 20, 2019 9:37 am

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.

Post Reply