Disclaimer: This blog post is original and has All Rights Reserved. Reprinted please indicate the source: http://www.wjfxgame.com, in addition to my csdn blog: http://blog.csdn.net/ml3947
Lwjgl, you should have heard of it. This is one of the two Java libraries bound to OpenGL in the Java field. The other is jogl, a well-known jogl, which was previously an "official" OpenGL binding Library Supported by Sun.
Although I am currently working in unity3d, It is very convenient to use unity3d. However, it is a commercial engine that is unsatisfactory in many aspects and cannot meet your own needs. In addition, because of the high encapsulation, It is not conducive to your own learning. Since I have been using Java since college, and recently I am playing the well-known Minecraft (developed using lwjgl), I decided to use lwjgl for a look.
The lwjgl library uses its own lightweight local window and has its own input system. The Java library used to bind the sound effect to openal. It also provides APIs for Operation controllers.
In lwjgl, display is a very important class. It is used to create and control local windows for rendering all graphic elements. In display, there are three methods that need attention.
- Create ()
- Update ()
- Destroy ()
The display. Create () method is used to create a local window. We need to set its displaymode to specify the size of the display window. Displaymode needs to be set before create. For example:
Display.setDisplayMode(new DisplayMode(width,height));Display.create();
Lwjgl uses dual buffering, and any image will be drawn to the cache outside the screen. When display. Update () is called, the cache is exchanged and the image is displayed in the window. This method is usually called at each frame in the rendering loop.
When lwjgl is destroyed, the display. Destroy () method is called to clear and release resources.
In addition, when we click the button to close the local window, the display. iscloserequested () method returns true, so we usually use it in the rendering loop, as shown below:
import org.lwjgl.LWJGLException;import org.lwjgl.opengl.Display;import org.lwjgl.opengl.DisplayMode;public class DisplayExample {public void start() {try {Display.setDisplayMode(new DisplayMode(800,600));Display.create();} catch (LWJGLException e) {e.printStackTrace();System.exit(0);}// init OpenGL herewhile (!Display.isCloseRequested()) {// render OpenGL hereDisplay.update();}Display.destroy();}public static void main(String[] argv) {DisplayExample displayExample = new DisplayExample();displayExample.start();}}
A 800x600 window is displayed.
For more information, see http://blog.csdn.net/ml3947.