WebGL
Web browsers are probably the most widely used software in desktops and mobile computers. They have become the swiss army knife of the Web 2.0 digital world and it is under this context that a Javascript API for rendering GPU-based graphics was born: WebGL.
Long live Java
The WebGL technology enables rendering complex 3D or 2D scenes such as games within your browser. You could write the next Angry Birds in javascript and WebGL. But why not leverage the power of existing Java technologies and write your game in Java using WebGL? Yes! You can write Java code and deploy it on the web as javascript thanks to the help of the Google Webtoolkit. (If you haven’t tried it, then you should!).
The following web app illustrates how easily Java and WebGL can be used together with Libgdx game development framework to create fancy 3D scenes.
Click on the image to see the webGL app. Note: you’ll need a WebGL compatible browser such as Firefox or Chrome.
Instructions: use the arrow keys to move the camera and drag the mouse to rotate the camera.
Notes about the code
- The code uses WebGL which is pretty much OpenGL ES 2.0.
- The sky and mountains background texture (a.k.a Skybox) are rendered using cube mapping and custom shaders.
- There is one shader program for rendering the water which is based on the excellent Jay Conrod’s water simulation shader. The water looks jaggy because there aren’t many triangles in the model. Feel free to change this.
- The boat 3D model comes from here and the texture from here.
- The teddy bear comes from here (if you know the original source, let me know).
- All models were exported to G3DT format using blender.
NB. The code will be available on github in the coming days.
Edit: The code is available here: https://github.com/recastrodiaz/java-webgl
Cross-platform game development
The holly grail of developers is to code once and run everywhere. Unfortunately, this is hardly true as platforms are extremely different from each other. Furthermore, screen sizes and input devices are not the same. Nevertheless, the Java ecosystem provides great multi platform support out of the box. Add GWT and Monotouch to the mix and you’ll support Mac, Windows, Linux, Android, HTML5 and iOS from day one. Check the following cross-platform gaming frameworks to see how it can be done: PlayN and Libgdx.