micahpearlman / MonkVG

MonkVG is an OpenVG 1.1 like vector graphics API implementation optimized for game use currently using an OpenGL ES backend that should be compatible with any HW that supports OpenGL ES 2.0 which includes most iOS and Android devices.
Other
380 stars 66 forks source link

[feature-request] JavaScript port. #45

Closed trusktr closed 2 years ago

trusktr commented 7 years ago

It'd be nice to have something like this for WebGL.

trusktr commented 7 years ago

This is too awesome, but I really want it in WebGL. Maybe I'll try porting it at some point...

micahpearlman commented 7 years ago

That would be cool. I don't know a thing about WebGL but let me know if I can advise on the code base.

On Jul 11, 2017, at 2:04 PM, Joseph Orbegoso Pea notifications@github.com wrote:

This is too awesome, but I really want it in WebGL. Maybe I'll try porting it at some point...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

trusktr commented 7 years ago

WebGL is very similar to OpenGL ES (well, it is written as a JavaScript interface for OpenGL ES). So many of the calls are very similar. For example, glTextImage2d() would be gl.textImage2d() in JavaScript, calling a method on the gl context object.

In almost every case, whenever I see gl.someMethod in JavaScript, I just look up glSomeMethod to find OpenGL documentation on it. It is literally almost a one-to-one mapping, so porting to JavaScript wouldn't be difficult, just time consuming to rewrite.

f.e. glEnable(GL_DEPTH_TEST) becomes gl.enable(gl.DEPTH_TEST). Almost everything maps one-to-one.

trusktr commented 7 years ago

A big difference is that everything is easier in WebGL. For example, you can pass a reference to a <img /> HTML element into the gl.textImage2d() call instead of a data array, and the webgl engine does the magic taking the data from the image element behind the scenes (though you can pass a Float32Array too if you want. It has lot's of shortcuts like that that make the webgl coding experience easier.