how get started with LWJGL 3
Java
import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.system.*;
import java.nio.*;
import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;
public class HelloWorld {
// The window handle
private long window;
public void run() {
System.out.println("Hello LWJGL " + Version.getVersion() + "!");
init();
loop();
// Free the window callbacks and destroy the window
glfwFreeCallbacks(window);
glfwDestroyWindow(window);
// Terminate GLFW and free the error callback
glfwTerminate();
glfwSetErrorCallback(null).free();
}
private void init() {
// Setup an error callback. The default implementation
// will print the error message in System.err.
GLFWErrorCallback.createPrint(System.err).set();
// Initialize GLFW. Most GLFW functions will not work before doing this.
if ( !glfwInit() )
throw new IllegalStateException("Unable to initialize GLFW");
// Configure GLFW
glfwDefaultWindowHints(); // optional, the current window hints are already the default
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // the window will stay hidden after creation
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // the window will be resizable
// Create the window
window = glfwCreateWindow(300, 300, "Hello World!", NULL, NULL);
if ( window == NULL )
throw new RuntimeException("Failed to create the GLFW window");
// Setup a key callback. It will be called every time a key is pressed, repeated or released.
glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> {
if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE )
glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop
});
// Get the thread stack and push a new frame
try ( MemoryStack stack = stackPush() ) {
IntBuffer pWidth = stack.mallocInt(1); // int*
IntBuffer pHeight = stack.mallocInt(1); // int*
// Get the window size passed to glfwCreateWindow
glfwGetWindowSize(window, pWidth, pHeight);
// Get the resolution of the primary monitor
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
// Center the window
glfwSetWindowPos(
window,
(vidmode.width() - pWidth.get(0)) / 2,
(vidmode.height() - pHeight.get(0)) / 2
);
} // the stack frame is popped automatically
// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable v-sync
glfwSwapInterval(1);
// Make the window visible
glfwShowWindow(window);
}
private void loop() {
// This line is critical for LWJGL's interoperation with GLFW's
// OpenGL context, or any context that is managed externally.
// LWJGL detects the context that is current in the current thread,
// creates the GLCapabilities instance and makes the OpenGL
// bindings available for use.
GL.createCapabilities();
// Set the clear color
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
// Run the rendering loop until the user has attempted to close
// the window or has pressed the ESCAPE key.
while ( !glfwWindowShouldClose(window) ) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
glfwSwapBuffers(window); // swap the color buffers
// Poll for window events. The key callback above will only be
// invoked during this call.
glfwPollEvents();
}
}
public static void main(String[] args) {
new HelloWorld().run();
}
}
Also in Java:
- Title
- how to do for each in java
- Category
- Java
- Title
- java get annotation value
- Category
- Java
- Title
- character at index of string java
- Category
- Java
- Title
- thymeleaf Expression Object dialects
- Category
- Java
- Title
- what is graphics default color java
- Category
- Java
- Title
- how to check wether the property exist in a object in java script
- Category
- Java
- Title
- how to find complement of a number in java
- Category
- Java
- Title
- java get size of array
- Category
- Java
- Title
- java while loop break
- Category
- Java
- Title
- add in list java
- Category
- Java
- Title
- sending a excel in an attachment in email java
- Category
- Java
- Title
- java how to change the length of an array
- Category
- Java
- Title
- convert java list to array
- Category
- Java
- Title
- testing the web layer without authentication spring
- Category
- Java
- Title
- print in one line in java
- Category
- Java
- Title
- java mouseevent
- Category
- Java
- Title
- java get current date without time
- Category
- Java
- Title
- how to make an arraylist java
- Category
- Java
- Title
- money value commas java
- Category
- Java
- Title
- load contents of file into string java
- Category
- Java
- Title
- Java arraylist if you don't want to use add()
- Category
- Java
- Title
- annotation spring notnull
- Category
- Java
- Title
- Method used for getting metadata of a database in jdbc
- Category
- Java
- Title
- hashmap get value java
- Category
- Java
- Title
- biginteger in java
- Category
- Java
- Title
- java convert a set to array
- Category
- Java
- Title
- simple javascript to detect browser using java utils
- Category
- Java
- Title
- java while loop example
- Category
- Java
- Title
- covariant type in java
- Category
- Java
- Title
- Primitive Type vs. Reference Type
- Category
- Java
- Title
- java 8 string to localdate
- Category
- Java
- Title
- java replace all html tags
- Category
- Java
- Title
- open an existing excel file in java apache poi
- Category
- Java
- Title
- expression régulière téléphone java
- Category
- Java
- Title
- how to init an array with objects in java
- Category
- Java
- Title
- java get environment variables
- Category
- Java
- Title
- java string to int
- Category
- Java
- Title
- java make arraylist
- Category
- Java
- Title
- java hashmap set value
- Category
- Java
- Title
- how to use pow function in java
- Category
- Java
- Title
- how to get the checkbox checked value in javafx
- Category
- Java
- Title
- how to change actionbar color in android programmatically
- Category
- Java
- Title
- how to remove all whitespace from string java
- Category
- Java
- Title
- get sha key android
- Category
- Java
- Title
- kotlin jsonobject get nested
- Category
- Java
- Title
- java newinstance alternative
- Category
- Java
- Title
- Filebody in java
- Category
- Java
- Title
- java stream order by property
- Category
- Java
- Title
- java repository sql find not in list
- Category
- Java
- Title
- get method of a class which I only have string to
- Category
- Java
- Title
- java new string array
- Category
- Java
- Title
- android studio java random number generator
- Category
- Java
- Title
- jsonobject to java object
- Category
- Java
- Title
- how to declare string array in java
- Category
- Java
- Title
- how to change maven java version in po,
- Category
- Java
- Title
- what it means when create final variable in java
- Category
- Java
- Title
- java recursion
- Category
- Java
- Title
- java stack push
- Category
- Java
- Title
- create java windows application
- Category
- Java
- Title
- Java's BigInteger class
- Category
- Java
- Title
- java 8 stream option
- Category
- Java
- Title
- how to instanciate map.entry java
- Category
- Java
- Title
- how to replace all of one character with nothing in java
- Category
- Java
- Title
- java generate list of random element
- Category
- Java
- Title
- final variables in java
- Category
- Java
- Title
- java io
- Category
- Java
- Title
- gat environment variables java
- Category
- Java
- Title
- intellij replace all
- Category
- Java
- Title
- how to count the number of occurrences of an element in a arraylist in java
- Category
- Java
- Title
- Java use Base64
- Category
- Java
- Title
- convert string to mayus java
- Category
- Java
- Title
- read csv java
- Category
- Java
- Title
- how to get witdth of window android
- Category
- Java
- Title
- java connect to mysql
- Category
- Java
- Title
- java final meaning
- Category
- Java
- Title
- same method name with different arguments
- Category
- Java
- Title
- import collections in java
- Category
- Java
- Title
- how to add java_home in mac
- Category
- Java
- Title
- android studio centering textview in relativelayout
- Category
- Java
- Title
- detect tv remote keys andoid studio
- Category
- Java
- Title
- binary to int java
- Category
- Java
- Title
- dictionary in java
- Category
- Java
- Title
- how to print each element of an arraylist on a new line in java
- Category
- Java
- Title
- check leap year in java
- Category
- Java
- Title
- restart application programmatically android
- Category
- Java
- Title
- how to add to a file in java
- Category
- Java
- Title
- spigot get player from UUID
- Category
- Java
- Title
- capacitor-android. Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project
- Category
- Java
- Title
- arraylist add method
- Category
- Java
- Title
- android cardview dependency
- Category
- Java
- Title
- java map string to list
- Category
- Java
- Title
- get first character of string java
- Category
- Java
- Title
- java loop through string
- Category
- Java
- Title
- on click android studio not working
- Category
- Java
- Title
- java split string
- Category
- Java
- Title
- change activity main drawer items text color programmatically android
- Category
- Java
- Title
- java how to serialize a file into a local server
- Category
- Java
- Title
- java sort method
- Category
- Java
- Title
- how to reverse a list in java
- Category
- Java
- Title
- converter int array para string java
- Category
- Java