Lwjgl tutorial-1.The display

Source: Internet
Author: User

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.

  1. Create ()
  2. Update ()
  3. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.