Page curling effect: OpenGL?

Monkey Forums/Monkey Programming/Page curling effect: OpenGL?

Anatol(Posted 2012) [#1]
Hi,

I'm working on an interactive book in Monkey and I'm just playing with some different page turning effects. I'm still very undecided if it would be worth the effort to redo parts of the code with the OpenGL module just to get a page curling effect (in fact I'm not even sure if that's doable - I don't have experience with OpenGL).

Any opinions from more experienced Monkeycoders would be highly appreciated.

I could probably find some 2D workaround such as http://www.youtube.com/watch?v=aVZHN_o45sg (but for that example I'd need a scissor that's not limited to a rectangular shape).

Cheers!
Anatol


JIM(Posted 2012) [#2]
I think there's an "easy" way to solve your scissor problem. Not sure if diddy has anything like this, but you could probably hack monkey to do it:

Instead of a rectangle, you should draw a polygon. That polygon should be the page rectangle sliced by the page curling effect. For the UV coordinates just use position / size and it should be good.

It probably would be easier with OpenGL shaders (at least for me).

As for the effect itself, there's a bunch of source code on google code on that video's description. That could help you draw the backside of the page.

Good luck ;)


MonkeyPig(Posted 2012) [#3]
I did this FB landing page for a friend.

http://www.facebook.com/Peelzone/app_230224260356929

Works in HTML5 and Flash (as a fallback). I think it looks pretty decent - with no need for any OpenGL calls.

I did it before the GL module was added. If I was only targeting consoles I'd probably use OpenGL now and allow for more interesting corner peels.


Anatol(Posted 2012) [#4]
Thank you very much for your replies. I'll do some tests to see if I can get my head around OpenGL. Just a quick question beforehand, is there any way that the graphics module and openGL can coexist?

But I guess when I use pages I basically need to have 2 canvases (for current, next/previous page), so it wouldn't really work?


MonkeyPig(Posted 2012) [#5]
As I understand it - OpenGL 1.1 will happily co-exist with mojo graphics. OpenGL 2.0 won't.

You only need one canvas (or drawing surface) and then draw your pages in the the correct order. Draw Page n+1 first (but only if you're page turning). Draw Page n.

Once your turn is complete page n advances to n+1.


NoOdle(Posted 2012) [#6]
Had an idea to hack this. It uses SetScissor to draw one line at a time, clipping as necessary. To test the idea I quickly threw this together, please forgive the hideous code (its only to prove a point). I did the scissor in the wrong direction, I should have drawn the lines vertically and done a test to draw as many columns at once as possible, could have saved alot of expensive draw calls.

Use Left/Right keys to turn




Anatol(Posted 2012) [#7]
Wow, even with full working code! I just tested it, the transition looks really good and smooth! Thanks, that's a really good idea!

I'll definitely test this and see how it runs with pages that are not 'static'. There's quite a lot going on on some of the pages of my interactive book project (particle effects, etc.), so drawing the scene many times during page turns may slow things down. I'll test this - I don't know how smart the scissor is and if it just renders the part it needs or if it renders all and then crops it. I may not be able to do this today, but I will post here again once I tested it.

Also, I'll still try to use OpenGL. Regardless if I'll use it eventually or not, I can still learn something in the process...

My ideal case would be to use different page turn effects and page turn triggers for different platforms or even device sizes, whichever is supported or works best.

Thanks a lot, NoOdle! This is very helpful.


NoOdle(Posted 2012) [#8]
ok, below is a much much better version. The pageMu is the completed amount of the effect in the range of 0 - 1. All you need to do is draw some AA lines (code snippet on the forum) along the white shape edges to create a fairly realistic shadow effect.

Further speed can probably be gained by optimising the draw scene function; only drawing stuff thats inside the scissor, not sure if thats done automatically or not.




Anatol(Posted 2012) [#9]
Fantastic! That looks really good! I'll test and see how it runs with more complex content and some shadows. Thanks also for the code comments!

I'll post here again, but give me a few days. Time is a bit tight right now :(