Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
EnTerr
Roku Guru

Re: How to draw a triangle?

"MazeWizzard" wrote:
I know this thread is a bit old, but since triangles are so common I thought I'd relay what I think is an important point...
...
It's slow in B.Script though. I wrote a simple one a year or two ago, but it wasn't fast enough for my needs so I abandoned it. Maybe you'll do better. Once you have the shape, you can always put it in a texture and blit it quickly...until you need to "reshape" it. Then you re-compute.

Thank you for chiming in. Thread is not too old, i have neither solved, nor given up on the idea i have (just haven't got developing on it - i have small list of things i work on, on and off).

I did think of scan-line rasterizing (it's not hard but will have to be careful with degenerate cases, like all 3 vertices on same horizontal line + alpha blending). Initially i was concerned that when i am working in non-native resolution (say if i use roScreen is 854x480 when player is in 720p or 1080p mode), that will lead to triangles turning into horizontal stripes, with gaps forming between the horizontal lines i draw due to zooming. I did not find discussion anywhere how the scaling is done - it could be vector or bitmap-wise, with different outcomes. I still don't know for sure and since it is not documented, it can potentially change (?!).

But performance is my biggest concern - as an idea of speed i would hope to be able to draw something like this spinning tetrahedron:

My gut feeling is line-by-line won't be able to. Was your routine close to such speed, ballpark?
0 Kudos
dev42
Visitor

Re: How to draw a triangle?

Thank you for chiming in. Thread is not too old, i have neither solved, nor given up on the idea i have (just haven't got developing on it - i have small list of things i work on, on and off).

I did think of scan-line rasterizing (it's not hard but will have to be careful with degenerate cases, like all 3 vertices on same horizontal line + alpha blending). Initially i was concerned that when i am working in non-native resolution (say if i use roScreen is 854x480 when player is in 720p or 1080p mode), that will lead to triangles turning into horizontal stripes, with gaps forming between the horizontal lines i draw due to zooming. I did not find discussion anywhere how the scaling is done - it could be vector or bitmap-wise, with different outcomes. I still don't know for sure and since it is not documented, it can potentially change (?!).

But performance is my biggest concern - as an idea of speed i would hope to be able to draw something like this spinning tetrahedron:
<snip>
My gut feeling is line-by-line won't be able to. Was your routine close to such speed, ballpark?

bump bump bump ( better late than never )

why alpha blending? isn't alpha on roku 2D compositing alpha only? my memory is kinda fuzzy on alpha in 3D, but I vaguely rem it has something to do with raycasting, no?

anyway, I bring it up as it might be a bottleneck. (maybe. maybe not.)

as for performance, try this: http://bloggingwordpress.com/2012/08/ro ... ster-demo/

and for those too lazy to click on the link, instead of real-time, why not have your triangle render engine be an offline one, creating sprite sheets for you at load time?

"rokujoel" wrote:
“can we draw to a bitmap directly and then show that bitmap?”

Effectively, drawing to a bitmap is the same operation as drawing to the screen – the screen is sort of a giant bitmap, pretty much anything that works on the screen will work to a bitmap, I believe you will need to call bitmapname.finish() after drawing to bitmaps, just like to the screen,(weird stuff can happen if you don’t) or possibly bitmapname.swapbuffers() under double buffering situations (not sure if bitmaps other than the screen can be double buffered).


but I'll be bold and say YES! that is possible, with backface culling ( alpha issue? ), I totally believe a Roku 2 can draw 2 (flat shaded) Triangles in realtime using BrightScript*... but probably not much else. 😉

* disclaimer, I'm not even going to guess what the FPS would be.
0 Kudos
TheEndless
Channel Surfer

Re: How to draw a triangle?

Be aware that drawing first to a bitmap, then to the the screen requires twice as many draws, which will further slow down your render time.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
dev42
Visitor

Re: How to draw a triangle?

"TheEndless" wrote:
Be aware that drawing first to a bitmap, then to the the screen requires twice as many draws, which will further slow down your render time.

good call.

So, then shouldn't the pre-rendered sprite-sheet solution work? Assuming sufficient time between 3D objects are used?
0 Kudos
TheEndless
Channel Surfer

Re: How to draw a triangle?

"dev42" wrote:
"TheEndless" wrote:
Be aware that drawing first to a bitmap, then to the the screen requires twice as many draws, which will further slow down your render time.

good call.

So, then shouldn't the pre-rendered sprite-sheet solution work? Assuming sufficient time between 3D objects are used?

In theory.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
EnTerr
Roku Guru

Re: How to draw a triangle?

"dev42" wrote:
why alpha blending? isn't alpha on roku 2D compositing alpha only? my memory is kinda fuzzy on alpha in 3D, but I vaguely rem it has something to do with raycasting, no?
What 3D?! I never said 3D... did the animated GIF above mislead you - those just 2 triangles visible at any one time, showing the speed and size i was looking for. I am a simple, 2D person 8-)

The Alpha is for see-through when two partially transparent figures overlap (fancification).

as for performance, try this: http://bloggingwordpress.com/2012/08/ro ... ster-demo/
That one is interesting - thanks, I need to look at the code - image is horribly grainy though, like drawn with a chainsaw.

and for those too lazy to click on the link, instead of real-time, why not have your triangle render engine be an offline one, creating sprite sheets for you at load time?
Nope, not really - the game should work offline, no justification to make it depend on outside server. Figures be moving and rotating, can't precompute it all. Theoretically there is ifDraw2D.DrawRotatedObject but that one is limited to 90 degree rotations (i.e. mostly useless). Unofficially, a few of the players (with GLES - 3xxx, 4200) will rotate to non-multiples of 90 but the rest just draw Nada.
0 Kudos
dev42
Visitor

Re: How to draw a triangle?

and for those too lazy to click on the link, instead of real-time, why not have your triangle render engine be an offline one, creating sprite sheets for you at load time?
Nope, not really - the game should work offline, no justification to make it depend on outside server. Figures be moving and rotating, can't precompute it all. Theoretically there is ifDraw2D.DrawRotatedObject but that one is limited to 90 degree rotations (i.e. mostly useless). Unofficially, a few of the players (with GLES - 3xxx, 4200) will rotate to non-multiples of 90 but the rest just draw Nada.

by "offline" I meant to say precomputed. Like right before they are needed... like during a "loading" screen or something. If enough rotations of the object are precomputed, stored in your sprite sheet, you can pick and choose which frames to display. Movement is the same for "normal" sprites ( those loaded from disk ).

As for triangle drawing code:

http://www.sunshine2k.de/coding/java/Tr ... ation.html

My guess is without anti-aliasing it'll look pretty jagged, but I still believe it's doable just not sure how much else can be moving on the screen at the same time. 😉
0 Kudos
BradC
Binge Watcher

Re: How to draw a triangle?

"dev42" wrote:

as for performance, try this: http://bloggingwordpress.com/2012/08/ro ... ster-demo/


:shock:

neat. that is pretty amazing. that's the coolest thing I've seen today.
♦MiniGolf♦HangMan♦Brain Puck♦Retro Tennis♦BORK♦FLIP♦Pathogen♦Pathogen 2♦Shut the Box♦Birdie♦Logic♦Dots♦Pool♦küglo♦Bubble Wrap♦Trivia Channel♦Mancala♦Air Hockey♦Weather♦CAMERA♦Your Photos Screensaver♦Desert Beauty Screensaver♦Wild Lakes Screensaver♦
0 Kudos
dev42
Visitor

Re: How to draw a triangle?

Update:

I can now draw 2D triangles! With alpha!
http://forums.roku.com/viewtopic.php?f=34&t=75545#p461149

BTW, I forgot that there was a 3D Ray Casting thread that went along with that blog post:
http://forums.roku.com/viewtopic.php?f=34&t=51299&p=348167&hilit=raycaster#p348115

It's been a while since I played around with it. I'm not even sure if I can find the version with RokuJoel's updates. Does anybody remember how he's drawing the rectangles? Is he drawing all the walls? Even those that are occluded? In other words, is there any Hidden Surface Removal going on?

As for performance improvements, I remember this running pretty slowly, but our Roku's have been updated since then. So, who knows?!

more when I have it.

peace & 42
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.