开发者

How does WebGL (on firefox) work?

I grabbed firefox 3.7a (note go to about:config and enable webgl) and ran the examples on this site http://www.iquilezles.org/apps/shadertoy/

The examples were cool then it hit me. How is it running? Code is being ran is it not? Is this an implementation of LLVM? is some开发者_如何学Pythonthing else going on? Would i be able to run my own examples and do something like a command line text based game?


The shader examples on that site are written in a C-like language called GLSL, which is the (Open/Web)GL Shader Language. When they're executed, the JavaScript WebGL code sends the shader source off to your graphics driver's OpenGL functions, which compile it down to a machine code that runs directly on your GPU.

BTW, the shader-only style of coding, while very popular and a great way of writing cool demos, is not an entirely typical use of WebGL. Normally the shaders are used to do a lot of the heavy-duty number crunching, but the design and animation of the various objects that make up your scene is done in JavaScript. (In OpenGL, you would see a similar split between GLSL and some other language, such as C or C++.)

If you want to learn more about coding WebGL, you could do worse than visit the tutorials on my site, learningwebgl.com. I frequently link to other people's demos and tutorials too, so if you don't like my examples you should easily be able to find something better :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜