WebGL4J - Simple GWT based WebGL wrapper for Java

WebGL4J is a WebGL wrapper library for the Java programming language which allows to use Java to write HTML5 applications using GWT (Google Web Toolkit) which uses WebGL to draw 2D / 3D hardware accelerated graphics using a HTML5 Canvas.
[h1]Design[/h1]
WebGL4J aims to provide static methods to all the WebGL functions, and also the extensions present in the Khronos WebGL Registry. This provides a similar interface to people who are coming from legacy OpenGL environments (by legacy, I mean desktop) to use WebGL easily, yet having the same interface to the users coming from JavaScript.

[tr]
[td]Class[/td]
[td]Description[/td]
[/tr]
[tr]
[td]WebGL10[/td]
[td]Contains all the constants and functions defined in the WebGL 1.0 specification[/td]
[/tr]
[tr]
[td]WebGL20[/td]
[td]Contains all the constants and functions defined in the WebGL 2.0 specification[/td]
[/tr]
[tr]
[td]{ExtName}[/td]
[td]Contains all the constants and functions defined in the extension {ExtName}[/td]
[/tr]

As you have seen above, that is how the functions are structured in the wrapper, allowing to use WebGL functions from any where in the app once the context is created. All the functions have the OpenGL prefixes and suffixes, to help the users coming from the native desktop OpenGL.
[h1]Installation[/h1]
Download the webgl4j.jar from releases and add it in the classpath of your GWT application. Now inherit the WebGL4J in your modules that use this library by adding the following line to your GWT module XML file.


<inherits name="com.shc.webgl4j.client" />

That should let you use WebGL4J in your project. You can now start writing WebGL applications using GWT.
[h1]Context Creation[/h1]
To create a WebGL context, you can use the createContext method from the WebGL10 class or the WebGL20 class, with a canvas element from GWT.


Canvas canvas = Canvas.createIfSupported();
WebGLContext.Attributes ctxAttributes = WebGLContext.Attributes.create();
ctxAttributes.setStencil(true);

// Create the context now
WebGL10.createContext(canvas, ctxAttributes);

Don’t forget to attach the canvas to the root pane or you won’t be able to see it on the page. The above example creates a WebGL 1.0 context with a stencil buffer. Note that it is completely optional to pass context attributes object to the createContext method if you need none.
[h1]Links[/h1]
There are a lot of other features including multiple contexts, extensions, fullscreen support, a builtin timer etc., See the README of the GitHub project for information on using them.


GitHub repository | Online Examples | Examples (Source)

Special thanks to NegativeZero for the awesome logos. The logos are under Creative Commons licence and the library is under MIT licence. If you have anything to talk, please post either here or on the IRC #WebGL4J on Freenode.