Страницы

суббота, 23 ноября 2013 г.

Mobius strip rendering using WebGL

In this post I want to share experience I accidentally got experimenting with WebGL. To get some fun and explore WebGL (never write a line of JS code before) I render a Mobius strip. It's not the hardest task in the world, but definitely more interesting than usual WebGL getting-started samples with two polygons. And after all, Mobius strip is cool, isn't it?
There is not so much to talk about, we have all the usual stuff such as VBO, shaders and so on. The most interesting part is Mobius strip vertices and polygons calculation. I use parametric representation of Mobius strip for tesselation:

Unfortunately got no time for long explanations; take a look at method that calculates vertices, indexes and colors of strip (below), throw a glance at jsfiddle or download entire sample from bitbucket if necessary.