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.
Triangle Flickering
Re: Triangle Flickering
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
- NightRadio
- Site Admin
- Posts: 3948
- Joined: Fri Jan 23, 2004 12:28 am
- Location: Ekaterinburg. Russia
- Contact:
Re: Triangle Flickering
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:
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
}
-
- Posts: 30
- Joined: Wed Dec 19, 2018 4:05 am
Re: Triangle Flickering
Thanks, this ended up fixing it.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
-
- Posts: 30
- Joined: Wed Dec 19, 2018 4:05 am
Re: Triangle Flickering
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.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 }