lightweight java game library
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
- change color of particular row in jtable
- Category
- Java
- Title
- how to take input in java
- Category
- Java
- Title
- get random number from enum in java
- Category
- Java
- Title
- java create directory
- Category
- Java
- Title
- integer to string java
- Category
- Java
- Title
- java loop through array
- Category
- Java
- Title
- decomposer chaine de caractère java
- Category
- Java
- Title
- java random char a-z
- Category
- Java
- Title
- java hashmap get value
- Category
- Java
- Title
- how to fill a list with a single value java
- Category
- Java
- Title
- java - a program to print open ports
- Category
- Java
- Title
- android studio centering textview in relativelayout
- Category
- Java
- Title
- check if optional is empty java
- Category
- Java
- Title
- annotation spring notnull
- Category
- Java
- Title
- java find duplicates in array
- Category
- Java
- Title
- java list as parameter
- Category
- Java
- Title
- java program to display characters from a to z using loop
- Category
- Java
- Title
- Java array nested equals
- Category
- Java
- Title
- ecommerce app github android
- Category
- Java
- Title
- split every character in string into array java
- Category
- Java
- Title
- print a string java
- Category
- Java
- Title
- sort elements with sortedset
- Category
- Java
- Title
- change fab image programatically
- Category
- Java
- Title
- java execute for cycle parallel thread
- Category
- Java
- Title
- height constraint layout guideline
- Category
- Java
- Title
- java 8 loop in map
- Category
- Java
- Title
- serialversionuid java
- Category
- Java
- Title
- java list get first element
- Category
- Java
- Title
- java 8 iterating and manipulating list
- Category
- Java
- Title
- sqrt in java
- Category
- Java
- Title
- object orientation in java
- Category
- Java
- Title
- from file to array java
- Category
- Java
- Title
- Category
- Java
- Title
- how to add integers in java
- Category
- Java
- Title
- change the value in a hashtable java
- Category
- Java
- Title
- how to run java program in linux server
- Category
- Java
- Title
- cannot fit requested classes in a single dex file
- Category
- Java
- Title
- read integer input java
- Category
- Java
- Title
- java how to print a string[]
- Category
- Java
- Title
- convert string to mayus java
- Category
- Java
- Title
- how to read in a file in java
- Category
- Java
- Title
- 2d array java
- Category
- Java
- Title
- how to check if a list is empty java
- Category
- Java
- Title
- convert array of int to arraylist java
- Category
- Java
- Title
- java random number between 100 and 999
- Category
- Java
- Title
- array in line java
- Category
- Java
- Title
- java rest client response json
- Category
- Java
- Title
- exponents java
- Category
- Java
- Title
- java observable to observer stack overflow
- Category
- Java
- Title
- how to compare two maps in java
- Category
- Java
- Title
- try block in java
- Category
- Java
- Title
- java random numbers in specific range
- Category
- Java
- Title
- palindrome function java
- Category
- Java
- Title
- how to create a method java
- Category
- Java
- Title
- java split string
- Category
- Java
- Title
- how to make a button disapear on click in javafx
- Category
- Java
- Title
- java convert String to int
- Category
- Java
- Title
- how to do for each in java
- Category
- Java
- Title
- keep jframe on top
- Category
- Java
- Title
- java find if element of list in present in another list
- Category
- Java
- Title
- java last element in array
- Category
- Java
- Title
- import java.util.hashset
- Category
- Java
- Title
- expression régulière seulement un espace java
- Category
- Java
- Title
- java read string input
- Category
- Java
- Title
- how to limit double decimal places java
- Category
- Java
- Title
- kotlin vs java
- Category
- Java
- Title
- removeeventlistener
- Category
- Java
- Title
- arraylist in java
- Category
- Java
- Title
- how to know if String is the same java
- Category
- Java
- Title
- make recycler view non scrollable
- Category
- Java
- Title
- get day name from date in java
- Category
- Java
- Title
- string contains java
- Category
- Java
- Title
- Primitive Type vs. Reference Type
- Category
- Java
- Title
- spigot heal player
- Category
- Java
- Title
- how to remove duplicates from an array java
- Category
- Java
- Title
- throwing exceptions java
- Category
- Java
- Title
- com.android.builder.dexing.DexArchiveMergerException:
- Category
- Java
- Title
- How to loop through objects in java using streams
- Category
- Java
- Title
- python vs java
- Category
- Java
- Title
- how to define an arraylist in java
- Category
- Java
- Title
- how to count the number of occurrences of an element in a arraylist in java
- Category
- Java
- Title
- ujava saum of positive integers
- Category
- Java
- Title
- programmation android avoir acces à la liste des intents de partage
- Category
- Java
- Title
- java insert array
- Category
- Java
- Title
- gradle require java version
- Category
- Java
- Title
- java int to binary
- Category
- Java
- Title
- left shift in java
- Category
- Java
- Title
- write an object java in a file
- Category
- Java
- Title
- java import text file into arraylist
- Category
- Java
- Title
- How to create a 2d array in java
- Category
- Java
- Title
- how to check internet is working or not in java
- Category
- Java
- Title
- java check for string length
- Category
- Java
- Title
- how to take max value from priority queue in java
- Category
- Java
- Title
- java do while
- Category
- Java
- Title
- Don't use a line-beased input after a token-based input.
- Category
- Java
- Title
- java setter
- Category
- Java
- Title
- hide elements android
- Category
- Java
- Title
- how to import jframe in java
- Category
- Java
- Title
- Removing DOM nodes when traversing a NodeList
- Category
- Java
- Title
- iterate map in java 8 using stream
- Category
- Java